1.1.0 • Published 4 months ago

fast-eucjp-encoder v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

fast-eucjp-encoder

Fast EUC-JP(CP51932) encoder - About 2x faster than iconv-lite

Installation

npm install fast-eucjp-encoder

Usage

Browser

<script src="https://cdn.jsdelivr.net/npm/fast-eucjp-encoder"></script>

ES Modules

import eucjp from 'fast-eucjp-encoder';

CommonJS

const eucjp = require('fast-eucjp-encoder');

Encode string to EUC-JP byte array

const bytes = eucjp('Hello 世界');
console.log(bytes); // Uint8Array(10) [72, 101, 108, 108, 111, 32, 192, 164, 179, 166]

Benchmark

Comparison with iconv-lite (operations per second)

charsfast-eucjp-encodericonv-litefaster
301,052,011284,2063.70x
300484,369249,5331.94x
300053,06026,3882.01x

3.7x faster than iconv-lite for short text, and about 2x faster for longer text.

Decoder?

const text = new TextDecoder('euc-jp').decode(bytes);
console.log(text); // "Hello 世界"

License

MIT

1.1.0

4 months ago

1.0.0

4 months ago