https://github.com/juanelas/base64
Base64 for both node.js and browser JavaScript. It supports URL-safe encoding and enabling/disabling padding. Buffers can be implemented using ArrayBuffer, any TypedArray or Buffer
https://github.com/juanelas/base64
arraybuffer bas64url base64 buffer typedarray uint8array
Last synced: 7 months ago
JSON representation
Base64 for both node.js and browser JavaScript. It supports URL-safe encoding and enabling/disabling padding. Buffers can be implemented using ArrayBuffer, any TypedArray or Buffer
- Host: GitHub
- URL: https://github.com/juanelas/base64
- Owner: juanelas
- License: mit
- Created: 2021-10-15T14:24:44.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-10T11:08:41.000Z (about 2 years ago)
- Last Synced: 2025-06-09T03:42:06.317Z (8 months ago)
- Topics: arraybuffer, bas64url, base64, buffer, typedarray, uint8array
- Language: JavaScript
- Homepage:
- Size: 891 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://opensource.org/licenses/MIT)
[](CODE_OF_CONDUCT.md)
[](https://standardjs.com)
[](https://github.com/juanelas/base64/actions/workflows/build-and-test.yml)
[](https://coveralls.io/github/juanelas/base64?branch=main)
# @juanelas/base64
Base64 for both node.js and browser javascript. It supports URL-safe encoding and enabling/disabling padding. Buffers can be implementedd using ArrayBuffer, any TypedArray, or Buffer.
## Usage
`@juanelas/base64` can be imported to your project with `npm`:
```console
npm install @juanelas/base64
```
Then either require (Node.js CJS):
```javascript
const base64 = require('@juanelas/base64')
```
or import (JavaScript ES module):
```javascript
import * as base64 from '@juanelas/base64'
```
The appropriate version for browser or node is automatically exported. Types for TypeScript users are also provided.
You can also download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/base64/main/dist/bundle.iife.js), the [ESM bundle](https://raw.githubusercontent.com/juanelas/base64/main/dist/esm/bundle.min.js) or the [UMD bundle](https://raw.githubusercontent.com/juanelas/base64/main/dist/bundle.umd.js) and manually add it to your project, or, if you have already installed `@juanelas/base64` in your project, just get the bundles from `node_modules/@juanelas/base64/dist/bundles/`.
An example of usage could be:
```typescript
import * as base64 from '@juanelas/base64'
const buf = new Uint8Array([254, 1, 128, 255])
const base64str = base64.encode(buf, true, false) // URL-safe base64 with no padding
console.log(base64str) // Outputs: '_gGA_w'
const buf2 = base64.decode(base64str) // URL-safe encoding and padding are automatically detected
console.log(buf2.toString()) // Outputs: '254,1,128,255'
const text = 'fooba'
const base64str2 = base64.encode(text) // Standard base64 with padding
console.log(base64str2) // Outputs: 'Zm9vYmE='
const text2 = base64.decode(base64str2, true) // Output to unicode string instead of Uint8Array
console.log(text2) // Outputs: 'fooba'
```
## API reference documentation
[Check the API](./docs/API.md)