UNPKG

@ace-util/core

Version:
73 lines 2.34 kB
var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; import { warn } from './tools'; /** * Safe json parse */ export function jsonSafeParse() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var value; var isValid = false; try { value = JSON.parse.apply(JSON, __spreadArray([], __read(args), false)); isValid = true; } catch (err) { warn(process.env.NODE_ENV === 'production', "JSON safe parse error: ".concat(err)); } return isValid ? value : undefined; } /** * Serialize to string json option */ export function jsonSerializeReviver(key, value) { if (typeof value === 'function') { return value + ''; } return value; } // const UCT_DATE_REG = /^\d{4}-[0-1]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-6]\d(.\d{3})?((\+|\-)\d\d(:)?\d\d|Z)$/; /** * Deserialize from string option */ export function jsonDeserializeReviver(scope) { if (scope === void 0) { scope = {}; } return function (key, value) { if ((value === null || value === void 0 ? void 0 : value.indexOf) && value.indexOf('function') > -1) { // Function return new Function('$root', "with($root){ return (".concat(value, "); }"))(scope); } // else if (include.includes('DATE') && !exclude.includes('DATE') && UCT_DATE_REG.test(value)) { // // UCT Date // return new Date(value); // } return value; }; } //# sourceMappingURL=json.js.map