Giter Club home page Giter Club logo

abab's Introduction

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');

Checklists

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

Remembering atob vs. btoa

Here's a mnemonic that might be useful: if you have a plain string and want to base64 encode it, then decode it, btoa is what you run before (before - btoa), and atob is what you run after (after - atob).

abab's People

Contributors

amishne avatar bevacqua avatar jeffcarp avatar just-boris avatar timothygu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.