Socket
Socket
Sign inDemoInstall

@hexagon/base64

Package Overview
Dependencies
0
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @hexagon/base64

Base64 and base64url to string or arraybuffer, and back. Node, Deno or browser.


Version published
Weekly downloads
63K
decreased by-14.53%
Maintainers
1
Install size
30.6 kB
Created
Weekly downloads
 

Readme

Source

@hexagon/base64

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.

Node.js CI Deno CI npm version NPM Downloads jsdelivr Codacy Badge MIT 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 typings.
// 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

Quick Installation

Node.js: npm install @hexagon/base64 --save

Deno: import base64 from "https://deno.land/x/b64@1.1.28/src/base64.js";

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

Donations

If you found this library helpful and wish to support its development, consider making a donation through Hexagon's GitHub Sponsors page. Your generosity ensures the library's continued development and maintenance.

Contributors

The underlying code is loosely based on github.com/niklasvh/base64-arraybuffer

License

MIT

Keywords

FAQs

Last updated on 18 Sep 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc