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

js-base64

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-base64 - npm Package Compare versions

Comparing version 3.3.3 to 3.4.0

34

base64.d.ts

@@ -12,20 +12,20 @@ /**

*/
declare const version = "3.3.3";
declare const version = "3.4.0";
/**
* @deprecated use lowercase `version`.
*/
declare const VERSION = "3.3.3";
declare const VERSION = "3.4.0";
/**
* converts a Uint8Array to a Base64 string.
* @param {Boolean} [rfc4648] URL-and-filename-safe a la RFC4648
* @returns {String} Base64 string
*/
declare const fromUint8Array: (src: Uint8Array, rfc4648?: boolean) => string;
/**
* does what `window.btoa` of web browsers does.
* @param {String} src binary string
* @returns {String} Base64-encoded string
* @returns {string} Base64-encoded string
*/
declare const _btoa: (s: string) => string;
/**
* converts a Uint8Array to a Base64 string.
* @param {boolean} [rfc4648] URL-and-filename-safe a la RFC4648
* @returns {string} Base64 string
*/
declare const fromUint8Array: (u8a: Uint8Array, rfc4648?: boolean) => string;
/**
* @deprecated should have been internal use only.

@@ -38,4 +38,4 @@ * @param {string} src UTF-8 string

* converts a UTF-8-encoded string to a Base64 string.
* @param {Boolean} [rfc4648] if `true` make the result URL-safe
* @returns {String} Base64 string
* @param {boolean} [rfc4648] if `true` make the result URL-safe
* @returns {string} Base64 string
*/

@@ -45,3 +45,3 @@ declare const encode: (src: string, rfc4648?: boolean) => string;

* converts a UTF-8-encoded string to URL-safe Base64 RFC4648.
* @returns {String} Base64 string
* @returns {string} Base64 string
*/

@@ -58,3 +58,3 @@ declare const encodeURI: (src: string) => string;

* @param {String} src Base64-encoded string
* @returns {String} binary string
* @returns {string} binary string
*/

@@ -65,3 +65,3 @@ declare const _atob: (a: string) => string;

* @param {String} src Base64 string. Both normal and URL-safe are supported
* @returns {String} UTF-8 string
* @returns {string} UTF-8 string
*/

@@ -72,3 +72,3 @@ declare const decode: (src: string) => string;

*/
declare const toUint8Array: (a: string) => Uint8Array;
declare const toUint8Array: (a: string) => any;
declare const extendString: () => void;

@@ -90,4 +90,4 @@ declare const extendUint8Array: () => void;

decode: (src: string) => string;
fromUint8Array: (src: Uint8Array, rfc4648?: boolean) => string;
toUint8Array: (a: string) => Uint8Array;
fromUint8Array: (u8a: Uint8Array, rfc4648?: boolean) => string;
toUint8Array: (a: string) => any;
extendString: () => void;

@@ -94,0 +94,0 @@ extendUint8Array: () => void;

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

*/
const version = '3.3.3';
const version = '3.4.0';
/**

@@ -57,36 +57,44 @@ * @deprecated use lowercase `version`.

})(_b64chars);
const _fromCharCode = String.fromCharCode;
const _hasBuffer = typeof Buffer === 'function';
const _hasatob = typeof atob === 'function';
const _hasbtoa = typeof btoa === 'function';
const _fromCharCode = String.fromCharCode.bind(String);
const _U8Afrom = typeof Uint8Array.from === 'function'
? Uint8Array.from.bind(Uint8Array)
: (it, fn = (x) => x) => new Uint8Array(Array.prototype.slice.call(it, 0).map(fn));
const _mkUriSafe = (src) => src
.replace(/[+\/]/g, (m0) => m0 == '+' ? '-' : '_')
.replace(/=+$/m, '');
const _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, '');
/**
* converts a Uint8Array to a Base64 string.
* @param {Boolean} [rfc4648] URL-and-filename-safe a la RFC4648
* @returns {String} Base64 string
*/
const fromUint8Array = (src, rfc4648 = false) => {
let b64 = '';
for (let i = 0, l = src.length; i < l; i += 3) {
const [a0, a1, a2] = [src[i], src[i + 1], src[i + 2]];
const ord = (a0 << 16) | (a1 << 8) | a2;
b64 += _b64chars[(ord >>> 18)];
b64 += _b64chars[(ord >>> 12) & 63];
b64 += typeof a1 !== 'undefined' ? _b64chars[(ord >>> 6) & 63] : '=';
b64 += typeof a2 !== 'undefined' ? _b64chars[ord & 63] : '=';
}
return rfc4648 ? _mkUriSafe(b64) : b64;
};
/**
* does what `window.btoa` of web browsers does.
* @param {String} src binary string
* @returns {String} Base64-encoded string
* @returns {string} Base64-encoded string
*/
const _btoa = typeof btoa === 'function'
? (s) => btoa(s)
: (s) => {
if (s.match(/[^\x00-\xFF]/))
throw new RangeError('The string contains invalid characters.');
return fromUint8Array(Uint8Array.from(s, c => c.charCodeAt(0)));
const _btoa = _hasbtoa ? (s) => btoa(s)
: _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)));
};
const _fromUint8Array = _hasBuffer
? (u8a) => Buffer.from(u8a).toString('base64')
: (u8a) => {
// cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
const maxargs = 0x1000;
let strs = [];
for (let i = 0, l = u8a.length; i < l; i += maxargs) {
strs.push(_fromCharCode.apply(null, u8a.subarray(i, i + maxargs)));
}
return btoa(strs.join(''));
};
/**
* converts a Uint8Array to a Base64 string.
* @param {boolean} [rfc4648] URL-and-filename-safe a la RFC4648
* @returns {string} Base64 string
*/
const fromUint8Array = (u8a, rfc4648 = false) => rfc4648 ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a);
/**
* @deprecated should have been internal use only.

@@ -98,13 +106,16 @@ * @param {string} src UTF-8 string

/**
*
*/
const _encode = _hasBuffer
? (s) => Buffer.from(s, 'utf8').toString('base64')
: (s) => _btoa(utob(s));
/**
* converts a UTF-8-encoded string to a Base64 string.
* @param {Boolean} [rfc4648] if `true` make the result URL-safe
* @returns {String} Base64 string
* @param {boolean} [rfc4648] if `true` make the result URL-safe
* @returns {string} Base64 string
*/
const encode = (src, rfc4648 = false) => {
const b64 = _btoa(utob(src));
return rfc4648 ? _mkUriSafe(b64) : b64;
};
const encode = (src, rfc4648 = false) => rfc4648 ? _mkUriSafe(_encode(src)) : _encode(src);
/**
* converts a UTF-8-encoded string to URL-safe Base64 RFC4648.
* @returns {String} Base64 string
* @returns {string} Base64 string
*/

