New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

b2a

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

b2a - npm Package Compare versions

Comparing version 1.0.12 to 1.1.0

es/atobu.js

4

es/index.js
import btoa from './btoa';
import btoau from './btoau';
import atob from './atob';
export { btoa, atob };
import atobu from './atobu';
export { btoa, btoau, atob, atobu };

@@ -54,2 +54,6 @@ 'use strict';

var btoau = (function (input) {
return btoa$1(input).replace(/\+/g, '-').replace(/\//g, '_');
});
var E$1 = error('The string to be decoded is not correctly encoded');

@@ -92,3 +96,9 @@ var _atob = typeof atob !== 'undefined'

var atobu = (function (input) {
return atob$1(input.replace(/-/g, '+').replace(/_/g, '/'));
});
exports.atob = atob$1;
exports.atobu = atobu;
exports.btoa = btoa$1;
exports.btoau = btoau;
{
"name": "b2a",
"version": "1.0.12",
"version": "1.1.0",
"description": "btoa and atob (ie base64 encoding and decoding) support for node.js or old browsers, with the Unicode Problems fixed",

@@ -11,6 +11,10 @@ "main": "lib/index.js",

"build:es": "BABEL_ENV=es babel --out-dir es src",
"test": "BABEL_ENV=ava nyc ava --verbose --timeout=10s",
"prepublish": "npm run build",
"report-cov": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"posttest": "npm run report-cov"
"test:only": "BABEL_ENV=ava nyc ava --verbose --timeout=10s",
"test:dev": "npm run test:only && npm run report:dev",
"test": "npm run test:only",
"prepublishOnly": "npm run build",
"posttest": "npm run report",
"report": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"report:dev": "nyc report --reporter=html && npm run report:open",
"report:open": "open coverage/index.html"
},

@@ -56,16 +60,16 @@ "files": [

"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/cli": "^7.5.5",
"@babel/plugin-transform-arrow-functions": "^7.2.0",
"@babel/plugin-transform-block-scoping": "^7.4.4",
"@babel/preset-env": "^7.4.5",
"@babel/register": "^7.4.4",
"ava": "^2.1.0",
"@babel/plugin-transform-block-scoping": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/register": "^7.5.5",
"ava": "^2.2.0",
"codecov": "^3.5.0",
"eslint-config-ostai": "^3.0.0",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-import": "^2.18.2",
"nyc": "^14.1.1",
"rollup": "^1.16.2",
"rollup": "^1.19.3",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-node-resolve": "^5.0.4"
"rollup-plugin-node-resolve": "^5.2.0"
}
}

@@ -20,3 +20,3 @@ [![Build Status](https://travis-ci.org/kaelzhang/b2a.svg?branch=master)](https://travis-ci.org/kaelzhang/b2a)

The common problem of other libraries is that they fail to encode 16-bit strings. Since DOMStrings are 16-bit-encoded strings, in most browsers calling `window.btoa` on a Unicode string will cause a `'Character Out Of Range'` exception if a character exceeds the range of a 8-bit byte (`0x00~0xFF`).
The common problem of other libraries is that they fail to encode 16-bit strings. Since DOMStrings are 16-bit-encoded strings, in most browsers calling `window.btoa` on a Unicode string will cause a `'Character Out Of Range'` exception if a character exceeds the range of a 8-bit byte (`0x00~0xFF`).

@@ -35,8 +35,15 @@ This module will try to reuse `window.atob` and `window.btoa` when possible.

import {
// Encode a string in base-64
btoa,
// Decode a string in base-64
atob,
btoa
// Encode a string into base64url
btoau,
// Decode a base64url-encoded string
atobu
} from 'b2a'
btoa('a') // 'YQ=='
window.btoa('a') // 'YQ==', works fine with ASCII characters
btoa('a') // 'YQ=='
window.btoa('a') // 'YQ==', works fine with ASCII characters

@@ -47,15 +54,30 @@

// will cause a Character Out Of Range exception.
window.btoa('中文') // throws InvalidCharacterError
window.btoa('中文') // throws InvalidCharacterError ❌
btoa('中文') // '5Lit5paH'
btoa('中文') // '5Lit5paH' ✅
// Oooooooops!
window.atob('5Lit5paH') // '中æ', oh no!
window.atob('5Lit5paH') // '中æ', oh no! ❌
atob('5Lit5paH') // '中文', great!
atob('5Lit5paH') // '中文', great! ✅
btoau('μπορούμε') // zrzPgM6_z4HOv8-NzrzOtQ==
atobu('zrzPgM6_z4HOv8-NzrzOtQ==') // μπορούμε
```
### `base64url` support since 1.1.0
Since `1.1.0`, `btoau` and `atobu` are introduced to encode and decode in [base64url](https://en.wikipedia.org/wiki/Base64#URL_applications) format.
```js
import {btoau} from 'b2a'
location.href = `https://domain.com/login?return_to=${btoau(location.href)}`
```
## License
MIT
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