Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 1.54 KB

README.md

File metadata and controls

46 lines (33 loc) · 1.54 KB

base64

Cross-platform base64 methods for encoding and decoding data. This module solves three problems.

  1. It works in Node.js and in any browser with or without btoa(), atob(), Buffers, or TypedArrays.
  2. It handles 16-bit-encoded strings, even those that contain characters exceeding the 8-bit ASCII-encoding range (see The “Unicode Problem”).
  3. It provides methods for encoding and decoding with a URL- and filename-safe alphabet with or without '=' padding characters so that encoded strings can be safely used with application/x-www-form-urlencoded data, including as part of URL query strings (see Named Information (ni) URI Format Digest Values in RFC 6920).

Installation

$ npm install https://github.com/mikol/base64

Usage

var json = '{"alchemy": "🜘🜛🜜🜝🜞🜟🜠🜡🜣🜤🜥🜨🜩🜪🜫🜬🜭🜮🜯🜱"}';

// Use canonical encoding.
var b64 = base64.encode(json);

// eyJhbGNoZW15IjogIvCfnJjwn5yb8J+co/CfnKTwn5yl8J+cqPCfnKnwn5yq8J+cr/CfnLEifQ==

// Use URL- and filename-safe alphabet.
var b64url = base64.url.encode(json);

// eyJhbGNoZW15IjogIvCfnJjwn5yb8J-co_CfnKTwn5yl8J-cqPCfnKnwn5yq8J-cr_CfnLEifQ==

// Use URL- and filename-safe alphabet. Omit '=' padding characters.
var b64ni = base64.ni.encode(json);

// eyJhbGNoZW15IjogIvCfnJjwn5yb8J-co_CfnKTwn5yl8J-cqPCfnKnwn5yq8J-cr_CfnLEifQ

// Decode. One method to rule them all.
base64.decode(b64);
base64.decode(b64url);
base64.decode(b64ni);