1.1.1 • Published 9 months ago
fast-sjis-encoder v1.1.1
fast-sjis-encoder
Fast Shift-JIS(MS932) encoder - About 2x faster than iconv-lite
Installation
npm install fast-sjis-encoderUsage
Browser
<script src="https://cdn.jsdelivr.net/npm/fast-sjis-encoder"></script>ES Modules
import sjis from 'fast-sjis-encoder';CommonJS
const sjis = require('fast-sjis-encoder');Encode string to Shift-JIS byte array
const bytes = sjis('Hello 世界');
console.log(bytes); // Uint8Array(10) [72, 101, 108, 108, 111, 32, 144, 162, 138, 91]Benchmark
Comparison with iconv-lite (operations per second)
| chars | fast-sjis-encoder | iconv-lite | faster | 
|---|---|---|---|
| 30 | 1,491,271 | 789,446 | 1.89x | 
| 300 | 471,622 | 222,128 | 2.12x | 
| 3000 | 61,771 | 24,708 | 2.50x | 
About 2x faster than iconv-lite.
Decoder?
const text = new TextDecoder('shift-jis').decode(bytes);
console.log(text); // "Hello 世界"License
MIT