UNPKG

@hazae41/base64

Version:

Base64 adapter for WebAssembly and JS implementations

34 lines (30 loc) 1.03 kB
'use strict'; var index = require('../../libs/copiable/index.cjs'); var buffer = require('./buffer.cjs'); function fromBufferOrScure(scure) { if ("process" in globalThis) return buffer.fromBuffer(); return fromScure(scure); } function fromScure(scure) { const { base64, base64nopad } = scure; function getBytes(bytes) { return "bytes" in bytes ? bytes.bytes : bytes; } function encodePaddedOrThrow(bytes) { return base64.encode(getBytes(bytes)); } function decodePaddedOrThrow(text) { return new index.Copied(base64.decode(text)); } function encodeUnpaddedOrThrow(bytes) { return base64nopad.encode(getBytes(bytes)); } function decodeUnpaddedOrThrow(text) { return new index.Copied(base64nopad.decode(text)); } return { encodePaddedOrThrow, decodePaddedOrThrow, encodeUnpaddedOrThrow, decodeUnpaddedOrThrow }; } exports.fromBufferOrScure = fromBufferOrScure; exports.fromScure = fromScure; //# sourceMappingURL=scure.cjs.map