nativescript-akylas-bluetooth
Version:
Connect to and interact with Bluetooth LE peripherals
38 lines • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
function InvalidCharacterError(message) {
this.message = message;
}
InvalidCharacterError.prototype = new Error();
InvalidCharacterError.prototype.name = 'InvalidCharacterError';
function btoa(input) {
var str = String(input);
var output = '';
for (var block = void 0, charCode = void 0, idx = 0, map = chars; str.charAt(idx | 0) || ((map = '='), idx % 1); output += map.charAt(63 & (block >> (8 - (idx % 1) * 8)))) {
charCode = str.charCodeAt((idx += 3 / 4));
if (charCode > 0xff) {
throw new InvalidCharacterError("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");
}
block = (block << 8) | charCode;
}
return output;
}
exports.btoa = btoa;
function atob(input) {
var str = String(input).replace(/=+$/, '');
if (str.length % 4 === 1) {
throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded.");
}
var output = '';
for (var bc = 0, bs = void 0, buffer = void 0, idx = 0; (buffer = str.charAt(idx++)); ~buffer &&
((bs = bc % 4 ? bs * 64 + buffer : buffer),
bc++ % 4)
? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6))))
: 0) {
buffer = chars.indexOf(buffer);
}
return output;
}
exports.atob = atob;
//# sourceMappingURL=base64.js.map