Skip to content
/ base64 Public

Cross-platform base64 methods for encoding and decoding Unicode (16-bit) strings, including methods to make strings safe for use in `application/x-www-form-urlencoded` values.

Notifications You must be signed in to change notification settings

mikol/base64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Cross-platform base64 methods for encoding and decoding Unicode (16-bit) strings, including methods to make strings safe for use in `application/x-www-form-urlencoded` values.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published