base64-js
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Base64-js is a pure JavaScript module that provides basic base64 encoding and decoding functionality. While many browsers already support base64 encoding/decoding for text data, base64-js brings this functionality to all-purpose binary data, thus significantly expanding the use cases for base64 operations.
The base64-js module is simple to install and use. You can install it with npm using the command npm install base64-js
. After its installation, it can be included in your JavaScript files using var base64js = require('base64-js')
.
Working with base64-js is quite simple as it exposes three primary functions byteLength
, toByteArray
and fromByteArray
.
var base64js = require('base64-js');
// Assuming you have a base64 string, you can get the byte length as follows:
var base64String = 'your-base64string';
var byteLength = base64js.byteLength(base64String);
console.log(byteLength); // Outputs byte length of the string
// To get the byte array from a base64 string
var byteArray = base64js.toByteArray(base64String);
console.log(byteArray); // Outputs the byte array
// To convert a byte array to a base64 string
var byteArr = new Uint8Array([1, 2, 3]);
var base64Str = base64js.fromByteArray(byteArr);
console.log(base64Str); // Outputs the base64 string
The byteLength
function takes a base64 string and returns the length of the byte array. The toByteArray
function takes a base64 string and returns a byte array. Conversely, the fromByteArray
function takes a byte array and returns a base64 string.
As for the base64-js documentation, while it doesn't appear to have its own standalone website, the most comprehensive and updated descriptions, examples and usage guidelines can be found directly on its GitHub page at beatgammit/base64-js.