@endo/base64
Advanced tools
Comparing version 0.2.7 to 0.2.8
@@ -6,2 +6,11 @@ # Change Log | ||
### [0.2.8](https://github.com/endojs/endo/compare/@endo/base64@0.2.7...@endo/base64@0.2.8) (2021-09-18) | ||
### Features | ||
* **base64:** Polyfill on XSnap ([#889](https://github.com/endojs/endo/issues/889)) ([f4f10e2](https://github.com/endojs/endo/commit/f4f10e2e30637fdb6b2925c65f6fcf7901aa907e)) | ||
### [0.2.7](https://github.com/endojs/endo/compare/@endo/base64@0.2.6...@endo/base64@0.2.7) (2021-08-14) | ||
@@ -8,0 +17,0 @@ |
{ | ||
"name": "@endo/base64", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"description": "Transcodes base64", | ||
@@ -40,3 +40,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@endo/eslint-config": "^0.3.14", | ||
"@endo/eslint-config": "^0.3.15", | ||
"ava": "^3.12.1", | ||
@@ -80,3 +80,3 @@ "babel-eslint": "^10.0.3", | ||
}, | ||
"gitHead": "d95b3951c50dbaf3b6f7cdc52f0fc8ad166d9c4e" | ||
"gitHead": "619005298bde41e3013b8d704db543c0888a239f" | ||
} |
// @ts-check | ||
/* eslint no-bitwise: ["off"] */ | ||
/* global globalThis */ | ||
@@ -10,2 +11,7 @@ import { monodu64, padding } from './common.js'; | ||
* | ||
* XSnap is a JavaScript engine based on Moddable/XS. | ||
* The algorithm below is orders of magnitude too slow on this VM, but it | ||
* arranges a native binding on the global object. | ||
* We use that if it is available instead. | ||
* | ||
* @param {string} string Base64-encoded string | ||
@@ -16,3 +22,3 @@ * @param {string} [name] The name of the string as it will appear in error | ||
*/ | ||
export function decodeBase64(string, name = '<unknown>') { | ||
const jsDecodeBase64 = (string, name = '<unknown>') => { | ||
const data = new Uint8Array(Math.ceil((string.length * 4) / 3)); | ||
@@ -57,2 +63,5 @@ let register = 0; | ||
return data.subarray(0, j); | ||
} | ||
}; | ||
export const decodeBase64 = | ||
globalThis.Base64 !== undefined ? globalThis.Base64.decode : jsDecodeBase64; |
// @ts-check | ||
/* eslint no-bitwise: ["off"] */ | ||
/* global globalThis */ | ||
@@ -10,6 +11,11 @@ import { alphabet64, padding } from './common.js'; | ||
* | ||
* XSnap is a JavaScript engine based on Moddable/XS. | ||
* The algorithm below is orders of magnitude too slow on this VM, but it | ||
* arranges a native binding on the global object. | ||
* We use that if it is available instead. | ||
* | ||
* @param {Uint8Array} data | ||
* @returns {string} base64 encoding | ||
*/ | ||
export function encodeBase64(data) { | ||
const jsEncodeBase64 = data => { | ||
// A cursory benchmark shows that string concatenation is about 25% faster | ||
@@ -58,2 +64,5 @@ // than building an array and joining it in v8, in 2020, for strings of about | ||
return string; | ||
} | ||
}; | ||
export const encodeBase64 = | ||
globalThis.Base64 !== undefined ? globalThis.Base64.encode : jsEncodeBase64; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21070
139