What is is-base64?
The is-base64 npm package is a utility for checking if a given string is a valid Base64 encoded string. It provides simple and straightforward methods to validate Base64 strings, making it useful for applications that need to handle or verify Base64 encoded data.
What are is-base64's main functionalities?
Validation of Base64 Strings
This feature allows you to check if a given string is a valid Base64 encoded string. The function returns true if the string is valid Base64 and false otherwise.
const isBase64 = require('is-base64');
const validBase64 = 'SGVsbG8gd29ybGQ=';
const invalidBase64 = 'Hello world';
console.log(isBase64(validBase64)); // true
console.log(isBase64(invalidBase64)); // false
Validation with Options
This feature allows you to validate Base64 strings with additional options. For example, you can specify whether to allow empty strings as valid Base64.
const isBase64 = require('is-base64');
const validBase64 = 'SGVsbG8gd29ybGQ=';
const invalidBase64 = 'Hello world';
console.log(isBase64(validBase64, { allowEmpty: false })); // true
console.log(isBase64('', { allowEmpty: false })); // false
Other packages similar to is-base64
base64-js
The base64-js package provides utilities for encoding and decoding Base64 strings. Unlike is-base64, which focuses solely on validation, base64-js offers functionality for both encoding and decoding Base64 data.
js-base64
The js-base64 package is a comprehensive library for Base64 encoding and decoding. It provides methods for encoding strings to Base64 and decoding Base64 strings back to their original form. This package offers more functionality compared to is-base64, which is limited to validation.
base-64
The base-64 package is a lightweight library for encoding and decoding Base64 strings. It is similar to js-base64 but with a smaller footprint. While is-base64 focuses on validation, base-64 provides encoding and decoding capabilities.
is-base64
Predicate that returns true if base64 string.
Install
npm install is-base64
bower install is-base64
Usage
var isBase64 = require('is-base64');
var string = 'iVBORw0KGgoAAAAN ... kSuQmCC';
var stringWithMime = 'data:image/png;base64,iVBORw0KGgoAAAA ... AAElFTkSuQmCC';
console.log(isBase64(string));
console.log(isBase64(stringWithMime));
console.log(isBase64('1342234'));
console.log(isBase64('afQ$%rfew'));
console.log(isBase64('dfasdfr342'));
License
MIT