is-base64

WebJar for is-base64

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

is-base64
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

is-base64
WebJar for is-base64
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/miguelmota/is-base64

Download is-base64

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/is-base64/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>is-base64</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/is-base64/
implementation 'org.webjars.npm:is-base64:0.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/is-base64/
implementation ("org.webjars.npm:is-base64:0.1.0")
'org.webjars.npm:is-base64:jar:0.1.0'
<dependency org="org.webjars.npm" name="is-base64" rev="0.1.0">
  <artifact name="is-base64" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='is-base64', version='0.1.0')
)
libraryDependencies += "org.webjars.npm" % "is-base64" % "0.1.0"
[org.webjars.npm/is-base64 "0.1.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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

Versions

Version
0.1.0