@hexagon/base64
Base64 and base64url to string or arraybuffer, and back.
- Support regular base64, and base64url
- Convert to/from string or ArrayBuffers
- Works in Node.js >=4.0 (both require and import).
- Works in Deno >=1.16.
- Works in browsers as standalone, UMD or ES-module.
- Includes TypeScript typings.
Installation
Node.js
npm install @hexagon/base64 --save
JavaScript
import base64 from "@hexagon/base64";
const base64 = require("@hexagon/base64");
TypeScript
Note that only default export is available in Node.js TypeScript, as the commonjs module is used internally.
import base64 from "@hexagon/base64";
Deno
JavaScript
import base64 from "https://cdn.jsdelivr.net/gh/hexagon/base64@1/src/base64.js";
TypeScript
import { base64 } from "https://cdn.jsdelivr.net/gh/hexagon/base64@1/src/base64.js";
Browser
Manual
- Download latest zipball
- Unpack
- Grab
base64.min.js
(UMD and standalone) or base64.min.mjs
(ES-module) from the dist/ folder
CDN
To use as a UMD-module (stand alone, RequireJS etc.)
<script src="https://cdn.jsdelivr.net/npm/@hexagon/base64@1/dist/base64.min.js"></script>
To use as a ES-module
<script type="module">
import base64 from "https://cdn.jsdelivr.net/npm/@hexagon/base64@/dist/base64.min.mjs";
</script>
Documentation
Full documentation available at hexagon.github.io/base64.
API
The library encodes and decodes base64/base64url to and from ArrayBuffers
-
fromArrayBuffer(buffer) - Encodes ArrayBuffer
into base64 string
-
toArrayBuffer(str) - Decodes base64 string to ArrayBuffer
-
fromArrayBuffer(buffer, true) - Encodes ArrayBuffer
into base64url string
-
toArrayBuffer(str, true) - Decodes base64url string to ArrayBuffer
-
fromString(str) - Encodes String
into base64 string
-
toString(str) - Decodes base64 string to String
-
fromString(buffer, true) - Encodes String
into base64url string
-
toString(str, true) - Decodes base64url string to String
Contributing
See Contribution Guide
License
MIT