Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fast-sjis-encoder

t-kouyama17MIT1.1.1TypeScript support: included

Fast Shift-JIS(MS932) encoder - About 2x faster than iconv-lite

sjis, shift-jis, ms932, encoder, japanese, charset, encoding, fast

readme

fast-sjis-encoder

Fast Shift-JIS(MS932) encoder - About 2x faster than iconv-lite

Installation

npm install fast-sjis-encoder

Usage

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