Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hexagon/base64
Base64 and base64url to string or arraybuffer, and back. Works in Node, Deno or browser.
https://github.com/hexagon/base64
arraybuffer base64 base64url commonjs deno esm esmodule javascript node string typescript umd
Last synced: about 2 months ago
JSON representation
Base64 and base64url to string or arraybuffer, and back. Works in Node, Deno or browser.
- Host: GitHub
- URL: https://github.com/hexagon/base64
- Owner: Hexagon
- License: mit
- Created: 2021-12-28T00:15:37.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-18T20:06:27.000Z (4 months ago)
- Last Synced: 2024-10-30T08:20:10.366Z (3 months ago)
- Topics: arraybuffer, base64, base64url, commonjs, deno, esm, esmodule, javascript, node, string, typescript, umd
- Language: TypeScript
- Homepage: http://base64.56k.guru/
- Size: 1.32 MB
- Stars: 10
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: docs/contributing.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
Probably the only JavaScript base64 library you'll ever need!
# @hexagon/base64
Encode, decode and validate base64/base64url to string/arraybuffer and vice-versa. Works in Node, Deno and browser.
[![CI](https://github.com/Hexagon/base64/actions/workflows/test.yml/badge.svg)](https://github.com/Hexagon/base64/actions/workflows/test.yml)
[![npm version](https://badge.fury.io/js/@hexagon%2Fbase64.svg)](https://badge.fury.io/js/@hexagon%2Fbase64) [![NPM Downloads](https://img.shields.io/npm/dm/@hexagon/base64.svg)](https://www.npmjs.org/package/@hexagon/base64) [![jsdelivr](https://data.jsdelivr.com/v1/package/npm/@hexagon/base64/badge?style=rounded)](https://www.jsdelivr.com/package/npm/@hexagon/base64)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Hexagon/base64/blob/master/LICENSE)* Supports regular base64 and base64url
* Convert to/from string or arraybuffer
* Validate / identify base64 and base64url
* 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](https://www.typescriptlang.org/) typings.```javascript
// Encode string as regular base64
const example1enc = base64.fromString("Hellö Wörld, how are you doing today?!");
console.log(example1enc);
// > SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk/IQ==// Decode string as regular base64
const example1dec = base64.toString("SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk/IQ==");
console.log(example1dec);
// > Hellö Wörld, how are you doing today?!
```Full documentation available at [base64.56k.guru](https://base64.56k.guru)
## Quick Installation
**Node.js:**
```bash
npm install @hexagon/base64 --save
```**Deno (x):**
```js
import { base64 } from "https://deno.land/x/[email protected]/src/base64.ts";
```**Deno (jsr.io):**
```js
import { base64 } from "jsr:@hexagon/base64";
```For browser/cdn usage, refer to the documentation.
### Quick API
- __fromArrayBuffer(buffer, urlMode)__ - Encodes `ArrayBuffer` into base64 or base64url if urlMode(optional) is true
- __toArrayBuffer(str, urlMode)__ - Decodes base64url string (or base64url string if urlMode is true) to `ArrayBuffer`- __fromString(str, urlMode)__ - Encodes `String` into base64 string(base64url string if urlMode is true)
- __toString(str, urlMode)__ - Decodes base64 or base64url string to `String`- __validate(str, urlMode)__ - Returns true if `String` str is valid base64/base64 dependending on urlMode
## Contributing
See [Contribution Guide](https://base64.56k.guru/contributing.html)
## Donations
If you found this library helpful and wish to support its development, consider making a donation through [Hexagon's GitHub Sponsors page](https://github.com/sponsors/hexagon). Your generosity ensures the library's continued development and maintenance.
### Contributors
The underlying code is loosely based on [github.com/niklasvh/base64-arraybuffer](https://github.com/niklasvh/base64-arraybuffer)
## License
MIT