Socket
Socket
Sign inDemoInstall

js-base64

Package Overview
Dependencies
0
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.4.1 to 3.4.2

12

base64.d.ts

@@ -12,7 +12,7 @@ /**

*/
declare const version = "3.4.1";
declare const version = "3.4.2";
/**
* @deprecated use lowercase `version`.
*/
declare const VERSION = "3.4.1";
declare const VERSION = "3.4.2";
/**

@@ -23,3 +23,3 @@ * does what `window.btoa` of web browsers does.

*/
declare const _btoa: (s: string) => string;
declare const _btoa: (bin: string) => string;
/**

@@ -59,3 +59,3 @@ * converts a Uint8Array to a Base64 string.

*/
declare const _atob: (a: string) => string;
declare const _atob: (asc: string) => string;
/**

@@ -77,4 +77,4 @@ * converts a Base64 string to a UTF-8 string.

VERSION: string;
atob: (a: string) => string;
btoa: (s: string) => string;
atob: (asc: string) => string;
btoa: (bin: string) => string;
fromBase64: (src: string) => string;

@@ -81,0 +81,0 @@ toBase64: (src: string, rfc4648?: boolean) => string;

@@ -43,3 +43,3 @@

*/
const version = '3.4.1';
const version = '3.4.2';
/**

@@ -49,6 +49,8 @@ * @deprecated use lowercase `version`.

const VERSION = version;
const _hasBuffer = typeof Buffer === 'function';
const _hasatob = typeof atob === 'function';
const _hasbtoa = typeof btoa === 'function';
const _fromCharCode = String.fromCharCode.bind(String);
const _hasBuffer = typeof Buffer === 'function';
const b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
const _fromCC = String.fromCharCode.bind(String);
const _U8Afrom = typeof Uint8Array.from === 'function'

@@ -66,9 +68,20 @@ ? Uint8Array.from.bind(Uint8Array)

*/
const _btoa = _hasbtoa ? (s) => btoa(s)
const _btoa = _hasbtoa ? (bin) => btoa(bin)
: _hasBuffer
? (s) => Buffer.from(s, 'binary').toString('base64')
: (s) => {
if (s.match(/[^\x00-\xFF]/))
throw new RangeError('The string contains invalid characters.');
return fromUint8Array(_U8Afrom(s, c => c.charCodeAt(0)));
? (bin) => Buffer.from(bin, 'binary').toString('base64')
: (bin) => {
let u32, c0, c1, c2, asc = '';
const pad = bin.length % 3;
for (let i = 0; i < bin.length;) {
if ((c0 = bin.charCodeAt(i++)) > 255 ||
(c1 = bin.charCodeAt(i++)) > 255 ||
(c2 = bin.charCodeAt(i++)) > 255)
throw new TypeError('invalid character found');
u32 = (c0 << 16) | (c1 << 8) | c2;
asc += b64ch.charAt(u32 >> 18 & 63)
+ b64ch.charAt(u32 >> 12 & 63)
+ b64ch.charAt(u32 >> 6 & 63)
+ b64ch.charAt(u32 & 63);
}
return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
};

@@ -82,3 +95,3 @@ const _fromUint8Array = _hasBuffer

for (let i = 0, l = u8a.length; i < l; i += maxargs) {
strs.push(_fromCharCode.apply(null, u8a.subarray(i, i + maxargs)));
strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
}

@@ -127,6 +140,20 @@ return btoa(strs.join(''));

*/
const _atob = _hasatob ? (a) => atob(_tidyB64(a))
: _hasBuffer ? (a) => Buffer.from(a, 'base64').toString('binary')
: (a) => {
throw ReferenceError('neither `atob` nor `Buffer` is available ');
const _atob = _hasatob ? (asc) => atob(_tidyB64(asc)) :
_hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary') :
(asc) => {
asc = asc.replace(/\s+/g, '');
if (!b64re.test(asc))
throw new TypeError('malformed base64.');
asc += '=='.slice(2 - (asc.length & 3));
let u24, bin = '', r1, r2;
for (let i = 0; i < asc.length;) {
u24 = b64ch.indexOf(asc.charAt(i++)) << 18
| b64ch.indexOf(asc.charAt(i++)) << 12
| (r1 = b64ch.indexOf(asc.charAt(i++))) << 6
| (r2 = b64ch.indexOf(asc.charAt(i++)));
bin += r1 === 64 ? _fromCC(u24 >> 16 & 255)
: r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255)
: _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);
}
return bin;
};

@@ -133,0 +160,0 @@ const _decode = _hasBuffer

{
"name": "js-base64",
"version": "3.4.1",
"version": "3.4.2",
"description": "Yet another Base64 transcoder in pure-JS",

@@ -5,0 +5,0 @@ "main": "base64.js",

@@ -32,3 +32,3 @@ [![build status](https://secure.travis-ci.org/dankogai/js-base64.png)](http://travis-ci.org/dankogai/js-base64)

```html
<script src="https://cdn.jsdelivr.net/npm/js-base64@3.4.1/base64.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-base64@3.4.2/base64.min.js"></script>
```

@@ -56,3 +56,3 @@

// note jsdelivr.net does not automatically minify .mjs
import { Base64 } from 'https://cdn.jsdelivr.net/npm/js-base64@3.4.1/base64.mjs';
import { Base64 } from 'https://cdn.jsdelivr.net/npm/js-base64@3.4.2/base64.mjs';
</script>

@@ -64,3 +64,3 @@ ```

// or if you prefer no Base64 namespace
import { encode, decode } from 'https://cdn.jsdelivr.net/npm/js-base64@3.4.1/base64.mjs';
import { encode, decode } from 'https://cdn.jsdelivr.net/npm/js-base64@3.4.2/base64.mjs';
</script>

@@ -67,0 +67,0 @@ ```

Sorry, the diff of this file is not supported yet

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