2.1.9 • Published 3 months ago
@i-xi-dev/ms932-encoder v2.1.9
@i-xi-dev/ms932-encoder
A JavaScript Windows-31J encoder, implements Shift_JIS encoder defined in WHATWG Encoding Standard.
Requirement
Ms932.Encoder
class
Chrome | Edge | Firefox | Safari | Deno | Node.js |
---|---|---|---|---|---|
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Ms932.EncoderStream
class
Ms932.EncoderStream
requires
TransformStream
.
Chrome | Edge | Firefox | Safari | Deno | Node.js |
---|---|---|---|---|---|
✅ | ✅ | ✅102+ | ✅14.1+ | ✅ | ✅16.5+ |
Installation
npm
$ npm i @i-xi-dev/ms932-encoder@2.1.9
import { Ms932 } from "@i-xi-dev/ms932-encoder";
CDN
Example for UNPKG
import { Ms932 } from "https://www.unpkg.com/@i-xi-dev/ms932-encoder@2.1.9/esm/mod.js";
Usage
Ms932.Encoder
class
The Ms932.Encoder
implements the
TextEncoder
interface.
const encoder = new Ms932.Encoder();
encoder.encode("あいうえお");
// → Uint8Array[ 0x82, 0xA0, 0x82, 0xA2, 0x82, 0xA4, 0x82, 0xA6, 0x82, 0xA8 ]
const bytes = new Uint8Array(10);
const { read, written } = encoder.encodeInto("あいうえお", bytes);
// → read: 5
// written: 10
// bytes: Uint8Array[ 0x82, 0xA0, 0x82, 0xA2, 0x82, 0xA4, 0x82, 0xA6, 0x82, 0xA8 ]
Encoding error handling
const encoder = new Ms932.Encoder({ fatal: false }); // default
encoder.encode("𩸽");
// → Uint8Array[ 0x3F ]
const encoder = new Ms932.Encoder({ replacementChar: "■" });
encoder.encode("𩸽");
// → Uint8Array[ 0x81, 0xA1 ]
const encoder = new Ms932.Encoder({ fatal: true });
encoder.encode("𩸽");
// → throws TypeError.
Ms932.EncoderStream
class
The Ms932.EncoderStream
implements
TextEncoderStream
interface.
const encoderStream = new Ms932.EncoderStream();
// readableStream: ReadableStream<string>
// writableStream: WritableStream<Uint8Array>
readableStream.pipeThrough(encoderStream).pipeTo(writableStream);
Examples
FAQ
Q: Where is Ms932.Decoder?
A: Browsers and Node.js implement the
Shift_JIS decoder. Use a
TextDecoder
.
const decoder = new TextDecoder("shift_jis");
2.1.9
3 months ago
2.1.7
5 months ago
2.1.3
8 months ago
2.0.22
9 months ago
2.0.11
1 year ago
2.0.3
2 years ago
2.0.5
2 years ago
2.0.4
2 years ago
2.0.7
2 years ago
2.0.0
2 years ago
1.3.0
3 years ago
1.2.7
3 years ago
1.2.6
3 years ago
1.2.5
3 years ago
1.2.4
3 years ago
1.2.3
3 years ago
1.2.2
3 years ago
1.2.0
3 years ago
1.2.1
3 years ago
1.1.0
3 years ago
1.0.0
3 years ago
0.9.0
3 years ago