# is-base64

> Predicate that returns true if base64 string.

Latest version **1.1.0** (published 2020-03-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-base64
pnpm add is-base64
yarn add is-base64
bun add is-base64
```

Provides the commands `is-base64`, `is_base64`.

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-03-04 |
| First published | 2015-05-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/is-base64) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | Miguel Mota |
| Maintainers | miguelmota |
| Keywords | predicate, base64, mime |

## Links

- npm: https://www.npmjs.com/package/is-base64
- Repository: https://github.com/miguelmota/is-base64
- Issues: https://github.com/miguelmota/is-base64/issues
- npm.io page: https://npm.io/package/is-base64

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2020-03-04
- 1.0.0 — 2019-08-31
- 0.1.0 — 2018-10-26
- 0.0.6 — 2018-07-24
- 0.0.5 — 2018-06-01
- 0.0.4 — 2017-06-20
- 0.0.3 — 2017-06-20
- 0.0.2 — 2016-11-18
- 0.0.1 — 2015-05-15

## README

# is-base64

> Predicate that returns true if [base64](https://en.wikipedia.org/wiki/Base64) string.

## Install

```bash
npm install is-base64
```

## Usage

```javascript
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:

```bash
npm install -g is-base64
```

CLI example:

```bash
$ is-base64 aGVsbG8gd29ybGQ=
true
```

Piping example:

```bash
$ echo aGVsbG8gd29ybGQ= | is-base64
true
```

## FAQ

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

  - A: According to [RFC 4648 Section 10](https://tools.ietf.org/html/rfc4648#section-10), the following is valid test vector:

      ```
      BASE64("") = ""
      ```

# License

MIT

---
_Source: https://npm.io/package/is-base64 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
