@hazae41/base64
Version:
Base64 adapter for JS implementations
31 lines (28 loc) • 997 B
JavaScript
import { Buffers } from '../../../libs/buffers/buffers.mjs';
import { Bytes } from '../../../libs/bytes/bytes.mjs';
import { fromNative } from '../native/index.mjs';
function fromNativeOrBuffer() {
if ("fromBase64" in Uint8Array)
return fromNative();
return fromBuffer();
}
function fromBuffer() {
return {
encodePaddedOrThrow(bytes) {
const unpadded = Buffers.fromView(bytes).toString("base64url");
const repadded = unpadded + "=".repeat((4 - unpadded.length % 4) % 4);
return repadded;
},
decodePaddedOrThrow(text) {
return Bytes.fromView(Buffer.from(text, "base64url"));
},
encodeUnpaddedOrThrow(bytes) {
return Buffers.fromView(bytes).toString("base64url");
},
decodeUnpaddedOrThrow(text) {
return Bytes.fromView(Buffer.from(text, "base64url"));
}
};
}
export { fromBuffer, fromNativeOrBuffer };
//# sourceMappingURL=index.mjs.map