/basex-encoder

Encode / decode any base X to and from string or buffer written in TypeScript

Primary LanguageTypeScriptMIT LicenseMIT

BaseX Encoder

BaseX Encoder is encoder / decoder for any base X. It can encode / decode to and from string and buffer

Build Status Coverage Status npm version Dependency Status License

+ Written in TypeScript

+ 0 dependencies

Getting Started

First, install BaseX Encoder using npm.

npm install --save basex-encoder
# or
yarn add basex-encoder

Note: BaseX Encoder assumes a JavaScript environment with global Buffer. Use safe-buffer to polyfill.

import { encoder } from 'basex-encoder';

const base58 = encoder('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');

// or
const base6 = encoder('abcdef', 'utf8');

// encode from string to string
const encoded = base58.encode('text to encode');

// decode from string to string
const decoded = base58.decode(encoded);

// encode from buffer to string
const encoded = base58.encodeFromBuffer(rawBuffer);

// decode from string to buffer
const decodedBuffer = base58.decodeToBuffer(encoded);