1.0.0 β’ Published 2 years ago
@dwcore/utf8 v1.0.0
UTF8
Install
npm i --save @dwcore/utf8
Usage
// CJS
const UTF8 = require('@dwcore/utf8');
// ESM
import UTF8, {
UTF8Encode,
UTF8EncodeInto,
UTF8Decode
} from '@dwcore/utf8';
const string = 'Ave, Darkwolf!πΊπΊπΊ$Β’β¬π';
const encoded = UTF8.encode(string); // => Uint8Array
const decoded = UTF8.decode(encoded); // => 'Ave, Darkwolf!πΊπΊπΊ$Β’β¬π'
decoded === string; // => true
const buffer = new Uint8Array(string.length * 2 + 5);
const result = UTF8.encodeInto(string, buffer);
result.read; // => 25
result.written; // => 36
const decodedString = UTF8.decode(buffer); // => 'Ave, Darkwolf!πΊπΊπΊ$Β’β¬π'
decodedString === string; // => false
const newBuffer = buffer.slice(0, result.written); // => Uint8Array
const newDecodedString = UTF8.decode(newBuffer); // => 'Ave, Darkwolf!πΊπΊπΊ$Β’β¬π'
newDecodedString === string; // => true
API Documentation
1.0.0
2 years ago