0.0.3 • Published 7 years ago

node-b64 v0.0.3

Weekly downloads
4
License
GPL-3.0
Repository
github
Last release
7 years ago

node-b64

Basic implementations of btoa and atob for Node v6+

Why?

Becaue I got tired of writing

Buffer.from(x, 'base64').toString('utf8');

Usage

Using the entire module:

"use strict";

const b64 = require('node-b64');

const str = 'this is some stuff';


/**
 * Encode a string
 */
b64.btoa(str);

// Prints -> 'dGhpcyBpcyBzb21lIHN0dWZm'


/**
 * Decode a string
 */

b64.atob(b64.btoa(str));

// Prints -> 'this is some stuff'


/**
 * Works with buffers too
 */
btoa(Buffer.from('foo')) === btoa('foo')

// true

Or just use one of the two functions:

const btoa = require('node-b64/btoa');
const atob = require('node-b64/atob');

const str2 = 'this is other stuff';

btoa(str2);

atob(btoa(str2));