# url-safe-base64

> url safe base64 en- and decoding

Latest version **1.3.0** (published 2022-12-23) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install url-safe-base64
pnpm add url-safe-base64
yarn add url-safe-base64
bun add url-safe-base64
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2022-12-23 |
| First published | 2017-04-20 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | commenthol@gmail.com |
| Maintainers | commenthol |
| Keywords | base64, safe, url |

## Links

- npm: https://www.npmjs.com/package/url-safe-base64
- Repository: https://github.com/commenthol/url-safe-base64
- Homepage: https://github.com/commenthol/url-safe-base64#readme
- Issues: https://github.com/commenthol/url-safe-base64/issues
- npm.io page: https://npm.io/package/url-safe-base64

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.3.0 (latest) — 2022-12-23
- 1.2.0 — 2022-03-27
- 1.1.1 — 2019-10-26
- 1.1.0 — 2017-06-25
- 1.0.0 — 2017-04-20

## README

# url-safe-base64

> url safe base64 en- and decoding

[![NPM version](https://badge.fury.io/js/url-safe-base64.svg)](https://www.npmjs.com/package/url-safe-base64/)

## TOC

* [Example](#example)
* [API](#api)
  * [`encode(base64)`](#encodebase64)
  * [`decode(safe)`](#decodesafe)
  * [`trim(string)`](#trimstr)
  * [`isBase64(string)`](#isbase64string)
  * [`isUrlSafeBase64(string)`](#isurlsafebase64string)
* [Installation](#installation)
* [Tests](#tests)
* [LICENSE](#license)

## Example

```js
import {
  encode, decode, trim,
  isBase64, isUrlSafeBase64
} from 'url-safe-base64'
const safe = encode('A/B+C==')
// > 'A-B_C=='
trim(safe)
// > 'A-B_C'
const base64 = decode(safe)
// > 'A/B+C=='
isBase64(base64)
// > true
isBase64(safe)
// > false
isUrlSafeBase64(base64)
// > false
isUrlSafeBase64(safe)
// > true
```

## API

### `encode(base64)`

encode base64 string url safe

**Parameters**

| parameter | type   | description             |
| --------- | ------ | ----------------------- |
| `base64`  | String | base64 encoded string |

**Returns** `String`, url-safe-base64 encoded


### `decode(safe)`

decode url-safe-base64 string to base64

**Parameters**

| parameter | type   | description              |
| --------- | ------ | ------------------------ |
| `safe`    | String | - url-safe-base64 string |

**Returns** `String`, base64 encoded


### `trim(string)`

trim padding - `window.atob` might handle trimmed strings, e.g. in Chrome@57, Firefox@52

**Parameters**

| parameter | type   | description                        |
| --------- | ------ | ---------------------------------- |
| `string`  | String | - base64 or url-safe-base64 string |

**Returns** `String`, string with padding chars removed


### `isBase64(string)`

checks if `string` is base64 encoded

**Returns** `Boolean`, true if base64 encoded


### `isUrlSafeBase64(string)`

checks if `string` is url-safe-base64 encoded

**Returns** `Boolean`, true if url-safe-base64 encoded

## Installation

```sh
$ npm install --save url-safe-base64
```

## Tests

```sh
$ npm test
```

## LICENSE

UNLICENSE <https://unlicense.org/>

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