Skip to content

Latest commit

 

History

History
82 lines (54 loc) · 2.48 KB

File metadata and controls

82 lines (54 loc) · 2.48 KB

@antmind/encoding

Latest version NPM Package Github Actions build codecov License

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/encoding

Quick 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 to Base32StdEncoder.
    • options.padChar?: string — padding character (set to empty string '' to disable padding). Defaults to '='.
  • encode(data: string, options?: Base32Options) — Encodes data to a Base32 string. Accepts the same options as the constructor to override encoder/pad for a single call.

  • decode(str: string, options?: Base32Options) — Decodes a Base32 str to the original string. Accepts the same options to override encoder/pad.

Tests

Run the test suite with:

npm test

Contributing

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.