@@ -133,18 +144,15 @@ const encodeURI = (src) => encode(src, true);

* @param {String} src Base64-encoded string
* @returns {String} binary string
* @returns {string} binary string
*/
const _atob = typeof atob === 'function'
? (a) => atob(a)
: (a) => a.replace(/[^A-Za-z0-9\+\/]/g, '')
.replace(/\S{1,4}/g, _cb_decode);
const _decode = (a) => btou(_atob(a));
const _unURI = (a) => {
return a
.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/')
.replace(/[^A-Za-z0-9\+\/]/g, '');
};
const _atob = _hasatob ? (a) => atob(_tidyB64(a))
: _hasBuffer ? (a) => Buffer.from(a, 'base64').toString('binary')
: (a) => _tidyB64(a).replace(/\S{1,4}/g, _cb_decode);
const _decode = _hasBuffer
? (a) => Buffer.from(a, 'base64').toString('utf8')
: (a) => btou(_atob(a));
const _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/'));
/**
* converts a Base64 string to a UTF-8 string.
* @param {String} src Base64 string. Both normal and URL-safe are supported
* @returns {String} UTF-8 string
* @returns {string} UTF-8 string
*/

@@ -155,5 +163,5 @@ const decode = (src) => _decode(_unURI(src));

*/
const toUint8Array = (a) => {
return Uint8Array.from(_atob(_unURI(a)), c => c.charCodeAt(0));
};
const toUint8Array = _hasBuffer
? (a) => _U8Afrom(Buffer.from(_unURI(a), 'base64'))
: (a) => _U8Afrom(_atob(_unURI(a)), c => c.charCodeAt(0));
const _noEnum = (v) => {

@@ -221,3 +229,3 @@ return {

//
gBase64.Base64 = Object.assign({}, gBase64);
gBase64.Base64 = { ...gBase64 };
return gBase64;

@@ -224,0 +232,0 @@ }));

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

@@ -14,3 +14,3 @@ "main": "base64.js",

"scripts": {
"test": "make test"
"test": "make clean && make test"
},

@@ -17,0 +17,0 @@ "devDependencies": {

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

Yet another Base64 transcoder
Yet another [Base64] transcoder.
[Base64]: http://en.wikipedia.org/wiki/Base64
## HEADS UP: switch to TypeScript since version 3.3

@@ -31,3 +33,3 @@

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

@@ -37,12 +39,4 @@

### node.js (commonjs)
### As an ES6 Module
```javascript
const Base64 = require('js-base64').Base64;
```
Unlike the case above, the global context is no longer modified.
### As a ES6 Module
locally…

@@ -64,3 +58,3 @@

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

@@ -72,6 +66,24 @@ ```

// or if you prefer no Base64 namespace
import { encode, decode } from 'https://cdn.jsdelivr.net/npm/js-base64@3.3.3/base64.mjs';
import { encode, decode } from 'https://cdn.jsdelivr.net/npm/js-base64@3.4.0/base64.mjs';
</script>
```
### node.js (commonjs)
```javascript
const {Base64} = require('js-base64');
```
Unlike the case above, the global context is no longer modified.
You can also use [esm] to `import` instead of `require`.
[esm]: https://github.com/standard-things/esm
```javascript
require=require('esm')(module);
import {Base64} from 'js-base64';
```
## SYNOPSIS

@@ -149,4 +161,8 @@

## SEE ALSO
### If you really, really need an ES5 version
+ http://en.wikipedia.org/wiki/Base64
You can transpiles to an ES5 that runs on IE11. Do the following in your shell.
```shell
$ make base64.es5.js
```

Sorry, the diff of this file is not supported yet

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