node-b64

0.0.3 • Public • Published

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));
 

Readme

Keywords

Package Sidebar

Install

npm i node-b64

Weekly Downloads

2

Version

0.0.3

License

GPL-3.0

Last publish

Collaborators

  • adulin