UNPKG

serde-fns

Version:

simple shapes and procedures for serde with a pit-of-success

14 lines 751 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deSerialBase64 = exports.asSerialBase64 = exports.isSerialBase64 = void 0; const type_fns_1 = require("type-fns"); exports.isSerialBase64 = (0, type_fns_1.withAssure)((input) => { if (typeof input !== 'string') return false; return /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/.test(input); }); const asSerialBase64 = (input) => exports.isSerialBase64.assure(btoa(unescape(encodeURIComponent(input)))); // todo: make this work on node exports.asSerialBase64 = asSerialBase64; const deSerialBase64 = (input) => decodeURIComponent(escape(window.atob(input))); exports.deSerialBase64 = deSerialBase64; //# sourceMappingURL=base64.js.map