11.88.1 • Published 9 months ago

@brandingbrand/utils-base64 v11.88.1

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

This is a fork of https://github.com/mathiasbynens/base64

base64 Build status Code coverage status

base64 is a robust base64 encoder/decoder that is fully compatible with atob() and btoa(), written in JavaScript. The base64-encoding and -decoding algorithms it uses are fully RFC 4648 compliant.

Installation

Via npm:

npm install base-64

In a browser:

<script src="base64.js"></script>

In Narwhal, Node.js, and RingoJS:

var base64 = require('base-64');

In Rhino:

load('base64.js');

Using an AMD loader like RequireJS:

require({
  paths: {
    base64: 'path/to/base64',
  },
}, ['base64'], function (base64) {
  console.log(base64);
});

API

base64.version

A string representing the semantic version number.

base64.encode(input)

This function takes a byte string (the input parameter) and encodes it according to base64. The input data must be in the form of a string containing only characters in the range from U+0000 to U+00FF, each representing a binary byte with values 0x00 to 0xFF. The base64.encode() function is designed to be fully compatible with btoa() as described in the HTML Standard.

var encodedData = base64.encode(input);

To base64-encode any Unicode string, encode it as UTF-8 first:

var base64 = require('base-64');
var utf8 = require('utf8');

var text = 'foo © bar 𝌆 baz';
var bytes = utf8.encode(text);
var encoded = base64.encode(bytes);
console.log(encoded);
// → 'Zm9vIMKpIGJhciDwnYyGIGJheg=='

base64.decode(input)

This function takes a base64-encoded string (the input parameter) and decodes it. The return value is in the form of a string containing only characters in the range from U+0000 to U+00FF, each representing a binary byte with values 0x00 to 0xFF. The base64.decode() function is designed to be fully compatible with atob() as described in the HTML Standard.

var decodedData = base64.decode(encodedData);

To base64-decode UTF-8-encoded data back into a Unicode string, UTF-8-decode it after base64-decoding it:

var encoded = 'Zm9vIMKpIGJhciDwnYyGIGJheg==';
var bytes = base64.decode(encoded);
var text = utf8.decode(bytes);
console.log(text);
// → 'foo © bar 𝌆 baz'

Support

base64 is designed to work in at least Node.js v0.10.0, Narwhal 0.3.2, RingoJS 0.8-0.9, PhantomJS 1.9.0, Rhino 1.7RC4, as well as old and modern versions of Chrome, Firefox, Safari, Opera, and Internet Explorer.

Unit tests & code coverage

After cloning this repository, run npm install to install the dependencies needed for development and testing. You may want to install Istanbul globally using npm install istanbul -g.

Once that’s done, you can run the unit tests in Node using npm test or node tests/tests.js. To run the tests in Rhino, Ringo, Narwhal, and web browsers as well, use grunt test.

To generate the code coverage report, use grunt cover.

Author

twitter/mathias
Mathias Bynens

License

base64 is available under the MIT license.

12.0.0-alpha.20

10 months ago

12.0.0-alpha.19

10 months ago

12.0.0-alpha.17

10 months ago

12.0.0-alpha.18

10 months ago

11.88.0

9 months ago

11.88.1

9 months ago

12.0.0-alpha.13

11 months ago

12.0.0-alpha.14

11 months ago

12.0.0-alpha.15

11 months ago

12.0.0-alpha.16

11 months ago

11.87.1

11 months ago

12.0.0-alpha.11

12 months ago

12.0.0-alpha.12

11 months ago

11.87.0

11 months ago

12.0.0-alpha.10

1 year ago

12.0.0-alpha.9

1 year ago

12.0.0-alpha.8

1 year ago

12.0.0-alpha.7

1 year ago

12.0.0-alpha.6

1 year ago

11.79.0

1 year ago

11.81.0

1 year ago

11.80.0

1 year ago

11.75.1

2 years ago

11.75.0

2 years ago

11.73.1

2 years ago

11.73.0

2 years ago

11.77.1

1 year ago

11.77.0

2 years ago

11.76.0

2 years ago

11.74.0

2 years ago

11.78.0

1 year ago

11.76.1

2 years ago

11.72.0

2 years ago

11.71.2

2 years ago

11.71.1

2 years ago

11.71.0

2 years ago

11.68.0

2 years ago

11.70.0

2 years ago

11.69.0

2 years ago

11.64.0

2 years ago

11.66.0-alpha.0

2 years ago

11.66.0

2 years ago

11.65.0

2 years ago

11.63.0

2 years ago

11.64.0-alpha.0

2 years ago

11.67.0

2 years ago

11.55.0

2 years ago

11.56.0

2 years ago

11.57.0

2 years ago

11.58.0

2 years ago

11.59.0

2 years ago

11.54.0

2 years ago

11.62.0

2 years ago

11.61.0

2 years ago

11.60.0

2 years ago

11.39.0

2 years ago

11.50.0

2 years ago

11.51.0

2 years ago

11.52.0

2 years ago

11.53.0

2 years ago

11.44.0

2 years ago

11.45.0

2 years ago

11.46.0

2 years ago

11.47.0

2 years ago

11.48.0

2 years ago

11.49.0

2 years ago

11.40.0

2 years ago

11.41.0

2 years ago

11.42.0

2 years ago

11.43.0

2 years ago

11.35.0

2 years ago

11.36.0

2 years ago

11.37.0

2 years ago

11.38.0

2 years ago

11.34.0

2 years ago

11.33.0

2 years ago

11.32.0

2 years ago

11.31.0

2 years ago

11.30.0

2 years ago

11.29.0

2 years ago

11.28.0

2 years ago

11.27.0

2 years ago

11.26.1

2 years ago

11.26.0

2 years ago

11.25.1

2 years ago

11.25.0

2 years ago

11.24.0

2 years ago

11.23.0

2 years ago

11.22.0

2 years ago