@antmind/encoding
v0.1.0
Published
Lightweight data encoding utilities for Node.js and browsers.
Readme
@antmind/encoding
Lightweight data encoding utilities for Node.js and browsers.
Features
- Base32 encoding/decoding.
- Node.js and browser compatible.
Installation
Install from npm:
npm install @antmind/encodingQuick Start
Encode and decode Base32 strings with default settings:
import { base32 } from '@antmind/encoding';
// encode
const encoded = base32.encode('foo');
// => 'MZXW6==='
// decode
const decoded = base32.decode('MZXW6===');
// => 'foo'You can also create a custom Base32 encoding instance with your own alphabet and padding character:
import { Base32Encoding } from '@antmind/encoding';
const customBase32 = new Base32Encoding({
encoder: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', // standard Base32 alphabet
padChar: '*', // custom padding character
});
const encoded = customBase32.encode('foo');
// => 'MZXW6***'
// or method override
const encoded2 = customBase32.encode('foo', { padChar: '+' });
// => 'MZXW6+++'API
new Base32Encoding(options?: Base32Options)options.encoder?: string— 32-character alphabet string. Defaults toBase32StdEncoder.options.padChar?: string— padding character (set to empty string''to disable padding). Defaults to'='.
encode(data: string, options?: Base32Options)— Encodesdatato a Base32 string. Accepts the sameoptionsas the constructor to override encoder/pad for a single call.decode(str: string, options?: Base32Options)— Decodes a Base32strto the original string. Accepts the sameoptionsto override encoder/pad.
Tests
Run the test suite with:
npm testContributing
Contributions and bug reports are welcome. Please open issues or pull requests.
License
This project is licensed under the MIT License. See the LICENSE file for details.
