'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports.UrlSafer = void 0; (function (UrlSafer) { UrlSafer.isSafe = (input) => /^[\w-]*$/.test(input); UrlSafer.encode = (rawString) => { const encodedString = typeof window === 'undefined' ? Buffer.from(rawString, 'utf8').toString('base64') : window.btoa(encodeURIComponent(rawString)); // 使用 encodeURIComponent return UrlSafer.replaceNonUrlSafeCharacters(encodedString); }; UrlSafer.decode = (encodedString) => { const nonUrlSafeEncodedString = UrlSafer.restoreNonUrlSafeCharacters(encodedString); return typeof window === 'undefined' ? Buffer.from(nonUrlSafeEncodedString, 'base64').toString('utf8') : decodeURIComponent(window.atob(nonUrlSafeEncodedString)); // 使用 decodeURIComponent }; UrlSafer.replaceNonUrlSafeCharacters = (base64String) => base64String.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, ''); UrlSafer.restoreNonUrlSafeCharacters = (base64String) => base64String.replace(/-/g, '+').replace(/_/g, '/'); })(exports.UrlSafer || (exports.UrlSafer = {})); var UrlSafer = exports.UrlSafer; exports.default = UrlSafer; //# sourceMappingURL=index.cjs.map