@hazae41/base64url
Version:
Base64Url adapter for WebAssembly and JS implementations
28 lines (25 loc) • 1.05 kB
JavaScript
import { Buffers } from '../../libs/buffers/buffers.mjs';
import { Bytes } from '../../libs/bytes/bytes.mjs';
import { Copied } from '../../libs/copiable/index.mjs';
function fromBuffer() {
function getBytes(bytes) {
return "bytes" in bytes ? bytes.bytes : bytes;
}
function encodePaddedOrThrow(bytes) {
const unpadded = Buffers.fromView(getBytes(bytes)).toString("base64url");
const repadded = unpadded + "=".repeat((4 - unpadded.length % 4) % 4);
return repadded;
}
function decodePaddedOrThrow(text) {
return new Copied(Bytes.fromView(Buffer.from(text, "base64url")));
}
function encodeUnpaddedOrThrow(bytes) {
return Buffers.fromView(getBytes(bytes)).toString("base64url");
}
function decodeUnpaddedOrThrow(text) {
return new Copied(Bytes.fromView(Buffer.from(text, "base64url")));
}
return { encodePaddedOrThrow, decodePaddedOrThrow, encodeUnpaddedOrThrow, decodeUnpaddedOrThrow };
}
export { fromBuffer };
//# sourceMappingURL=buffer.mjs.map