UNPKG

@awhere/api

Version:

The awesome aWhere API for JavaScript.

47 lines 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.arrayBufferToBase64Url = arrayBufferToBase64Url; exports.arrayBufferFromBase64Url = arrayBufferFromBase64Url; exports.arrayBufferToHex = arrayBufferToHex; function arrayBufferToBase64Url(arrayBuffer) { // const binaryString = new Uint8Array(arrayBuffer).reduce((str, byte: number) => { // str += String.fromCharCode(byte); // return str; // }, ''); // return btoa(binaryString) // .replace(/\+/g, '-') // .replace(/\//g, '_') // .replace(/=+$/, ''); if (typeof process === 'undefined') { var binaryString = new Uint8Array(arrayBuffer).reduce(function (str, byte) { str += String.fromCharCode(byte); return str; }, ''); return btoa(binaryString) .replace(/\+/g, '-') .replace(/\//g, '_') .replace(/=+$/, ''); } else { return Buffer.from(arrayBuffer) .toString('base64') .replace(/\+/g, '-') .replace(/\//g, '_') .replace(/=+$/, ''); } } function arrayBufferFromBase64Url(base64Url) { // const raw = atob(base64Url.replace(/-/g, '+').replace(/_/g, '/')); // return new Uint8Array(raw.split('').map(char => char.charCodeAt(0))).buffer; if (typeof process === 'undefined') { var raw = atob(base64Url.replace(/-/g, '+').replace(/_/g, '/')); return new Uint8Array(raw.split('').map(function (char) { return char.charCodeAt(0); })).buffer; } else { return new Uint8Array(Buffer.from(base64Url.replace(/-/g, '+').replace(/_/g, '/'), 'base64')).buffer; } } function arrayBufferToHex(arrayBuffer) { return Array.from(new Uint8Array(arrayBuffer), function (dec) { return ('0' + dec.toString(16)).substr(-2); }).join(''); } //# sourceMappingURL=arrayBufferUtil.js.map