is-base64
Predicate that returns true if base64 string.
Last updated 5 years ago by miguelmota .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install is-base64 
SYNC missed versions from official npm registry.

is-base64

Predicate that returns true if base64 string.

Install

npm 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)); // true
console.log(isBase64(stringWithMime)); // false
console.log(isBase64(stringWithMime, {allowMime: true})); // true
console.log(isBase64(string, {mimeRequired: true})); // false
console.log(isBase64(stringWithMime, {mimeRequired: true})); // true
console.log(isBase64('1342234')); // false
console.log(isBase64('afQ$%rfew')); // false
console.log(isBase64('dfasdfr342')); // false
console.log(isBase64('uuLMhh==')); // true
console.log(isBase64('uuLMhh')); // false
console.log(isBase64('uuLMhh', {paddingRequired: false})); // true
console.log(isBase64('')); // true
console.log(isBase64('', {allowEmpty: false})); // 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-base64
true

FAQ

  • Q: Why is empty string "" a valid base64 string by default?

License

MIT

Current Tags

  • 1.1.0                                ...           latest (5 years ago)

9 Versions

  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.1.0                                ...           6 years ago
  • 0.0.6                                ...           6 years ago
  • 0.0.5                                ...           6 years ago
  • 0.0.4                                ...           7 years ago
  • 0.0.3                                ...           7 years ago
  • 0.0.2                                ...           8 years ago
  • 0.0.1                                ...           9 years ago
Maintainers (1)
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE