Socket
Socket
Sign inDemoInstall

abab

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

abab

WHATWG spec-compliant implementations of window.atob and window.btoa.


Version published
Maintainers
1
Weekly downloads
14,511,994
decreased by-17.69%
Install size
10.9 kB

Weekly downloads

Package description

What is abab?

The abab npm package is a utility that provides Base64 encoding and decoding as well as window.atob and window.btoa polyfills for Node.js. It is designed to mimic the behavior of these methods in the web browser environment.

What are abab's main functionalities?

Base64 Encoding

This feature allows you to encode a string to Base64. The provided code sample demonstrates how to encode the string 'Hello, World!' using the btoa function.

"use strict";
const abab = require('abab');
let encodedData = abab.btoa('Hello, World!');
console.log(encodedData); // Outputs: SGVsbG8sIFdvcmxkIQ==

Base64 Decoding

This feature allows you to decode a Base64 encoded string. The provided code sample demonstrates how to decode the string 'SGVsbG8sIFdvcmxkIQ==' using the atob function.

"use strict";
const abab = require('abab');
let decodedData = abab.atob('SGVsbG8sIFdvcmxkIQ==');
console.log(decodedData); // Outputs: Hello, World!

Other packages similar to abab

Readme

Source

abab npm version Build Status

A JavaScript module that implements window.atob and window.btoa according the forgiving-base64 algorithm in the Infra Standard. The original code was forked from w3c/web-platform-tests.

Compatibility: Node.js version 3+ and all major browsers.

Install with npm:

npm install abab

API

btoa (base64 encode)

const { btoa } = require('abab');
btoa('Hello, world!'); // 'SGVsbG8sIHdvcmxkIQ=='

atob (base64 decode)

const { atob } = require('abab');
atob('SGVsbG8sIHdvcmxkIQ=='); // 'Hello, world!'
Valid characters

Per the spec, btoa will accept strings "containing only characters in the range U+0000 to U+00FF." If passed a string with characters above U+00FF, btoa will return null. If atob is passed a string that is not base64-valid, it will also return null. In both cases when null is returned, the spec calls for throwing a DOMException of type InvalidCharacterError.

Browsers

If you want to include just one of the methods to save bytes in your client-side code, you can require the desired module directly.

const atob = require('abab/lib/atob');
const btoa = require('abab/lib/btoa');

Development

If you're submitting a PR or deploying to npm, please use the checklists in CONTRIBUTING.md.

Remembering what atob and btoa stand for

Base64 comes from IETF RFC 4648 (2006).

  • btoa, the encoder function, stands for binary to ASCII, meaning it converts any binary input into a subset of ASCII (Base64).
  • atob, the decoder function, converts ASCII (or Base64) to its original binary format.

Keywords

FAQs

Last updated on 17 Apr 2022

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