tiny-eucjp-encoder
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

tiny-eucjp-encoder

Tiny EUC-JP(CP51932) encoder - Only 679 bytes

Installation

npm install tiny-eucjp-encoder

Usage

Browser

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

ES Modules

import eucjp from 'tiny-eucjp-encoder';

CommonJS

const eucjp = require('tiny-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)

chars tiny-eucjp-encoder iconv-lite faster
30 1,052,011 284,206 3.70x
300 484,369 249,533 1.94x
3000 53,060 26,388 2.01x

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

First call needs a few ms to init. After that, very fast.

Decoder?

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

License

MIT

Package Sidebar

Install

npm i tiny-eucjp-encoder

Weekly Downloads

8

Version

1.0.1

License

MIT

Unpacked Size

5.01 kB

Total Files

6

Last publish

Collaborators

  • t-kouyama