UNPKG

visionary-base64url

Version:

A platform-agnostic library for URL-safe Base64 encoding and decoding.

19 lines (18 loc) 750 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decodeBase64Url = exports.encodeBase64Url = void 0; const js_base64_1 = require("js-base64"); const encodeBase64Url = (input) => { if (typeof input !== "string") { throw new Error("encodeBase64Url: input must be a string"); } return (0, js_base64_1.encode)(input).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); }; exports.encodeBase64Url = encodeBase64Url; const decodeBase64Url = (input) => { if (typeof input !== "string") { throw new Error("decodeBase64Url: input must be a string"); } return (0, js_base64_1.decode)(input.replace(/-/g, "+").replace(/_/g, "/")); }; exports.decodeBase64Url = decodeBase64Url;