4.1.13 • Published 16 days ago

@i-xi-dev/base64 v4.1.13

Weekly downloads
-
License
MIT
Repository
github
Last release
16 days ago

@i-xi-dev/base64

A JavaScript Base64 encoder and decoder, implements Forgiving base64 defined in WHATWG Infra Standard.

Requirement

Base64.Decoder and Base64.Encoder classes, and Base64 static class

ChromeEdgeFirefoxSafariDenoNode.js

Base64.DecoderStream and Base64.EncoderStream classes

These require TransformStream.

ChromeEdgeFirefoxSafariDenoNode.js
102+14.1+16.5+

Installation

npm

$ npm i @i-xi-dev/base64@4.1.13
import { Base64 } from "@i-xi-dev/base64";

CDN

Example for UNPKG

import { Base64 } from "https://www.unpkg.com/@i-xi-dev/base64@4.1.13/esm/mod.js";

Usage

Base64.Decoder and Base64.Encoder classes, and Base64 static class

const decoder = new Base64.Decoder();

decoder.decode("AwIBAP/+/fw=");
// → Uint8Array[ 0x03, 0x02, 0x01, 0x00, 0xFF, 0xFE, 0xFD, 0xFC ]
const encoder = new Base64.Encoder();

encoder.encode(Uint8Array.of(0x03, 0x02, 0x01, 0x00, 0xFF, 0xFE, 0xFD, 0xFC));
// → "AwIBAP/+/fw="
Base64.decode("AwIBAP/+/fw=");
// → Uint8Array[ 0x03, 0x02, 0x01, 0x00, 0xFF, 0xFE, 0xFD, 0xFC ]
Base64.encode(Uint8Array.of(0x03, 0x02, 0x01, 0x00, 0xFF, 0xFE, 0xFD, 0xFC));
// → "AwIBAP/+/fw="

Base64.DecoderStream and Base64.EncoderStream classes

const decoderStream = new Base64.DecoderStream();

// readableStream: ReadableStream<string>
// writableStream: WritableStream<Uint8Array>
readableStream.pipeThrough(decoderStream).pipeTo(writableStream);
const encoderStream = new Base64.EncoderStream();

// readableStream: ReadableStream<Uint8Array>
// writableStream: WritableStream<string>
readableStream.pipeThrough(encoderStream).pipeTo(writableStream);

Encoding options

See the documentation

Example

The options for Base 64 Encoding with URL and Filename Safe Alphabet, defined in RFC 4648

// use the predefined Base64.Options
const rfc4648urlOptions = Base64.Options.RFC4648URL;

const decoder = new Base64.Decoder(rfc4648urlOptions);
const encoder = new Base64.Encoder(rfc4648urlOptions);
const decoderStream = new Base64.DecoderStream(rfc4648urlOptions);
const encoderStream = new Base64.EncoderStream(rfc4648urlOptions);
const decoded = Base64.decode(str, rfc4648urlOptions);
const encoded = Base64.encode(uint8Array, rfc4648urlOptions);
// create Base64.Options
const rfc4648urlOptions = {
  /*
  rawTable: [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_" ],
  */
  tableLastChars: ["-", "_"],
  noPadding: true,
};

const decoder = new Base64.Decoder(rfc4648urlOptions);
const encoder = new Base64.Encoder(rfc4648urlOptions);
const decoderStream = new Base64.DecoderStream(rfc4648urlOptions);
const encoderStream = new Base64.EncoderStream(rfc4648urlOptions);
const decoded = Base64.decode(str, rfc4648urlOptions);
const encoded = Base64.encode(uint8Array, rfc4648urlOptions);

Examples

4.1.13

16 days ago

4.1.9

4 months ago

4.1.4

6 months ago

4.1.3

6 months ago

4.0.1

12 months ago

4.0.0

12 months ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.0

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.0

2 years ago

0.0.1

2 years ago