Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

byte-base64

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

byte-base64

base64 utilities for TypeScript and JavaScript

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

byte-base64

base64 utilities for TypeScript and JavaScript.

This library allows you to encode all the following data structures to a base64-encoded string and back:

  • Uint8Array of bytes
  • JS array of bytes - encoded as numbers from 0 to 255
  • JS string - using any encoding supported by TextEncoder and TextDecoder

All other known solutions and approaches provide only a limited support for these features. In particular, atob and btoa only support ASCII strings.

byte-base64 is available as npm package.

npm i byte-base64

Consumption:

import * as base64 from "byte-base64";

Functions:

  • bytesToBase64(bytes: number[] | Uint8Array): string - Encodes a Uint8Array or JS array of bytes to a base64-encoded string.
  • base64ToBytes(str: string): Uint8Array - Decodes a base64-encoded string to a Uint8Array of bytes. If str is not a valid base64-encoded string, throws new Error("Unable to parse base64 string.").
  • base64encode(str: string, encoder: { encode: (str: string) => Uint8Array | number[] } = new TextEncoder()) - Encodes a JS string to a base64-encoded string using the specified character encoding. The encoding defaults to new TextEncoder() which represents UTF-8 encoding.
  • base64decode(str: string, decoder: { decode: (bytes: Uint8Array) => string } = new TextDecoder()) - Decodes a base64-encoded string to a JS string using the specified character encoding. The encoding defaults to new TextDecoder() which represents UTF-8 encoding. If str is not a valid base64-encoded string, throws new Error("Unable to parse base64 string.").

TextEncoder supports only UTF-8 encoding in the majority of browsers. For more encodings, consider using a polyfill.

Project license is MIT.

FAQs

Package last updated on 18 Aug 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc