Socket
Socket
Sign inDemoInstall

base-64

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

base-64

A robust base64 encoder/decoder that is fully compatible with `atob()` and `btoa()`, written in JavaScript.


Version published
Maintainers
1
Weekly downloads
2,293,568
decreased by-26.44%

Weekly downloads

Package description

What is base-64?

The base-64 npm package is a robust base64 encoder/decoder that is fully compatible with `atob()` and `btoa()`, built to work in a browser or Node.js environment. It allows users to encode and decode strings to and from base64, a binary-to-text encoding scheme that represents binary data in an ASCII string format.

What are base-64's main functionalities?

Encoding a string to base64

This feature allows you to encode a UTF-8 string into a base64 encoded string. The code sample demonstrates how to encode the string 'Hello, World!' to base64.

"use strict";\nvar base64 = require('base-64');\nvar utf8 = require('utf8');\n\nvar text = 'Hello, World!';\nvar bytes = utf8.encode(text);\nvar encoded = base64.encode(bytes);\nconsole.log(encoded); // Outputs: SGVsbG8sIFdvcmxkIQ==

Decoding a base64 string to UTF-8

This feature allows you to decode a base64 encoded string back into a UTF-8 string. The code sample demonstrates how to decode the base64 string 'SGVsbG8sIFdvcmxkIQ==' back to 'Hello, World!'.

"use strict";\nvar base64 = require('base-64');\nvar utf8 = require('utf8');\n\nvar encoded = 'SGVsbG8sIFdvcmxkIQ==';\nvar bytes = base64.decode(encoded);\nvar text = utf8.decode(bytes);\nconsole.log(text); // Outputs: Hello, World!

Other packages similar to base-64

Readme

Source

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.

Keywords

FAQs

Last updated on 17 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc