Code Monkey home page Code Monkey logo

base32's Introduction

LunaCrew's Base32

Base32 encoding and decoding library for Node.js.

For details on how it works, please check out the documentation.

Installation

npm install @lunacrew/base32

Usage

Convenience Functions

import { Base32 } from '@lunacrew/base32';

/**
 * Convenience encoder.
 *
 * @param {string} input - The string to encode.
 * @param {Alphabet} [type] - The alphabet type to use for encoding. Defaults to 'rfc4648'.
 * @param {boolean} [lowercase] - Use lower-case alphabet. Defaults to false.
 * @returns {Buffer} The encoded string as a Buffer.
 */

const encoded = Base32.encode('Hello World!');
console.log(encoded); // JBSWY3DPEBLW64TMMQQQAA==

/**
 * Convenience decoder.
 *
 * @param {string} input - The base32 encoded string to decode.
 * @param {CharMap} [type] - The character map type to use for decoding. Defaults to 'rfc4648'.
 * @returns {Buffer} The decoded data as a Buffer.
 */

const decoded = Base32.decode(encoded);
console.log(decoded); // Hello World!

Class Interface

import { Encoder, Decoder } from '@lunacrew/base32';

/**
 * Create a new `Encoder` with the given options.
 *
 * @param {string} [type] The alphabet type to use for encoding. Default is 'rfc4648'.
 * @param {boolean} [lowercase] Use lower-case alphabet. Default is false.
 * @constructor
 */

const encoder = new Encoder();
const encoded = encoder.encode('Hello World!');
console.log(encoded); // JBSWY3DPEBLW64TMMQQQAA==

/**
* Create a new `Decoder` with the given options.
*
* @param {string} [type] The charmap type to use for encoding. Default is 'rfc4648'.
* @constructor
*/

const decoder = new Decoder();
const decoded = decoder.decode(encoded);
console.log(decoded); // Hello World!

License

This project incorporates code from base32.js and base32-js, both are licensed under MIT. Please see the LICENSE file for the full combined license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.