is-base64
Predicate that returns true if base64 string.
Install
npm install is-base64
Usage
var isBase64 = ; var string = 'iVBORw0KGgoAAAAN ... kSuQmCC';var stringWithMime = 'data:image/png;base64,iVBORw0KGgoAAAA ... AAElFTkSuQmCC'; console; // trueconsole; // falseconsole; // trueconsole; // falseconsole; // trueconsole; // falseconsole; // falseconsole; // falseconsole; // trueconsole; // falseconsole; // trueconsole; // trueconsole; // false
API
isBase64(string, options)
-
{string} string - string to check if is valid base64 string
-
{object} [options]
- [options.allowEmpty=true] {boolean} - returns true for empty string
- [options.allowMime=false] {boolean} - returns true for valid strings with optional mime
- [options.mimeRequired=false] {boolean} - returns true for valid strings with mime
- [options.paddingRequired=true] {boolean} - returns true for valid strings with valid padding
CLI
Install CLI:
npm install -g is-base64
CLI example:
$ is-base64 aGVsbG8gd29ybGQ=true
Piping example:
$ echo aGVsbG8gd29ybGQ= | is-base64true
FAQ
-
Q: Why is empty string
""
a valid base64 string by default?-
A: According to RFC 4648 Section 10, the following is valid test vector:
BASE64("") = ""
-
License
MIT