diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 5a2559b..0000000 --- a/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "grumbler-scripts/config/.babelrc-browser" -} \ No newline at end of file diff --git a/.flowconfig b/.flowconfig index e864dc9..ada3a63 100644 --- a/.flowconfig +++ b/.flowconfig @@ -4,7 +4,6 @@ .*/node_modules/npm .*/node_modules/eslint-plugin-compat .*/node_modules/jsonlint -.*/dist/module [include] [libs] flow-typed diff --git a/.gitignore b/.gitignore index 457b569..0bcdad4 100644 --- a/.gitignore +++ b/.gitignore @@ -52,4 +52,7 @@ flow-typed .idea .DS_Store -package-lock.json \ No newline at end of file +package-lock.json + +/es +/lib diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 26a0dcc..75e5baf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,8 +25,6 @@ $ npm install # Run scripts to verify installation $ npm test -$ npm run-script lint -$ npm run-script cover ``` ## Making Changes diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..f0119ac --- /dev/null +++ b/babel.config.js @@ -0,0 +1,23 @@ +// eslint-disable-next-line import/no-commonjs,flowtype/require-valid-file-annotation +module.exports = (api) => { + const modules = api.env() === 'esm' ? false : 'auto'; + return { + extends: 'grumbler-scripts/config/.babelrc-browser', + presets: [ + [ + '@babel/env', + { + modules + } + ] + ], + plugins: [ + [ + '@babel/plugin-transform-runtime', + { + 'useESModules': !modules + } + ] + ] + }; +}; diff --git a/dist/module/button/create.js b/dist/module/button/create.js deleted file mode 100644 index ca2b410..0000000 --- a/dist/module/button/create.js +++ /dev/null @@ -1,7 +0,0 @@ -export function createButton(container, text, onClick) { - var button = document.createElement('button'); - button.innerText = text; - button.addEventListener('click', onClick); - container.appendChild(button); - return button; -} \ No newline at end of file diff --git a/dist/module/button/index.js b/dist/module/button/index.js deleted file mode 100644 index cda8d63..0000000 --- a/dist/module/button/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from './create'; \ No newline at end of file diff --git a/dist/module/common.js b/dist/module/common.js deleted file mode 100644 index cd13c8a..0000000 --- a/dist/module/common.js +++ /dev/null @@ -1,59 +0,0 @@ -import { TYPE } from './constants'; -export function isSerializedType(item) { - return typeof item === 'object' && item !== null && typeof item.__type__ === 'string'; -} -export function determineType(val) { - if (typeof val === 'undefined') { - return TYPE.UNDEFINED; - } - - if (val === null) { - return TYPE.NULL; - } - - if (Array.isArray(val)) { - return TYPE.ARRAY; - } - - if (typeof val === 'function') { - return TYPE.FUNCTION; - } - - if (typeof val === 'object') { - if (val instanceof Error) { - return TYPE.ERROR; - } - - if (typeof val.then === 'function') { - return TYPE.PROMISE; - } - - if (Object.prototype.toString.call(val) === '[object RegExp]') { - return TYPE.REGEX; - } - - if (Object.prototype.toString.call(val) === '[object Date]') { - return TYPE.DATE; - } - - return TYPE.OBJECT; - } - - if (typeof val === 'string') { - return TYPE.STRING; - } - - if (typeof val === 'number') { - return TYPE.NUMBER; - } - - if (typeof val === 'boolean') { - return TYPE.BOOLEAN; - } -} -export function serializeType(type, val) { - return { - __type__: type, - __val__: val - }; -} \ No newline at end of file diff --git a/dist/module/constants.js b/dist/module/constants.js deleted file mode 100644 index f761605..0000000 --- a/dist/module/constants.js +++ /dev/null @@ -1,14 +0,0 @@ -export var TYPE = { - FUNCTION: 'function', - ERROR: 'error', - PROMISE: 'promise', - REGEX: 'regex', - DATE: 'date', - ARRAY: 'array', - OBJECT: 'object', - STRING: 'string', - NUMBER: 'number', - BOOLEAN: 'boolean', - NULL: 'null', - UNDEFINED: 'undefined' -}; \ No newline at end of file diff --git a/dist/module/deserialize.js b/dist/module/deserialize.js deleted file mode 100644 index 683a6c6..0000000 --- a/dist/module/deserialize.js +++ /dev/null @@ -1,51 +0,0 @@ -var _DESERIALIZER; - -import { TYPE } from './constants'; -import { determineType, isSerializedType } from './common'; -import { deserializeFunction, deserializeError, deserializePromise, deserializeRegex, deserializeDate, deserializeArray, deserializeObject, deserializeString, deserializeNumber, deserializeBoolean, deserializeNull } from './serializers'; -// $FlowFixMe -var DESERIALIZER = (_DESERIALIZER = {}, _DESERIALIZER[TYPE.FUNCTION] = deserializeFunction, _DESERIALIZER[TYPE.ERROR] = deserializeError, _DESERIALIZER[TYPE.PROMISE] = deserializePromise, _DESERIALIZER[TYPE.REGEX] = deserializeRegex, _DESERIALIZER[TYPE.DATE] = deserializeDate, _DESERIALIZER[TYPE.ARRAY] = deserializeArray, _DESERIALIZER[TYPE.OBJECT] = deserializeObject, _DESERIALIZER[TYPE.STRING] = deserializeString, _DESERIALIZER[TYPE.NUMBER] = deserializeNumber, _DESERIALIZER[TYPE.BOOLEAN] = deserializeBoolean, _DESERIALIZER[TYPE.NULL] = deserializeNull, _DESERIALIZER); // $FlowFixMe - -var defaultDeserializers = {}; -export function deserialize(str, deserializers) { - if (deserializers === void 0) { - deserializers = defaultDeserializers; - } - - if (str === TYPE.UNDEFINED) { - // $FlowFixMe - return; - } - - function replacer(key, val) { - if (isSerializedType(this)) { - return val; - } - - var type; - var value; - - if (isSerializedType(val)) { - type = val.__type__; - value = val.__val__; - } else { - type = determineType(val); - value = val; - } - - if (!type) { - return value; - } // $FlowFixMe - - - var deserializer = deserializers[type] || DESERIALIZER[type]; - - if (!deserializer) { - return value; - } - - return deserializer(value, key); - } - - return JSON.parse(str, replacer); -} \ No newline at end of file diff --git a/dist/module/index.js b/dist/module/index.js deleted file mode 100644 index 449140b..0000000 --- a/dist/module/index.js +++ /dev/null @@ -1,6 +0,0 @@ -export * from './serialize'; -export * from './deserialize'; -export * from './serializers'; -export * from './constants'; -export * from './common'; -export * from './types'; \ No newline at end of file diff --git a/dist/module/index.js.flow b/dist/module/index.js.flow deleted file mode 100644 index bed7f67..0000000 --- a/dist/module/index.js.flow +++ /dev/null @@ -1,114 +0,0 @@ -// @flow - -declare class Class0 extends Element { - - accessKey: string; - accessKeyLabel: string; - className: string; - contentEditable: string; - contextMenu: ?HTMLMenuElement; - dataset: {[key: string]: string}; - dir: "ltr" | "rtl" | "auto"; - draggable: boolean; - dropzone: any; - hidden: boolean; - id: string; - innerHTML: string; - isContentEditable: boolean; - itemProp: any; - itemScope: boolean; - itemType: any; - itemValue: Object; - lang: string; - offsetHeight: number; - offsetLeft: number; - offsetParent: Element; - offsetTop: number; - offsetWidth: number; - onabort: ?Function; - onblur: ?Function; - oncancel: ?Function; - oncanplay: ?Function; - oncanplaythrough: ?Function; - onchange: ?Function; - onclick: ?Function; - oncuechange: ?Function; - ondblclick: ?Function; - ondurationchange: ?Function; - onemptied: ?Function; - onended: ?Function; - onerror: ?Function; - onfocus: ?Function; - oninput: ?Function; - oninvalid: ?Function; - onkeydown: ?Function; - onkeypress: ?Function; - onkeyup: ?Function; - onload: ?Function; - onloadeddata: ?Function; - onloadedmetadata: ?Function; - onloadstart: ?Function; - onmousedown: ?Function; - onmouseenter: ?Function; - onmouseleave: ?Function; - onmousemove: ?Function; - onmouseout: ?Function; - onmouseover: ?Function; - onmouseup: ?Function; - onmousewheel: ?Function; - onpause: ?Function; - onplay: ?Function; - onplaying: ?Function; - onprogress: ?Function; - onratechange: ?Function; - onreadystatechange: ?Function; - onreset: ?Function; - onresize: ?Function; - onscroll: ?Function; - onseeked: ?Function; - onseeking: ?Function; - onselect: ?Function; - onshow: ?Function; - onstalled: ?Function; - onsubmit: ?Function; - onsuspend: ?Function; - ontimeupdate: ?Function; - ontoggle: ?Function; - onvolumechange: ?Function; - onwaiting: ?Function; - properties: any; - spellcheck: boolean; - style: CSSStyleDeclaration; - tabIndex: number; - title: string; - translate: boolean; - blur(): void; - click(): void; - focus(): void; - forceSpellcheck(): void; - getBoundingClientRect(): ClientRect; -} -declare class Class1 { - - AT_TARGET: number; - BUBBLING_PHASE: number; - CAPTURING_PHASE: number; - bubbles: boolean; - cancelable: boolean; - currentTarget: EventTarget; - deepPath?: () => Array; - defaultPrevented: boolean; - eventPhase: number; - isTrusted: boolean; - scoped: boolean; - srcElement: Element; - target: EventTarget; - timeStamp: number; - type: string; - constructor(type: string, eventInitDict?: {bubbles?: boolean, cancelable?: boolean, composed?: boolean, scoped?: boolean}): void; - initEvent(type: string, bubbles: boolean, cancelable: boolean): void; - preventDefault(): void; - stopImmediatePropagation(): void; - stopPropagation(): void; -} -declare export function createButton(container: Class0, text: string, onClick: (event: Class1) => void): Class0; diff --git a/dist/module/serialize.js b/dist/module/serialize.js deleted file mode 100644 index bb3b29b..0000000 --- a/dist/module/serialize.js +++ /dev/null @@ -1,44 +0,0 @@ -var _SERIALIZER; - -import { TYPE } from './constants'; -import { determineType, isSerializedType } from './common'; -import { serializeFunction, serializeError, serializePromise, serializeRegex, serializeDate, serializeArray, serializeObject, serializeString, serializeNumber, serializeBoolean, serializeNull } from './serializers'; -var SERIALIZER = (_SERIALIZER = {}, _SERIALIZER[TYPE.FUNCTION] = serializeFunction, _SERIALIZER[TYPE.ERROR] = serializeError, _SERIALIZER[TYPE.PROMISE] = serializePromise, _SERIALIZER[TYPE.REGEX] = serializeRegex, _SERIALIZER[TYPE.DATE] = serializeDate, _SERIALIZER[TYPE.ARRAY] = serializeArray, _SERIALIZER[TYPE.OBJECT] = serializeObject, _SERIALIZER[TYPE.STRING] = serializeString, _SERIALIZER[TYPE.NUMBER] = serializeNumber, _SERIALIZER[TYPE.BOOLEAN] = serializeBoolean, _SERIALIZER[TYPE.NULL] = serializeNull, _SERIALIZER); // $FlowFixMe - -var defaultSerializers = {}; -export function serialize(obj, serializers) { - if (serializers === void 0) { - serializers = defaultSerializers; - } - - function replacer(key) { - var val = this[key]; - - if (isSerializedType(this)) { - return val; - } - - var type = determineType(val); - - if (!type) { - return val; - } // $FlowFixMe - - - var serializer = serializers[type] || SERIALIZER[type]; - - if (!serializer) { - return val; - } - - return serializer(val, key); - } - - var result = JSON.stringify(obj, replacer); - - if (typeof result === 'undefined') { - return TYPE.UNDEFINED; - } - - return result; -} \ No newline at end of file diff --git a/dist/module/serializers/array.js b/dist/module/serializers/array.js deleted file mode 100644 index 18e9554..0000000 --- a/dist/module/serializers/array.js +++ /dev/null @@ -1,6 +0,0 @@ -export function serializeArray(val) { - return val; -} -export function deserializeArray(val) { - return val; -} \ No newline at end of file diff --git a/dist/module/serializers/boolean.js b/dist/module/serializers/boolean.js deleted file mode 100644 index 2fafc26..0000000 --- a/dist/module/serializers/boolean.js +++ /dev/null @@ -1,6 +0,0 @@ -export function serializeBoolean(val) { - return val; -} -export function deserializeBoolean(val) { - return val; -} \ No newline at end of file diff --git a/dist/module/serializers/date.js b/dist/module/serializers/date.js deleted file mode 100644 index 877f1ba..0000000 --- a/dist/module/serializers/date.js +++ /dev/null @@ -1,8 +0,0 @@ -import { serializeType } from '../common'; -import { TYPE } from '../constants'; -export function serializeDate(val) { - return serializeType(TYPE.DATE, val.toJSON()); -} -export function deserializeDate(val) { - return new Date(val); -} \ No newline at end of file diff --git a/dist/module/serializers/error.js b/dist/module/serializers/error.js deleted file mode 100644 index 12d221d..0000000 --- a/dist/module/serializers/error.js +++ /dev/null @@ -1,23 +0,0 @@ -import { serializeType } from '../common'; -import { TYPE } from '../constants'; -// $FlowFixMe -export function serializeError(_ref) { - var message = _ref.message, - stack = _ref.stack, - code = _ref.code; - return serializeType(TYPE.ERROR, { - message: message, - stack: stack, - code: code - }); -} -export function deserializeError(_ref2) { - var message = _ref2.message, - stack = _ref2.stack, - code = _ref2.code; - var error = new Error(message); // $FlowFixMe - - error.code = code; - error.stack = stack + "\n\n" + error.stack; - return error; -} \ No newline at end of file diff --git a/dist/module/serializers/function.js b/dist/module/serializers/function.js deleted file mode 100644 index bf222fe..0000000 --- a/dist/module/serializers/function.js +++ /dev/null @@ -1,5 +0,0 @@ -export function serializeFunction() {// pass -} -export function deserializeFunction() { - throw new Error("Function serialization is not implemented; nothing to deserialize"); -} \ No newline at end of file diff --git a/dist/module/serializers/index.js b/dist/module/serializers/index.js deleted file mode 100644 index 50a8786..0000000 --- a/dist/module/serializers/index.js +++ /dev/null @@ -1,11 +0,0 @@ -export * from './array'; -export * from './boolean'; -export * from './date'; -export * from './error'; -export * from './function'; -export * from './number'; -export * from './object'; -export * from './promise'; -export * from './regex'; -export * from './string'; -export * from './null'; \ No newline at end of file diff --git a/dist/module/serializers/null.js b/dist/module/serializers/null.js deleted file mode 100644 index ebd3a19..0000000 --- a/dist/module/serializers/null.js +++ /dev/null @@ -1,6 +0,0 @@ -export function serializeNull(val) { - return val; -} -export function deserializeNull(val) { - return val; -} \ No newline at end of file diff --git a/dist/module/serializers/number.js b/dist/module/serializers/number.js deleted file mode 100644 index f222448..0000000 --- a/dist/module/serializers/number.js +++ /dev/null @@ -1,6 +0,0 @@ -export function serializeNumber(val) { - return val; -} -export function deserializeNumber(val) { - return val; -} \ No newline at end of file diff --git a/dist/module/serializers/object.js b/dist/module/serializers/object.js deleted file mode 100644 index cbbe6f5..0000000 --- a/dist/module/serializers/object.js +++ /dev/null @@ -1,6 +0,0 @@ -export function serializeObject(val) { - return val; -} -export function deserializeObject(val) { - return val; -} \ No newline at end of file diff --git a/dist/module/serializers/promise.js b/dist/module/serializers/promise.js deleted file mode 100644 index bc47bfc..0000000 --- a/dist/module/serializers/promise.js +++ /dev/null @@ -1,5 +0,0 @@ -export function serializePromise() {// pass -} -export function deserializePromise() { - throw new Error("Promise serialization is not implemented; nothing to deserialize"); -} \ No newline at end of file diff --git a/dist/module/serializers/regex.js b/dist/module/serializers/regex.js deleted file mode 100644 index f143670..0000000 --- a/dist/module/serializers/regex.js +++ /dev/null @@ -1,9 +0,0 @@ -import { serializeType } from '../common'; -import { TYPE } from '../constants'; -export function serializeRegex(val) { - return serializeType(TYPE.REGEX, val.source); -} -export function deserializeRegex(val) { - // eslint-disable-next-line security/detect-non-literal-regexp - return new RegExp(val); -} \ No newline at end of file diff --git a/dist/module/serializers/string.js b/dist/module/serializers/string.js deleted file mode 100644 index cf59635..0000000 --- a/dist/module/serializers/string.js +++ /dev/null @@ -1,6 +0,0 @@ -export function serializeString(val) { - return val; -} -export function deserializeString(val) { - return val; -} \ No newline at end of file diff --git a/dist/module/types.js b/dist/module/types.js deleted file mode 100644 index bbacffc..0000000 --- a/dist/module/types.js +++ /dev/null @@ -1,3 +0,0 @@ -import { TYPE } from './constants'; // export something to force webpack to see this as an ES module - -export var TYPES = true; // eslint-disable-next-line flowtype/require-exact-type \ No newline at end of file diff --git a/dist/universalSerialize.js b/dist/universalSerialize.js index 8a9c57e..78859e6 100644 --- a/dist/universalSerialize.js +++ b/dist/universalSerialize.js @@ -1,2 +1,2 @@ -!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define("universal-serialize",[],n):"object"==typeof exports?exports["universal-serialize"]=n():e["universal-serialize"]=n()}("undefined"!=typeof self?self:this,function(){return function(e){var n={};function r(t){if(n[t])return n[t].exports;var i=n[t]={i:t,l:!1,exports:{}};return e[t].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=n,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,n){if(1&n&&(e=r(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var i in e)r.d(t,i,function(n){return e[n]}.bind(null,i));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="",r(r.s=0)}([function(e,n,r){"use strict";r.r(n);var t,i={FUNCTION:"function",ERROR:"error",PROMISE:"promise",REGEX:"regex",DATE:"date",ARRAY:"array",OBJECT:"object",STRING:"string",NUMBER:"number",BOOLEAN:"boolean",NULL:"null",UNDEFINED:"undefined"};function o(e){return"object"==typeof e&&null!==e&&"string"==typeof e.__type__}function u(e){return void 0===e?i.UNDEFINED:null===e?i.NULL:Array.isArray(e)?i.ARRAY:"function"==typeof e?i.FUNCTION:"object"==typeof e?e instanceof Error?i.ERROR:"function"==typeof e.then?i.PROMISE:"[object RegExp]"===Object.prototype.toString.call(e)?i.REGEX:"[object Date]"===Object.prototype.toString.call(e)?i.DATE:i.OBJECT:"string"==typeof e?i.STRING:"number"==typeof e?i.NUMBER:"boolean"==typeof e?i.BOOLEAN:void 0}function f(e,n){return{__type__:e,__val__:n}}function c(e){return e}function a(e){return e}function l(e){return e}function s(e){return e}function d(e){return f(i.DATE,e.toJSON())}function E(e){return new Date(e)}function p(e){var n=e.message,r=e.stack,t=e.code;return f(i.ERROR,{message:n,stack:r,code:t})}function R(e){var n=e.message,r=e.stack,t=e.code,i=new Error(n);return i.code=t,i.stack=r+"\n\n"+i.stack,i}function y(){}function N(){throw new Error("Function serialization is not implemented; nothing to deserialize")}function O(e){return e}function z(e){return e}function b(e){return e}function v(e){return e}function _(){}function m(){throw new Error("Promise serialization is not implemented; nothing to deserialize")}function g(e){return f(i.REGEX,e.source)}function T(e){return new RegExp(e)}function S(e){return e}function A(e){return e}function j(e){return e}function D(e){return e}var I,U=((t={})[i.FUNCTION]=y,t[i.ERROR]=p,t[i.PROMISE]=_,t[i.REGEX]=g,t[i.DATE]=d,t[i.ARRAY]=c,t[i.OBJECT]=b,t[i.STRING]=S,t[i.NUMBER]=O,t[i.BOOLEAN]=l,t[i.NULL]=j,t),x={};function B(e,n){void 0===n&&(n=x);var r=JSON.stringify(e,function(e){var r=this[e];if(o(this))return r;var t=u(r);if(!t)return r;var i=n[t]||U[t];return i?i(r,e):r});return void 0===r?i.UNDEFINED:r}var P=((I={})[i.FUNCTION]=N,I[i.ERROR]=R,I[i.PROMISE]=m,I[i.REGEX]=T,I[i.DATE]=E,I[i.ARRAY]=a,I[i.OBJECT]=v,I[i.STRING]=A,I[i.NUMBER]=z,I[i.BOOLEAN]=s,I[i.NULL]=D,I),L={};function M(e,n){if(void 0===n&&(n=L),e!==i.UNDEFINED)return JSON.parse(e,function(e,r){if(o(this))return r;var t,i;if(o(r)?(t=r.__type__,i=r.__val__):(t=u(r),i=r),!t)return i;var f=n[t]||P[t];return f?f(i,e):i})}r.d(n,"serialize",function(){return B}),r.d(n,"deserialize",function(){return M}),r.d(n,"serializeArray",function(){return c}),r.d(n,"deserializeArray",function(){return a}),r.d(n,"serializeBoolean",function(){return l}),r.d(n,"deserializeBoolean",function(){return s}),r.d(n,"serializeDate",function(){return d}),r.d(n,"deserializeDate",function(){return E}),r.d(n,"serializeError",function(){return p}),r.d(n,"deserializeError",function(){return R}),r.d(n,"serializeFunction",function(){return y}),r.d(n,"deserializeFunction",function(){return N}),r.d(n,"serializeNumber",function(){return O}),r.d(n,"deserializeNumber",function(){return z}),r.d(n,"serializeObject",function(){return b}),r.d(n,"deserializeObject",function(){return v}),r.d(n,"serializePromise",function(){return _}),r.d(n,"deserializePromise",function(){return m}),r.d(n,"serializeRegex",function(){return g}),r.d(n,"deserializeRegex",function(){return T}),r.d(n,"serializeString",function(){return S}),r.d(n,"deserializeString",function(){return A}),r.d(n,"serializeNull",function(){return j}),r.d(n,"deserializeNull",function(){return D}),r.d(n,"TYPE",function(){return i}),r.d(n,"isSerializedType",function(){return o}),r.d(n,"determineType",function(){return u}),r.d(n,"serializeType",function(){return f}),r.d(n,"TYPES",function(){return!0})}])}); +!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define("universal-serialize",[],n):"object"==typeof exports?exports["universal-serialize"]=n():e["universal-serialize"]=n()}("undefined"!=typeof self?self:this,(function(){return function(e){var n={};function r(t){if(n[t])return n[t].exports;var i=n[t]={i:t,l:!1,exports:{}};return e[t].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=n,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,n){if(1&n&&(e=r(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var i in e)r.d(t,i,function(n){return e[n]}.bind(null,i));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return{}.hasOwnProperty.call(e,n)},r.p="",r(r.s=0)}([function(e,n,r){"use strict";r.r(n),r.d(n,"serialize",(function(){return B})),r.d(n,"deserialize",(function(){return M})),r.d(n,"serializeArray",(function(){return O})),r.d(n,"deserializeArray",(function(){return z})),r.d(n,"serializeBoolean",(function(){return S})),r.d(n,"deserializeBoolean",(function(){return A})),r.d(n,"serializeDate",(function(){return N})),r.d(n,"deserializeDate",(function(){return y})),r.d(n,"serializeError",(function(){return l})),r.d(n,"deserializeError",(function(){return s})),r.d(n,"serializeFunction",(function(){return c})),r.d(n,"deserializeFunction",(function(){return a})),r.d(n,"serializeNumber",(function(){return g})),r.d(n,"deserializeNumber",(function(){return T})),r.d(n,"serializeObject",(function(){return v})),r.d(n,"deserializeObject",(function(){return b})),r.d(n,"serializePromise",(function(){return d})),r.d(n,"deserializePromise",(function(){return E})),r.d(n,"serializeRegex",(function(){return R})),r.d(n,"deserializeRegex",(function(){return p})),r.d(n,"serializeString",(function(){return _})),r.d(n,"deserializeString",(function(){return m})),r.d(n,"serializeNull",(function(){return D})),r.d(n,"deserializeNull",(function(){return j})),r.d(n,"TYPE",(function(){return i})),r.d(n,"isSerializedType",(function(){return u})),r.d(n,"determineType",(function(){return o})),r.d(n,"serializeType",(function(){return f})),r.d(n,"TYPES",(function(){return F}));var t,i={FUNCTION:"function",ERROR:"error",PROMISE:"promise",REGEX:"regex",DATE:"date",ARRAY:"array",OBJECT:"object",STRING:"string",NUMBER:"number",BOOLEAN:"boolean",NULL:"null",UNDEFINED:"undefined"};function u(e){return"object"==typeof e&&null!==e&&"string"==typeof e.__type__}function o(e){return void 0===e?i.UNDEFINED:null===e?i.NULL:Array.isArray(e)?i.ARRAY:"function"==typeof e?i.FUNCTION:"object"==typeof e?e instanceof Error?i.ERROR:"function"==typeof e.then?i.PROMISE:"[object RegExp]"==={}.toString.call(e)?i.REGEX:"[object Date]"==={}.toString.call(e)?i.DATE:i.OBJECT:"string"==typeof e?i.STRING:"number"==typeof e?i.NUMBER:"boolean"==typeof e?i.BOOLEAN:void 0}function f(e,n){return{__type__:e,__val__:n}}function c(){}function a(){throw new Error("Function serialization is not implemented; nothing to deserialize")}function l(e){return f(i.ERROR,{message:e.message,stack:e.stack,code:e.code})}function s(e){var n=e.stack,r=e.code,t=new Error(e.message);return t.code=r,t.stack=n+"\n\n"+t.stack,t}function d(){}function E(){throw new Error("Promise serialization is not implemented; nothing to deserialize")}function R(e){return f(i.REGEX,e.source)}function p(e){return new RegExp(e)}function N(e){return f(i.DATE,e.toJSON())}function y(e){return new Date(e)}function O(e){return e}function z(e){return e}function v(e){return e}function b(e){return e}function _(e){return e}function m(e){return e}function g(e){return e}function T(e){return e}function S(e){return e}function A(e){return e}function D(e){return e}function j(e){return e}var I,U=((t={})[i.FUNCTION]=c,t[i.ERROR]=l,t[i.PROMISE]=d,t[i.REGEX]=R,t[i.DATE]=N,t[i.ARRAY]=O,t[i.OBJECT]=v,t[i.STRING]=_,t[i.NUMBER]=g,t[i.BOOLEAN]=S,t[i.NULL]=D,t),x={};function B(e,n){void 0===n&&(n=x);var r=JSON.stringify(e,(function(e){var r=this[e];if(u(this))return r;var t=o(r);if(!t)return r;var i=n[t]||U[t];return i?i(r,e):r}));return void 0===r?i.UNDEFINED:r}var P=((I={})[i.FUNCTION]=a,I[i.ERROR]=s,I[i.PROMISE]=E,I[i.REGEX]=p,I[i.DATE]=y,I[i.ARRAY]=z,I[i.OBJECT]=b,I[i.STRING]=m,I[i.NUMBER]=T,I[i.BOOLEAN]=A,I[i.NULL]=j,I),L={};function M(e,n){if(void 0===n&&(n=L),e!==i.UNDEFINED)return JSON.parse(e,(function(e,r){if(u(this))return r;var t,i;if(u(r)?(t=r.__type__,i=r.__val__):(t=o(r),i=r),!t)return i;var f=n[t]||P[t];return f?f(i,e):i}))}var F=!0}])})); //# sourceMappingURL=universalSerialize.js.map \ No newline at end of file diff --git a/dist/universalSerialize.js.map b/dist/universalSerialize.js.map index 0f6c71c..d9caf9e 100644 --- a/dist/universalSerialize.js.map +++ b/dist/universalSerialize.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://universal-serialize/webpack/universalModuleDefinition","webpack://universal-serialize/webpack/bootstrap","webpack://universal-serialize/./src/constants.js","webpack://universal-serialize/./src/common.js","webpack://universal-serialize/./src/serializers/array.js","webpack://universal-serialize/./src/serializers/boolean.js","webpack://universal-serialize/./src/serializers/date.js","webpack://universal-serialize/./src/serializers/error.js","webpack://universal-serialize/./src/serializers/function.js","webpack://universal-serialize/./src/serializers/number.js","webpack://universal-serialize/./src/serializers/object.js","webpack://universal-serialize/./src/serializers/promise.js","webpack://universal-serialize/./src/serializers/regex.js","webpack://universal-serialize/./src/serializers/string.js","webpack://universal-serialize/./src/serializers/null.js","webpack://universal-serialize/./src/serialize.js","webpack://universal-serialize/./src/deserialize.js","webpack://universal-serialize/./src/index.js","webpack://universal-serialize/./src/types.js"],"names":["root","factory","exports","module","define","amd","self","this","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","TYPE","FUNCTION","ERROR","PROMISE","REGEX","DATE","ARRAY","OBJECT","STRING","NUMBER","BOOLEAN","NULL","UNDEFINED","isSerializedType","item","__type__","determineType","val","Array","isArray","Error","then","toString","serializeType","type","__val__","serializeArray","deserializeArray","serializeBoolean","deserializeBoolean","serializeDate","toJSON","deserializeDate","Date","serializeError","_ref","message","stack","code","deserializeError","_ref2","error","serializeFunction","deserializeFunction","serializeNumber","deserializeNumber","serializeObject","deserializeObject","serializePromise","deserializePromise","serializeRegex","source","deserializeRegex","RegExp","serializeString","deserializeString","serializeNull","deserializeNull","SERIALIZER","_SERIALIZER","defaultSerializers","serialize","obj","serializers","result","JSON","stringify","serializer","DESERIALIZER","_DESERIALIZER","defaultDeserializers","deserialize","str","deserializers","parse","deserializer","__webpack_exports__"],"mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,IACA,mBAAAG,eAAAC,IACAD,OAAA,yBAAAH,GACA,iBAAAC,QACAA,QAAA,uBAAAD,IAEAD,EAAA,uBAAAC,IARA,CASC,oBAAAK,UAAAC,KAAA,WACD,mBCTA,IAAAC,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAR,QAGA,IAAAC,EAAAK,EAAAE,GAAA,CACAC,EAAAD,EACAE,GAAA,EACAV,QAAA,IAUA,OANAW,EAAAH,GAAAI,KAAAX,EAAAD,QAAAC,IAAAD,QAAAO,GAGAN,EAAAS,GAAA,EAGAT,EAAAD,QA0DA,OArDAO,EAAAM,EAAAF,EAGAJ,EAAAO,EAAAR,EAGAC,EAAAQ,EAAA,SAAAf,EAAAgB,EAAAC,GACAV,EAAAW,EAAAlB,EAAAgB,IACAG,OAAAC,eAAApB,EAAAgB,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CV,EAAAgB,EAAA,SAAAvB,GACA,oBAAAwB,eAAAC,aACAN,OAAAC,eAAApB,EAAAwB,OAAAC,YAAA,CAAwDC,MAAA,WAExDP,OAAAC,eAAApB,EAAA,cAAiD0B,OAAA,KAQjDnB,EAAAoB,EAAA,SAAAD,EAAAE,GAEA,GADA,EAAAA,IAAAF,EAAAnB,EAAAmB,IACA,EAAAE,EAAA,OAAAF,EACA,KAAAE,GAAA,iBAAA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AAAtF,EAAAQ,EAAAsG,EAAA,oCAAAtB,IAAAxF,EAAAQ,EAAAsG,EAAA,sCAAArB,IAAAzF,EAAAQ,EAAAsG,EAAA,kCAAApB,IAAA1F,EAAAQ,EAAAsG,EAAA,oCAAAnB,IAAA3F,EAAAQ,EAAAsG,EAAA,yBAAA5E,IAAAlC,EAAAQ,EAAAsG,EAAA,qCAAA/D,IAAA/C,EAAAQ,EAAAsG,EAAA,kCAAA5D,IAAAlD,EAAAQ,EAAAsG,EAAA,kCAAArD,IAAAzD,EAAAQ,EAAAsG,EAAA,0BCGqB","file":"universalSerialize.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"universal-serialize\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"universal-serialize\"] = factory();\n\telse\n\t\troot[\"universal-serialize\"] = factory();\n})((typeof self !== 'undefined' ? self : this), function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","/* @flow */\n\nexport const TYPE = {\n FUNCTION: ('function' : 'function'),\n ERROR: ('error' : 'error'),\n PROMISE: ('promise' : 'promise'),\n REGEX: ('regex' : 'regex'),\n DATE: ('date' : 'date'),\n ARRAY: ('array' : 'array'),\n OBJECT: ('object' : 'object'),\n STRING: ('string' : 'string'),\n NUMBER: ('number' : 'number'),\n BOOLEAN: ('boolean' : 'boolean'),\n NULL: ('null' : 'null'),\n UNDEFINED: ('undefined' : 'undefined')\n};\n","/* @flow */\n\nimport { TYPE } from './constants';\nimport type { CustomSerializedType } from './types';\n\nexport function isSerializedType(item : mixed) : boolean {\n return (typeof item === 'object' && item !== null && typeof item.__type__ === 'string');\n}\n\nexport function determineType(val : mixed) : $Values | void {\n if (typeof val === 'undefined') {\n return TYPE.UNDEFINED;\n }\n\n if (val === null) {\n return TYPE.NULL;\n }\n\n if (Array.isArray(val)) {\n return TYPE.ARRAY;\n }\n\n if (typeof val === 'function') {\n return TYPE.FUNCTION;\n }\n\n if (typeof val === 'object') {\n\n if (val instanceof Error) {\n return TYPE.ERROR;\n }\n\n if (typeof val.then === 'function') {\n return TYPE.PROMISE;\n }\n\n if (Object.prototype.toString.call(val) === '[object RegExp]') {\n return TYPE.REGEX;\n }\n\n if (Object.prototype.toString.call(val) === '[object Date]') {\n return TYPE.DATE;\n }\n\n return TYPE.OBJECT;\n }\n\n if (typeof val === 'string') {\n return TYPE.STRING;\n }\n\n if (typeof val === 'number') {\n return TYPE.NUMBER;\n }\n\n if (typeof val === 'boolean') {\n return TYPE.BOOLEAN;\n }\n}\n\nexport function serializeType(type : T, val : V) : CustomSerializedType {\n return {\n __type__: type,\n __val__: val\n };\n}\n","/* @flow */\n\nexport type SerializedArray = $ReadOnlyArray;\n\nexport function serializeArray(val : $ReadOnlyArray) : SerializedArray {\n return val;\n}\n\nexport function deserializeArray(val : SerializedArray) : $ReadOnlyArray {\n return val;\n}\n","/* @flow */\n\nexport type SerializedBoolean = boolean;\n\nexport function serializeBoolean(val : boolean) : SerializedBoolean {\n return val;\n}\n\nexport function deserializeBoolean(val : SerializedBoolean) : boolean {\n return val;\n}\n","/* @flow */\n\nimport { serializeType } from '../common';\nimport { TYPE } from '../constants';\nimport type { NativeSerializedType } from '../types';\n\nexport type SerializedDate = string;\n\nexport function serializeDate(val : Date) : NativeSerializedType {\n return serializeType(TYPE.DATE, val.toJSON());\n}\n\nexport function deserializeDate(val : string) : Date {\n return new Date(val);\n}\n","/* @flow */\n\nimport { serializeType } from '../common';\nimport { TYPE } from '../constants';\nimport type { NativeSerializedType } from '../types';\n\nexport type SerializedError = {|\n message : string,\n stack : string,\n code : string | number | void\n|};\n\n// $FlowFixMe\nexport function serializeError({ message, stack, code } : Error) : NativeSerializedType {\n return serializeType(TYPE.ERROR, { message, stack, code });\n}\n\nexport function deserializeError({ message, stack, code } : SerializedError) : Error {\n const error = new Error(message);\n // $FlowFixMe\n error.code = code;\n error.stack = `${ stack }\\n\\n${ error.stack }`;\n return error;\n}\n","/* @flow */\n\nexport type SerializedFunction = void;\n\nexport function serializeFunction() : SerializedFunction {\n // pass\n}\n\nexport function deserializeFunction() {\n throw new Error(`Function serialization is not implemented; nothing to deserialize`);\n}\n","/* @flow */\n\nexport type SerializedNumber = number;\n\nexport function serializeNumber(val : number) : SerializedNumber {\n return val;\n}\n\nexport function deserializeNumber(val : SerializedNumber) : number {\n return val;\n}\n","/* @flow */\n\nexport type SerializedObject = Object;\n\nexport function serializeObject(val : Object) : SerializedObject {\n return val;\n}\n\nexport function deserializeObject(val : SerializedObject) : Object {\n return val;\n}\n","/* @flow */\n\nexport type SerializedPromise = void;\n\nexport function serializePromise() : SerializedPromise {\n // pass\n}\n\nexport function deserializePromise() {\n throw new Error(`Promise serialization is not implemented; nothing to deserialize`);\n}\n","/* @flow */\n\nimport { serializeType } from '../common';\nimport { TYPE } from '../constants';\nimport type { NativeSerializedType } from '../types';\n\nexport type SerializedRegex = string;\n\nexport function serializeRegex(val : RegExp) : NativeSerializedType {\n return serializeType(TYPE.REGEX, val.source);\n}\n\nexport function deserializeRegex(val : string) : RegExp {\n // eslint-disable-next-line security/detect-non-literal-regexp\n return new RegExp(val);\n}\n","/* @flow */\n\nexport type SerializedString = string;\n\nexport function serializeString(val : string) : SerializedString {\n return val;\n}\n\nexport function deserializeString(val : SerializedString) : string {\n return val;\n}\n","/* @flow */\n\nexport type SerializedNull = null;\n\nexport function serializeNull(val : null) : SerializedNull {\n return val;\n}\n\nexport function deserializeNull(val : SerializedNull) : null {\n return val;\n}\n","/* @flow */\n\nimport { TYPE } from './constants';\nimport type { Thenable, CustomSerializedType, NativeSerializedType } from './types';\nimport { determineType, isSerializedType } from './common';\nimport {\n serializeFunction,\n serializeError, type SerializedError,\n serializePromise,\n serializeRegex, type SerializedRegex,\n serializeDate, type SerializedDate,\n serializeArray,\n serializeObject,\n serializeString,\n serializeNumber,\n serializeBoolean,\n serializeNull\n} from './serializers';\n\ntype NativeSerializer> = (value : V, key : string) => NativeSerializedType;\ntype CustomSerializer = (value : V, key : string) => CustomSerializedType;\ntype PrimitiveSerializer = (value : V, key : string) => S;\ntype CustomOrPrimitiveSerializer = CustomSerializer | PrimitiveSerializer;\ntype NativeOrCustomOrPrimitiveSerializer = NativeSerializer | CustomOrPrimitiveSerializer;\n\ntype Serializers = {|\n function? : CustomOrPrimitiveSerializer,\n error? : NativeOrCustomOrPrimitiveSerializer,\n promise? : CustomOrPrimitiveSerializer,\n regex? : NativeOrCustomOrPrimitiveSerializer,\n date? : NativeOrCustomOrPrimitiveSerializer,\n array? : CustomOrPrimitiveSerializer<$ReadOnlyArray, typeof TYPE.ARRAY>,\n object? : CustomOrPrimitiveSerializer,\n string? : CustomOrPrimitiveSerializer,\n number? : CustomOrPrimitiveSerializer,\n boolean? : CustomOrPrimitiveSerializer,\n null? : CustomOrPrimitiveSerializer\n|};\n\nconst SERIALIZER : Serializers = {\n [ TYPE.FUNCTION ]: serializeFunction,\n [ TYPE.ERROR ]: serializeError,\n [ TYPE.PROMISE ]: serializePromise,\n [ TYPE.REGEX ]: serializeRegex,\n [ TYPE.DATE ]: serializeDate,\n [ TYPE.ARRAY ]: serializeArray,\n [ TYPE.OBJECT ]: serializeObject,\n [ TYPE.STRING ]: serializeString,\n [ TYPE.NUMBER ]: serializeNumber,\n [ TYPE.BOOLEAN ]: serializeBoolean,\n [ TYPE.NULL ]: serializeNull\n};\n\n// $FlowFixMe\nconst defaultSerializers : Serializers = {};\n\nexport function serialize(obj : T, serializers : Serializers = defaultSerializers) : string {\n\n function replacer(key) : ?mixed {\n const val = this[key];\n\n if (isSerializedType(this)) {\n return val;\n }\n \n const type = determineType(val);\n\n if (!type) {\n return val;\n }\n\n // $FlowFixMe\n const serializer = serializers[type] || SERIALIZER[type];\n\n if (!serializer) {\n return val;\n }\n\n return serializer(val, key);\n }\n\n const result = JSON.stringify(obj, replacer);\n\n if (typeof result === 'undefined') {\n return TYPE.UNDEFINED;\n }\n\n return result;\n}\n","/* @flow */\n\nimport type { Thenable } from './types';\nimport { TYPE } from './constants';\nimport { determineType, isSerializedType } from './common';\nimport {\n deserializeFunction,\n deserializeError, type SerializedError,\n deserializePromise,\n deserializeRegex, type SerializedRegex,\n deserializeDate, type SerializedDate,\n deserializeArray,\n deserializeObject,\n deserializeString,\n deserializeNumber,\n deserializeBoolean,\n deserializeNull\n} from './serializers';\n\ntype Deserializer = (serializedValue : S, key : string) => V;\ntype PrimitiveDeserializer = (serializedValue : S, key : string) => V;\n\ntype Deserializers = {\n function? : Deserializer,\n error? : Deserializer,\n promise? : Deserializer,\n regex? : Deserializer,\n date? : Deserializer,\n array? : PrimitiveDeserializer<$ReadOnlyArray>,\n object? : PrimitiveDeserializer,\n string? : PrimitiveDeserializer,\n number? : PrimitiveDeserializer,\n boolean? : PrimitiveDeserializer,\n null? : PrimitiveDeserializer,\n [string] : Deserializer\n};\n\n// $FlowFixMe\nconst DESERIALIZER : Deserializers = {\n [ TYPE.FUNCTION ]: deserializeFunction,\n [ TYPE.ERROR ]: deserializeError,\n [ TYPE.PROMISE ]: deserializePromise,\n [ TYPE.REGEX ]: deserializeRegex,\n [ TYPE.DATE ]: deserializeDate,\n [ TYPE.ARRAY ]: deserializeArray,\n [ TYPE.OBJECT ]: deserializeObject,\n [ TYPE.STRING ]: deserializeString,\n [ TYPE.NUMBER ]: deserializeNumber,\n [ TYPE.BOOLEAN ]: deserializeBoolean,\n [ TYPE.NULL ]: deserializeNull\n};\n\n// $FlowFixMe\nconst defaultDeserializers : Deserializers = {};\n\nexport function deserialize(str : string, deserializers : Deserializers = defaultDeserializers) : T {\n if (str === TYPE.UNDEFINED) {\n // $FlowFixMe\n return;\n }\n\n function replacer(key, val) : ?mixed {\n if (isSerializedType(this)) {\n return val;\n }\n\n let type;\n let value;\n\n if (isSerializedType(val)) {\n type = val.__type__;\n value = val.__val__;\n } else {\n type = determineType(val);\n value = val;\n }\n\n if (!type) {\n return value;\n }\n\n // $FlowFixMe\n const deserializer = deserializers[type] || DESERIALIZER[type];\n\n if (!deserializer) {\n return value;\n }\n\n return deserializer(value, key);\n }\n\n return JSON.parse(str, replacer);\n}\n","/* @flow */\n\nexport * from './serialize';\nexport * from './deserialize';\nexport * from './serializers';\nexport * from './constants';\nexport * from './common';\nexport * from './types';\n","/* @flow */\n\nimport { TYPE } from './constants';\n\n// export something to force webpack to see this as an ES module\nexport const TYPES = true;\n\n// eslint-disable-next-line flowtype/require-exact-type\nexport type Thenable = {\n then : (onSuccess? : (val? : mixed) => mixed, onError? : (err? : mixed) => mixed) => Thenable,\n catch : (onError? : (err? : mixed) => mixed) => Thenable\n};\n\n// eslint-disable-next-line flowtype/require-exact-type\nexport type NativeSerializedType, V : mixed> = {\n __type__ : T,\n __val__ : V\n};\n\nexport type CustomSerializedType = {|\n __type__ : T,\n __val__ : V\n|};\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://universal-serialize/webpack/universalModuleDefinition","webpack://universal-serialize/webpack/bootstrap","webpack://universal-serialize/./src/constants.js","webpack://universal-serialize/./src/common.js","webpack://universal-serialize/./src/serializers/function.js","webpack://universal-serialize/./src/serializers/error.js","webpack://universal-serialize/./src/serializers/promise.js","webpack://universal-serialize/./src/serializers/regex.js","webpack://universal-serialize/./src/serializers/date.js","webpack://universal-serialize/./src/serializers/array.js","webpack://universal-serialize/./src/serializers/object.js","webpack://universal-serialize/./src/serializers/string.js","webpack://universal-serialize/./src/serializers/number.js","webpack://universal-serialize/./src/serializers/boolean.js","webpack://universal-serialize/./src/serializers/null.js","webpack://universal-serialize/./src/serialize.js","webpack://universal-serialize/./src/deserialize.js","webpack://universal-serialize/./src/types.js"],"names":["root","factory","exports","module","define","amd","self","this","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","hasOwnProperty","p","s","TYPE","FUNCTION","ERROR","PROMISE","REGEX","DATE","ARRAY","OBJECT","STRING","NUMBER","BOOLEAN","NULL","UNDEFINED","isSerializedType","item","__type__","determineType","val","Array","isArray","Error","then","toString","serializeType","type","__val__","serializeFunction","deserializeFunction","serializeError","message","stack","code","deserializeError","error","serializePromise","deserializePromise","serializeRegex","source","deserializeRegex","RegExp","serializeDate","toJSON","deserializeDate","Date","serializeArray","deserializeArray","serializeObject","deserializeObject","serializeString","deserializeString","serializeNumber","deserializeNumber","serializeBoolean","deserializeBoolean","serializeNull","deserializeNull","SERIALIZER","defaultSerializers","serialize","obj","serializers","result","JSON","stringify","serializer","DESERIALIZER","defaultDeserializers","deserialize","str","deserializers","parse","deserializer","TYPES"],"mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,sBAAuB,GAAIH,GACR,iBAAZC,QACdA,QAAQ,uBAAyBD,IAEjCD,EAAK,uBAAyBC,IARhC,CASoB,oBAATK,KAAuBA,KAAOC,MAAO,WAChD,O,YCTE,IAAIC,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUR,QAGnC,IAAIC,EAASK,EAAiBE,GAAY,CACzCC,EAAGD,EACHE,GAAG,EACHV,QAAS,IAUV,OANAW,EAAQH,GAAUI,KAAKX,EAAOD,QAASC,EAAQA,EAA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ASgC,EAAWhC,GAEnD,OAAKwC,EAIEA,EAAW/C,EAAKzB,GAHZyB,KAQf,YAAsB,IAAX4C,EACA7D,EAAKY,UAGTiD,ECjDX,IAAMI,IAA4B,MAC5BjE,EAAKC,UAAa0B,EADU,EAE5B3B,EAAKE,OAAa8B,EAFU,EAG5BhC,EAAKG,SAAagC,EAHU,EAI5BnC,EAAKI,OAAakC,EAJU,EAK5BtC,EAAKK,MAAaqC,EALU,EAM5B1C,EAAKM,OAAauC,EANU,EAO5B7C,EAAKO,QAAawC,EAPU,EAQ5B/C,EAAKQ,QAAayC,EARU,EAS5BjD,EAAKS,QAAa0C,EATU,EAU5BnD,EAAKU,SAAa2C,EAVU,EAW5BrD,EAAKW,MAAa4C,EAXU,GAe5BW,EAAuC,GAEtC,SAASC,EAAqCC,EAAcC,GAC/D,QADyH,IAA1DA,MAAgCH,GAC3FE,IAAQpE,EAAKY,UAmCjB,OAAOkD,KAAKQ,MAAMF,GA9BlB,SAAkB5E,EAAKyB,GACnB,GAAIJ,EAAiBhD,MACjB,OAAOoD,EAGX,IAAIO,EACAtC,EAUJ,GARI2B,EAAiBI,IACjBO,EAAOP,EAAIF,SACX7B,EAAQ+B,EAAIQ,UAEZD,EAAOR,EAAcC,GACrB/B,EAAQ+B,IAGPO,EACD,OAAOtC,EAIX,IAAMqF,EAAeF,EAAc7C,IAASyC,EAAazC,GAEzD,OAAK+C,EAIEA,EAAarF,EAAOM,GAHhBN,KChFZ,IAAMsF,GAAQ","file":"universalSerialize.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"universal-serialize\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"universal-serialize\"] = factory();\n\telse\n\t\troot[\"universal-serialize\"] = factory();\n})((typeof self !== 'undefined' ? self : this), function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","/* @flow */\n\nexport const TYPE = {\n FUNCTION: ('function' : 'function'),\n ERROR: ('error' : 'error'),\n PROMISE: ('promise' : 'promise'),\n REGEX: ('regex' : 'regex'),\n DATE: ('date' : 'date'),\n ARRAY: ('array' : 'array'),\n OBJECT: ('object' : 'object'),\n STRING: ('string' : 'string'),\n NUMBER: ('number' : 'number'),\n BOOLEAN: ('boolean' : 'boolean'),\n NULL: ('null' : 'null'),\n UNDEFINED: ('undefined' : 'undefined')\n};\n","/* @flow */\n\nimport { TYPE } from './constants';\nimport type { CustomSerializedType } from './types';\n\nexport function isSerializedType(item : mixed) : boolean {\n return (typeof item === 'object' && item !== null && typeof item.__type__ === 'string');\n}\n\nexport function determineType(val : mixed) : $Values | void {\n if (typeof val === 'undefined') {\n return TYPE.UNDEFINED;\n }\n\n if (val === null) {\n return TYPE.NULL;\n }\n\n if (Array.isArray(val)) {\n return TYPE.ARRAY;\n }\n\n if (typeof val === 'function') {\n return TYPE.FUNCTION;\n }\n\n if (typeof val === 'object') {\n\n if (val instanceof Error) {\n return TYPE.ERROR;\n }\n\n if (typeof val.then === 'function') {\n return TYPE.PROMISE;\n }\n\n if (Object.prototype.toString.call(val) === '[object RegExp]') {\n return TYPE.REGEX;\n }\n\n if (Object.prototype.toString.call(val) === '[object Date]') {\n return TYPE.DATE;\n }\n\n return TYPE.OBJECT;\n }\n\n if (typeof val === 'string') {\n return TYPE.STRING;\n }\n\n if (typeof val === 'number') {\n return TYPE.NUMBER;\n }\n\n if (typeof val === 'boolean') {\n return TYPE.BOOLEAN;\n }\n}\n\nexport function serializeType(type : T, val : V) : CustomSerializedType {\n return {\n __type__: type,\n __val__: val\n };\n}\n","/* @flow */\n\nexport type SerializedFunction = void;\n\nexport function serializeFunction() : SerializedFunction {\n // pass\n}\n\nexport function deserializeFunction() {\n throw new Error(`Function serialization is not implemented; nothing to deserialize`);\n}\n","/* @flow */\n\nimport { serializeType } from '../common';\nimport { TYPE } from '../constants';\nimport type { NativeSerializedType } from '../types';\n\nexport type SerializedError = {|\n message : string,\n stack : string,\n code : string | number | void\n|};\n\n// $FlowFixMe\nexport function serializeError({ message, stack, code } : Error) : NativeSerializedType {\n return serializeType(TYPE.ERROR, { message, stack, code });\n}\n\nexport function deserializeError({ message, stack, code } : SerializedError) : Error {\n const error = new Error(message);\n // $FlowFixMe\n error.code = code;\n error.stack = `${ stack }\\n\\n${ error.stack }`;\n return error;\n}\n","/* @flow */\n\nexport type SerializedPromise = void;\n\nexport function serializePromise() : SerializedPromise {\n // pass\n}\n\nexport function deserializePromise() {\n throw new Error(`Promise serialization is not implemented; nothing to deserialize`);\n}\n","/* @flow */\n\nimport { serializeType } from '../common';\nimport { TYPE } from '../constants';\nimport type { NativeSerializedType } from '../types';\n\nexport type SerializedRegex = string;\n\nexport function serializeRegex(val : RegExp) : NativeSerializedType {\n return serializeType(TYPE.REGEX, val.source);\n}\n\nexport function deserializeRegex(val : string) : RegExp {\n // eslint-disable-next-line security/detect-non-literal-regexp\n return new RegExp(val);\n}\n","/* @flow */\n\nimport { serializeType } from '../common';\nimport { TYPE } from '../constants';\nimport type { NativeSerializedType } from '../types';\n\nexport type SerializedDate = string;\n\nexport function serializeDate(val : Date) : NativeSerializedType {\n return serializeType(TYPE.DATE, val.toJSON());\n}\n\nexport function deserializeDate(val : string) : Date {\n return new Date(val);\n}\n","/* @flow */\n\nexport type SerializedArray = $ReadOnlyArray;\n\nexport function serializeArray(val : $ReadOnlyArray) : SerializedArray {\n return val;\n}\n\nexport function deserializeArray(val : SerializedArray) : $ReadOnlyArray {\n return val;\n}\n","/* @flow */\n\nexport type SerializedObject = Object;\n\nexport function serializeObject(val : Object) : SerializedObject {\n return val;\n}\n\nexport function deserializeObject(val : SerializedObject) : Object {\n return val;\n}\n","/* @flow */\n\nexport type SerializedString = string;\n\nexport function serializeString(val : string) : SerializedString {\n return val;\n}\n\nexport function deserializeString(val : SerializedString) : string {\n return val;\n}\n","/* @flow */\n\nexport type SerializedNumber = number;\n\nexport function serializeNumber(val : number) : SerializedNumber {\n return val;\n}\n\nexport function deserializeNumber(val : SerializedNumber) : number {\n return val;\n}\n","/* @flow */\n\nexport type SerializedBoolean = boolean;\n\nexport function serializeBoolean(val : boolean) : SerializedBoolean {\n return val;\n}\n\nexport function deserializeBoolean(val : SerializedBoolean) : boolean {\n return val;\n}\n","/* @flow */\n\nexport type SerializedNull = null;\n\nexport function serializeNull(val : null) : SerializedNull {\n return val;\n}\n\nexport function deserializeNull(val : SerializedNull) : null {\n return val;\n}\n","/* @flow */\n\nimport { TYPE } from './constants';\nimport type { Thenable, CustomSerializedType, NativeSerializedType } from './types';\nimport { determineType, isSerializedType } from './common';\nimport {\n serializeFunction,\n serializeError, type SerializedError,\n serializePromise,\n serializeRegex, type SerializedRegex,\n serializeDate, type SerializedDate,\n serializeArray,\n serializeObject,\n serializeString,\n serializeNumber,\n serializeBoolean,\n serializeNull\n} from './serializers';\n\ntype NativeSerializer> = (value : V, key : string) => NativeSerializedType;\ntype CustomSerializer = (value : V, key : string) => CustomSerializedType;\ntype PrimitiveSerializer = (value : V, key : string) => S;\ntype CustomOrPrimitiveSerializer = CustomSerializer | PrimitiveSerializer;\ntype NativeOrCustomOrPrimitiveSerializer = NativeSerializer | CustomOrPrimitiveSerializer;\n\ntype Serializers = {|\n function? : CustomOrPrimitiveSerializer,\n error? : NativeOrCustomOrPrimitiveSerializer,\n promise? : CustomOrPrimitiveSerializer,\n regex? : NativeOrCustomOrPrimitiveSerializer,\n date? : NativeOrCustomOrPrimitiveSerializer,\n array? : CustomOrPrimitiveSerializer<$ReadOnlyArray, typeof TYPE.ARRAY>,\n object? : CustomOrPrimitiveSerializer,\n string? : CustomOrPrimitiveSerializer,\n number? : CustomOrPrimitiveSerializer,\n boolean? : CustomOrPrimitiveSerializer,\n null? : CustomOrPrimitiveSerializer\n|};\n\nconst SERIALIZER : Serializers = {\n [ TYPE.FUNCTION ]: serializeFunction,\n [ TYPE.ERROR ]: serializeError,\n [ TYPE.PROMISE ]: serializePromise,\n [ TYPE.REGEX ]: serializeRegex,\n [ TYPE.DATE ]: serializeDate,\n [ TYPE.ARRAY ]: serializeArray,\n [ TYPE.OBJECT ]: serializeObject,\n [ TYPE.STRING ]: serializeString,\n [ TYPE.NUMBER ]: serializeNumber,\n [ TYPE.BOOLEAN ]: serializeBoolean,\n [ TYPE.NULL ]: serializeNull\n};\n\n// $FlowFixMe\nconst defaultSerializers : Serializers = {};\n\nexport function serialize(obj : T, serializers : Serializers = defaultSerializers) : string {\n\n function replacer(key) : ?mixed {\n const val = this[key];\n\n if (isSerializedType(this)) {\n return val;\n }\n \n const type = determineType(val);\n\n if (!type) {\n return val;\n }\n\n // $FlowFixMe\n const serializer = serializers[type] || SERIALIZER[type];\n\n if (!serializer) {\n return val;\n }\n\n return serializer(val, key);\n }\n\n const result = JSON.stringify(obj, replacer);\n\n if (typeof result === 'undefined') {\n return TYPE.UNDEFINED;\n }\n\n return result;\n}\n","/* @flow */\n\nimport type { Thenable } from './types';\nimport { TYPE } from './constants';\nimport { determineType, isSerializedType } from './common';\nimport {\n deserializeFunction,\n deserializeError, type SerializedError,\n deserializePromise,\n deserializeRegex, type SerializedRegex,\n deserializeDate, type SerializedDate,\n deserializeArray,\n deserializeObject,\n deserializeString,\n deserializeNumber,\n deserializeBoolean,\n deserializeNull\n} from './serializers';\n\ntype Deserializer = (serializedValue : S, key : string) => V;\ntype PrimitiveDeserializer = (serializedValue : S, key : string) => V;\n\ntype Deserializers = {\n function? : Deserializer,\n error? : Deserializer,\n promise? : Deserializer,\n regex? : Deserializer,\n date? : Deserializer,\n array? : PrimitiveDeserializer<$ReadOnlyArray>,\n object? : PrimitiveDeserializer,\n string? : PrimitiveDeserializer,\n number? : PrimitiveDeserializer,\n boolean? : PrimitiveDeserializer,\n null? : PrimitiveDeserializer,\n [string] : Deserializer\n};\n\n// $FlowFixMe\nconst DESERIALIZER : Deserializers = {\n [ TYPE.FUNCTION ]: deserializeFunction,\n [ TYPE.ERROR ]: deserializeError,\n [ TYPE.PROMISE ]: deserializePromise,\n [ TYPE.REGEX ]: deserializeRegex,\n [ TYPE.DATE ]: deserializeDate,\n [ TYPE.ARRAY ]: deserializeArray,\n [ TYPE.OBJECT ]: deserializeObject,\n [ TYPE.STRING ]: deserializeString,\n [ TYPE.NUMBER ]: deserializeNumber,\n [ TYPE.BOOLEAN ]: deserializeBoolean,\n [ TYPE.NULL ]: deserializeNull\n};\n\n// $FlowFixMe\nconst defaultDeserializers : Deserializers = {};\n\nexport function deserialize(str : string, deserializers : Deserializers = defaultDeserializers) : T {\n if (str === TYPE.UNDEFINED) {\n // $FlowFixMe\n return;\n }\n\n function replacer(key, val) : ?mixed {\n if (isSerializedType(this)) {\n return val;\n }\n\n let type;\n let value;\n\n if (isSerializedType(val)) {\n type = val.__type__;\n value = val.__val__;\n } else {\n type = determineType(val);\n value = val;\n }\n\n if (!type) {\n return value;\n }\n\n // $FlowFixMe\n const deserializer = deserializers[type] || DESERIALIZER[type];\n\n if (!deserializer) {\n return value;\n }\n\n return deserializer(value, key);\n }\n\n return JSON.parse(str, replacer);\n}\n","/* @flow */\n\nimport { TYPE } from './constants';\n\n// export something to force webpack to see this as an ES module\nexport const TYPES = true;\n\n// eslint-disable-next-line flowtype/require-exact-type\nexport type Thenable = {\n then : (onSuccess? : (val? : mixed) => mixed, onError? : (err? : mixed) => mixed) => Thenable,\n catch : (onError? : (err? : mixed) => mixed) => Thenable\n};\n\n// eslint-disable-next-line flowtype/require-exact-type\nexport type NativeSerializedType, V : mixed> = {\n __type__ : T,\n __val__ : V\n};\n\nexport type CustomSerializedType = {|\n __type__ : T,\n __val__ : V\n|};\n"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/universalSerialize.min.js b/dist/universalSerialize.min.js index bd65656..e79c07f 100644 --- a/dist/universalSerialize.min.js +++ b/dist/universalSerialize.min.js @@ -1,2 +1,2 @@ -!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define("universal-serialize",[],n):"object"==typeof exports?exports["universal-serialize"]=n():e["universal-serialize"]=n()}("undefined"!=typeof self?self:this,function(){return function(e){var n={};function r(t){if(n[t])return n[t].exports;var i=n[t]={i:t,l:!1,exports:{}};return e[t].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=n,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,n){if(1&n&&(e=r(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var i in e)r.d(t,i,function(n){return e[n]}.bind(null,i));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="",r(r.s=0)}([function(e,n,r){"use strict";r.r(n);var t,i={FUNCTION:"function",ERROR:"error",PROMISE:"promise",REGEX:"regex",DATE:"date",ARRAY:"array",OBJECT:"object",STRING:"string",NUMBER:"number",BOOLEAN:"boolean",NULL:"null",UNDEFINED:"undefined"};function o(e){return"object"==typeof e&&null!==e&&"string"==typeof e.__type__}function u(e){return void 0===e?i.UNDEFINED:null===e?i.NULL:Array.isArray(e)?i.ARRAY:"function"==typeof e?i.FUNCTION:"object"==typeof e?e instanceof Error?i.ERROR:"function"==typeof e.then?i.PROMISE:"[object RegExp]"===Object.prototype.toString.call(e)?i.REGEX:"[object Date]"===Object.prototype.toString.call(e)?i.DATE:i.OBJECT:"string"==typeof e?i.STRING:"number"==typeof e?i.NUMBER:"boolean"==typeof e?i.BOOLEAN:void 0}function f(e,n){return{__type__:e,__val__:n}}function c(e){return e}function a(e){return e}function l(e){return e}function s(e){return e}function d(e){return f(i.DATE,e.toJSON())}function E(e){return new Date(e)}function p(e){var n=e.message,r=e.stack,t=e.code;return f(i.ERROR,{message:n,stack:r,code:t})}function R(e){var n=e.message,r=e.stack,t=e.code,i=new Error(n);return i.code=t,i.stack=r+"\n\n"+i.stack,i}function y(){}function N(){throw new Error("Function serialization is not implemented; nothing to deserialize")}function O(e){return e}function z(e){return e}function b(e){return e}function v(e){return e}function _(){}function m(){throw new Error("Promise serialization is not implemented; nothing to deserialize")}function g(e){return f(i.REGEX,e.source)}function T(e){return new RegExp(e)}function S(e){return e}function A(e){return e}function j(e){return e}function D(e){return e}var I,U=((t={})[i.FUNCTION]=y,t[i.ERROR]=p,t[i.PROMISE]=_,t[i.REGEX]=g,t[i.DATE]=d,t[i.ARRAY]=c,t[i.OBJECT]=b,t[i.STRING]=S,t[i.NUMBER]=O,t[i.BOOLEAN]=l,t[i.NULL]=j,t),x={};function B(e,n){void 0===n&&(n=x);var r=JSON.stringify(e,function(e){var r=this[e];if(o(this))return r;var t=u(r);if(!t)return r;var i=n[t]||U[t];return i?i(r,e):r});return void 0===r?i.UNDEFINED:r}var P=((I={})[i.FUNCTION]=N,I[i.ERROR]=R,I[i.PROMISE]=m,I[i.REGEX]=T,I[i.DATE]=E,I[i.ARRAY]=a,I[i.OBJECT]=v,I[i.STRING]=A,I[i.NUMBER]=z,I[i.BOOLEAN]=s,I[i.NULL]=D,I),L={};function M(e,n){if(void 0===n&&(n=L),e!==i.UNDEFINED)return JSON.parse(e,function(e,r){if(o(this))return r;var t,i;if(o(r)?(t=r.__type__,i=r.__val__):(t=u(r),i=r),!t)return i;var f=n[t]||P[t];return f?f(i,e):i})}r.d(n,"serialize",function(){return B}),r.d(n,"deserialize",function(){return M}),r.d(n,"serializeArray",function(){return c}),r.d(n,"deserializeArray",function(){return a}),r.d(n,"serializeBoolean",function(){return l}),r.d(n,"deserializeBoolean",function(){return s}),r.d(n,"serializeDate",function(){return d}),r.d(n,"deserializeDate",function(){return E}),r.d(n,"serializeError",function(){return p}),r.d(n,"deserializeError",function(){return R}),r.d(n,"serializeFunction",function(){return y}),r.d(n,"deserializeFunction",function(){return N}),r.d(n,"serializeNumber",function(){return O}),r.d(n,"deserializeNumber",function(){return z}),r.d(n,"serializeObject",function(){return b}),r.d(n,"deserializeObject",function(){return v}),r.d(n,"serializePromise",function(){return _}),r.d(n,"deserializePromise",function(){return m}),r.d(n,"serializeRegex",function(){return g}),r.d(n,"deserializeRegex",function(){return T}),r.d(n,"serializeString",function(){return S}),r.d(n,"deserializeString",function(){return A}),r.d(n,"serializeNull",function(){return j}),r.d(n,"deserializeNull",function(){return D}),r.d(n,"TYPE",function(){return i}),r.d(n,"isSerializedType",function(){return o}),r.d(n,"determineType",function(){return u}),r.d(n,"serializeType",function(){return f}),r.d(n,"TYPES",function(){return!0})}])}); +!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define("universal-serialize",[],n):"object"==typeof exports?exports["universal-serialize"]=n():e["universal-serialize"]=n()}("undefined"!=typeof self?self:this,(function(){return function(e){var n={};function r(t){if(n[t])return n[t].exports;var i=n[t]={i:t,l:!1,exports:{}};return e[t].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=n,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,n){if(1&n&&(e=r(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var i in e)r.d(t,i,function(n){return e[n]}.bind(null,i));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return{}.hasOwnProperty.call(e,n)},r.p="",r(r.s=0)}([function(e,n,r){"use strict";r.r(n),r.d(n,"serialize",(function(){return B})),r.d(n,"deserialize",(function(){return M})),r.d(n,"serializeArray",(function(){return O})),r.d(n,"deserializeArray",(function(){return z})),r.d(n,"serializeBoolean",(function(){return S})),r.d(n,"deserializeBoolean",(function(){return A})),r.d(n,"serializeDate",(function(){return N})),r.d(n,"deserializeDate",(function(){return y})),r.d(n,"serializeError",(function(){return l})),r.d(n,"deserializeError",(function(){return s})),r.d(n,"serializeFunction",(function(){return c})),r.d(n,"deserializeFunction",(function(){return a})),r.d(n,"serializeNumber",(function(){return g})),r.d(n,"deserializeNumber",(function(){return T})),r.d(n,"serializeObject",(function(){return v})),r.d(n,"deserializeObject",(function(){return b})),r.d(n,"serializePromise",(function(){return d})),r.d(n,"deserializePromise",(function(){return E})),r.d(n,"serializeRegex",(function(){return R})),r.d(n,"deserializeRegex",(function(){return p})),r.d(n,"serializeString",(function(){return _})),r.d(n,"deserializeString",(function(){return m})),r.d(n,"serializeNull",(function(){return D})),r.d(n,"deserializeNull",(function(){return j})),r.d(n,"TYPE",(function(){return i})),r.d(n,"isSerializedType",(function(){return u})),r.d(n,"determineType",(function(){return o})),r.d(n,"serializeType",(function(){return f})),r.d(n,"TYPES",(function(){return F}));var t,i={FUNCTION:"function",ERROR:"error",PROMISE:"promise",REGEX:"regex",DATE:"date",ARRAY:"array",OBJECT:"object",STRING:"string",NUMBER:"number",BOOLEAN:"boolean",NULL:"null",UNDEFINED:"undefined"};function u(e){return"object"==typeof e&&null!==e&&"string"==typeof e.__type__}function o(e){return void 0===e?i.UNDEFINED:null===e?i.NULL:Array.isArray(e)?i.ARRAY:"function"==typeof e?i.FUNCTION:"object"==typeof e?e instanceof Error?i.ERROR:"function"==typeof e.then?i.PROMISE:"[object RegExp]"==={}.toString.call(e)?i.REGEX:"[object Date]"==={}.toString.call(e)?i.DATE:i.OBJECT:"string"==typeof e?i.STRING:"number"==typeof e?i.NUMBER:"boolean"==typeof e?i.BOOLEAN:void 0}function f(e,n){return{__type__:e,__val__:n}}function c(){}function a(){throw new Error("Function serialization is not implemented; nothing to deserialize")}function l(e){return f(i.ERROR,{message:e.message,stack:e.stack,code:e.code})}function s(e){var n=e.stack,r=e.code,t=new Error(e.message);return t.code=r,t.stack=n+"\n\n"+t.stack,t}function d(){}function E(){throw new Error("Promise serialization is not implemented; nothing to deserialize")}function R(e){return f(i.REGEX,e.source)}function p(e){return new RegExp(e)}function N(e){return f(i.DATE,e.toJSON())}function y(e){return new Date(e)}function O(e){return e}function z(e){return e}function v(e){return e}function b(e){return e}function _(e){return e}function m(e){return e}function g(e){return e}function T(e){return e}function S(e){return e}function A(e){return e}function D(e){return e}function j(e){return e}var I,U=((t={})[i.FUNCTION]=c,t[i.ERROR]=l,t[i.PROMISE]=d,t[i.REGEX]=R,t[i.DATE]=N,t[i.ARRAY]=O,t[i.OBJECT]=v,t[i.STRING]=_,t[i.NUMBER]=g,t[i.BOOLEAN]=S,t[i.NULL]=D,t),x={};function B(e,n){void 0===n&&(n=x);var r=JSON.stringify(e,(function(e){var r=this[e];if(u(this))return r;var t=o(r);if(!t)return r;var i=n[t]||U[t];return i?i(r,e):r}));return void 0===r?i.UNDEFINED:r}var P=((I={})[i.FUNCTION]=a,I[i.ERROR]=s,I[i.PROMISE]=E,I[i.REGEX]=p,I[i.DATE]=y,I[i.ARRAY]=z,I[i.OBJECT]=b,I[i.STRING]=m,I[i.NUMBER]=T,I[i.BOOLEAN]=A,I[i.NULL]=j,I),L={};function M(e,n){if(void 0===n&&(n=L),e!==i.UNDEFINED)return JSON.parse(e,(function(e,r){if(u(this))return r;var t,i;if(u(r)?(t=r.__type__,i=r.__val__):(t=o(r),i=r),!t)return i;var f=n[t]||P[t];return f?f(i,e):i}))}var F=!0}])})); //# sourceMappingURL=universalSerialize.min.js.map \ No newline at end of file diff --git a/dist/universalSerialize.min.js.map b/dist/universalSerialize.min.js.map index feb29a2..82e9f21 100644 --- a/dist/universalSerialize.min.js.map +++ b/dist/universalSerialize.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://universal-serialize/webpack/universalModuleDefinition","webpack://universal-serialize/webpack/bootstrap","webpack://universal-serialize/./src/constants.js","webpack://universal-serialize/./src/common.js","webpack://universal-serialize/./src/serializers/array.js","webpack://universal-serialize/./src/serializers/boolean.js","webpack://universal-serialize/./src/serializers/date.js","webpack://universal-serialize/./src/serializers/error.js","webpack://universal-serialize/./src/serializers/function.js","webpack://universal-serialize/./src/serializers/number.js","webpack://universal-serialize/./src/serializers/object.js","webpack://universal-serialize/./src/serializers/promise.js","webpack://universal-serialize/./src/serializers/regex.js","webpack://universal-serialize/./src/serializers/string.js","webpack://universal-serialize/./src/serializers/null.js","webpack://universal-serialize/./src/serialize.js","webpack://universal-serialize/./src/deserialize.js","webpack://universal-serialize/./src/index.js","webpack://universal-serialize/./src/types.js"],"names":["root","factory","exports","module","define","amd","self","this","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","TYPE","FUNCTION","ERROR","PROMISE","REGEX","DATE","ARRAY","OBJECT","STRING","NUMBER","BOOLEAN","NULL","UNDEFINED","isSerializedType","item","__type__","determineType","val","Array","isArray","Error","then","toString","serializeType","type","__val__","serializeArray","deserializeArray","serializeBoolean","deserializeBoolean","serializeDate","toJSON","deserializeDate","Date","serializeError","_ref","message","stack","code","deserializeError","_ref2","error","serializeFunction","deserializeFunction","serializeNumber","deserializeNumber","serializeObject","deserializeObject","serializePromise","deserializePromise","serializeRegex","source","deserializeRegex","RegExp","serializeString","deserializeString","serializeNull","deserializeNull","SERIALIZER","_SERIALIZER","defaultSerializers","serialize","obj","serializers","result","JSON","stringify","serializer","DESERIALIZER","_DESERIALIZER","defaultDeserializers","deserialize","str","deserializers","parse","deserializer","__webpack_exports__"],"mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,IACA,mBAAAG,eAAAC,IACAD,OAAA,yBAAAH,GACA,iBAAAC,QACAA,QAAA,uBAAAD,IAEAD,EAAA,uBAAAC,IARA,CASC,oBAAAK,UAAAC,KAAA,WACD,mBCTA,IAAAC,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAR,QAGA,IAAAC,EAAAK,EAAAE,GAAA,CACAC,EAAAD,EACAE,GAAA,EACAV,QAAA,IAUA,OANAW,EAAAH,GAAAI,KAAAX,EAAAD,QAAAC,IAAAD,QAAAO,GAGAN,EAAAS,GAAA,EAGAT,EAAAD,QA0DA,OArDAO,EAAAM,EAAAF,EAGAJ,EAAAO,EAAAR,EAGAC,EAAAQ,EAAA,SAAAf,EAAAgB,EAAAC,GACAV,EAAAW,EAAAlB,EAAAgB,IACAG,OAAAC,eAAApB,EAAAgB,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CV,EAAAgB,EAAA,SAAAvB,GACA,oBAAAwB,eAAAC,aACAN,OAAAC,eAAApB,EAAAwB,OAAAC,YAAA,CAAwDC,MAAA,WAExDP,OAAAC,eAAApB,EAAA,cAAiD0B,OAAA,KAQjDnB,EAAAoB,EAAA,SAAAD,EAAAE,GAEA,GADA,EAAAA,IAAAF,EAAAnB,EAAAmB,IACA,EAAAE,EAAA,OAAAF,EACA,KAAAE,GAAA,iBAAAF,QAAAG,WAAA,OAA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AsG,EAAA,oCAAAtB,IAAAxF,EAAAQ,EAAAsG,EAAA,sCAAArB,IAAAzF,EAAAQ,EAAAsG,EAAA,kCAAApB,IAAA1F,EAAAQ,EAAAsG,EAAA,oCAAAnB,IAAA3F,EAAAQ,EAAAsG,EAAA,yBAAA5E,IAAAlC,EAAAQ,EAAAsG,EAAA,qCAAA/D,IAAA/C,EAAAQ,EAAAsG,EAAA,kCAAA5D,IAAAlD,EAAAQ,EAAAsG,EAAA,kCAAArD,IAAAzD,EAAAQ,EAAAsG,EAAA,0BCGqB","file":"universalSerialize.min.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"universal-serialize\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"universal-serialize\"] = factory();\n\telse\n\t\troot[\"universal-serialize\"] = factory();\n})((typeof self !== 'undefined' ? self : this), function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","/* @flow */\n\nexport const TYPE = {\n FUNCTION: ('function' : 'function'),\n ERROR: ('error' : 'error'),\n PROMISE: ('promise' : 'promise'),\n REGEX: ('regex' : 'regex'),\n DATE: ('date' : 'date'),\n ARRAY: ('array' : 'array'),\n OBJECT: ('object' : 'object'),\n STRING: ('string' : 'string'),\n NUMBER: ('number' : 'number'),\n BOOLEAN: ('boolean' : 'boolean'),\n NULL: ('null' : 'null'),\n UNDEFINED: ('undefined' : 'undefined')\n};\n","/* @flow */\n\nimport { TYPE } from './constants';\nimport type { CustomSerializedType } from './types';\n\nexport function isSerializedType(item : mixed) : boolean {\n return (typeof item === 'object' && item !== null && typeof item.__type__ === 'string');\n}\n\nexport function determineType(val : mixed) : $Values | void {\n if (typeof val === 'undefined') {\n return TYPE.UNDEFINED;\n }\n\n if (val === null) {\n return TYPE.NULL;\n }\n\n if (Array.isArray(val)) {\n return TYPE.ARRAY;\n }\n\n if (typeof val === 'function') {\n return TYPE.FUNCTION;\n }\n\n if (typeof val === 'object') {\n\n if (val instanceof Error) {\n return TYPE.ERROR;\n }\n\n if (typeof val.then === 'function') {\n return TYPE.PROMISE;\n }\n\n if (Object.prototype.toString.call(val) === '[object RegExp]') {\n return TYPE.REGEX;\n }\n\n if (Object.prototype.toString.call(val) === '[object Date]') {\n return TYPE.DATE;\n }\n\n return TYPE.OBJECT;\n }\n\n if (typeof val === 'string') {\n return TYPE.STRING;\n }\n\n if (typeof val === 'number') {\n return TYPE.NUMBER;\n }\n\n if (typeof val === 'boolean') {\n return TYPE.BOOLEAN;\n }\n}\n\nexport function serializeType(type : T, val : V) : CustomSerializedType {\n return {\n __type__: type,\n __val__: val\n };\n}\n","/* @flow */\n\nexport type SerializedArray = $ReadOnlyArray;\n\nexport function serializeArray(val : $ReadOnlyArray) : SerializedArray {\n return val;\n}\n\nexport function deserializeArray(val : SerializedArray) : $ReadOnlyArray {\n return val;\n}\n","/* @flow */\n\nexport type SerializedBoolean = boolean;\n\nexport function serializeBoolean(val : boolean) : SerializedBoolean {\n return val;\n}\n\nexport function deserializeBoolean(val : SerializedBoolean) : boolean {\n return val;\n}\n","/* @flow */\n\nimport { serializeType } from '../common';\nimport { TYPE } from '../constants';\nimport type { NativeSerializedType } from '../types';\n\nexport type SerializedDate = string;\n\nexport function serializeDate(val : Date) : NativeSerializedType {\n return serializeType(TYPE.DATE, val.toJSON());\n}\n\nexport function deserializeDate(val : string) : Date {\n return new Date(val);\n}\n","/* @flow */\n\nimport { serializeType } from '../common';\nimport { TYPE } from '../constants';\nimport type { NativeSerializedType } from '../types';\n\nexport type SerializedError = {|\n message : string,\n stack : string,\n code : string | number | void\n|};\n\n// $FlowFixMe\nexport function serializeError({ message, stack, code } : Error) : NativeSerializedType {\n return serializeType(TYPE.ERROR, { message, stack, code });\n}\n\nexport function deserializeError({ message, stack, code } : SerializedError) : Error {\n const error = new Error(message);\n // $FlowFixMe\n error.code = code;\n error.stack = `${ stack }\\n\\n${ error.stack }`;\n return error;\n}\n","/* @flow */\n\nexport type SerializedFunction = void;\n\nexport function serializeFunction() : SerializedFunction {\n // pass\n}\n\nexport function deserializeFunction() {\n throw new Error(`Function serialization is not implemented; nothing to deserialize`);\n}\n","/* @flow */\n\nexport type SerializedNumber = number;\n\nexport function serializeNumber(val : number) : SerializedNumber {\n return val;\n}\n\nexport function deserializeNumber(val : SerializedNumber) : number {\n return val;\n}\n","/* @flow */\n\nexport type SerializedObject = Object;\n\nexport function serializeObject(val : Object) : SerializedObject {\n return val;\n}\n\nexport function deserializeObject(val : SerializedObject) : Object {\n return val;\n}\n","/* @flow */\n\nexport type SerializedPromise = void;\n\nexport function serializePromise() : SerializedPromise {\n // pass\n}\n\nexport function deserializePromise() {\n throw new Error(`Promise serialization is not implemented; nothing to deserialize`);\n}\n","/* @flow */\n\nimport { serializeType } from '../common';\nimport { TYPE } from '../constants';\nimport type { NativeSerializedType } from '../types';\n\nexport type SerializedRegex = string;\n\nexport function serializeRegex(val : RegExp) : NativeSerializedType {\n return serializeType(TYPE.REGEX, val.source);\n}\n\nexport function deserializeRegex(val : string) : RegExp {\n // eslint-disable-next-line security/detect-non-literal-regexp\n return new RegExp(val);\n}\n","/* @flow */\n\nexport type SerializedString = string;\n\nexport function serializeString(val : string) : SerializedString {\n return val;\n}\n\nexport function deserializeString(val : SerializedString) : string {\n return val;\n}\n","/* @flow */\n\nexport type SerializedNull = null;\n\nexport function serializeNull(val : null) : SerializedNull {\n return val;\n}\n\nexport function deserializeNull(val : SerializedNull) : null {\n return val;\n}\n","/* @flow */\n\nimport { TYPE } from './constants';\nimport type { Thenable, CustomSerializedType, NativeSerializedType } from './types';\nimport { determineType, isSerializedType } from './common';\nimport {\n serializeFunction,\n serializeError, type SerializedError,\n serializePromise,\n serializeRegex, type SerializedRegex,\n serializeDate, type SerializedDate,\n serializeArray,\n serializeObject,\n serializeString,\n serializeNumber,\n serializeBoolean,\n serializeNull\n} from './serializers';\n\ntype NativeSerializer> = (value : V, key : string) => NativeSerializedType;\ntype CustomSerializer = (value : V, key : string) => CustomSerializedType;\ntype PrimitiveSerializer = (value : V, key : string) => S;\ntype CustomOrPrimitiveSerializer = CustomSerializer | PrimitiveSerializer;\ntype NativeOrCustomOrPrimitiveSerializer = NativeSerializer | CustomOrPrimitiveSerializer;\n\ntype Serializers = {|\n function? : CustomOrPrimitiveSerializer,\n error? : NativeOrCustomOrPrimitiveSerializer,\n promise? : CustomOrPrimitiveSerializer,\n regex? : NativeOrCustomOrPrimitiveSerializer,\n date? : NativeOrCustomOrPrimitiveSerializer,\n array? : CustomOrPrimitiveSerializer<$ReadOnlyArray, typeof TYPE.ARRAY>,\n object? : CustomOrPrimitiveSerializer,\n string? : CustomOrPrimitiveSerializer,\n number? : CustomOrPrimitiveSerializer,\n boolean? : CustomOrPrimitiveSerializer,\n null? : CustomOrPrimitiveSerializer\n|};\n\nconst SERIALIZER : Serializers = {\n [ TYPE.FUNCTION ]: serializeFunction,\n [ TYPE.ERROR ]: serializeError,\n [ TYPE.PROMISE ]: serializePromise,\n [ TYPE.REGEX ]: serializeRegex,\n [ TYPE.DATE ]: serializeDate,\n [ TYPE.ARRAY ]: serializeArray,\n [ TYPE.OBJECT ]: serializeObject,\n [ TYPE.STRING ]: serializeString,\n [ TYPE.NUMBER ]: serializeNumber,\n [ TYPE.BOOLEAN ]: serializeBoolean,\n [ TYPE.NULL ]: serializeNull\n};\n\n// $FlowFixMe\nconst defaultSerializers : Serializers = {};\n\nexport function serialize(obj : T, serializers : Serializers = defaultSerializers) : string {\n\n function replacer(key) : ?mixed {\n const val = this[key];\n\n if (isSerializedType(this)) {\n return val;\n }\n \n const type = determineType(val);\n\n if (!type) {\n return val;\n }\n\n // $FlowFixMe\n const serializer = serializers[type] || SERIALIZER[type];\n\n if (!serializer) {\n return val;\n }\n\n return serializer(val, key);\n }\n\n const result = JSON.stringify(obj, replacer);\n\n if (typeof result === 'undefined') {\n return TYPE.UNDEFINED;\n }\n\n return result;\n}\n","/* @flow */\n\nimport type { Thenable } from './types';\nimport { TYPE } from './constants';\nimport { determineType, isSerializedType } from './common';\nimport {\n deserializeFunction,\n deserializeError, type SerializedError,\n deserializePromise,\n deserializeRegex, type SerializedRegex,\n deserializeDate, type SerializedDate,\n deserializeArray,\n deserializeObject,\n deserializeString,\n deserializeNumber,\n deserializeBoolean,\n deserializeNull\n} from './serializers';\n\ntype Deserializer = (serializedValue : S, key : string) => V;\ntype PrimitiveDeserializer = (serializedValue : S, key : string) => V;\n\ntype Deserializers = {\n function? : Deserializer,\n error? : Deserializer,\n promise? : Deserializer,\n regex? : Deserializer,\n date? : Deserializer,\n array? : PrimitiveDeserializer<$ReadOnlyArray>,\n object? : PrimitiveDeserializer,\n string? : PrimitiveDeserializer,\n number? : PrimitiveDeserializer,\n boolean? : PrimitiveDeserializer,\n null? : PrimitiveDeserializer,\n [string] : Deserializer\n};\n\n// $FlowFixMe\nconst DESERIALIZER : Deserializers = {\n [ TYPE.FUNCTION ]: deserializeFunction,\n [ TYPE.ERROR ]: deserializeError,\n [ TYPE.PROMISE ]: deserializePromise,\n [ TYPE.REGEX ]: deserializeRegex,\n [ TYPE.DATE ]: deserializeDate,\n [ TYPE.ARRAY ]: deserializeArray,\n [ TYPE.OBJECT ]: deserializeObject,\n [ TYPE.STRING ]: deserializeString,\n [ TYPE.NUMBER ]: deserializeNumber,\n [ TYPE.BOOLEAN ]: deserializeBoolean,\n [ TYPE.NULL ]: deserializeNull\n};\n\n// $FlowFixMe\nconst defaultDeserializers : Deserializers = {};\n\nexport function deserialize(str : string, deserializers : Deserializers = defaultDeserializers) : T {\n if (str === TYPE.UNDEFINED) {\n // $FlowFixMe\n return;\n }\n\n function replacer(key, val) : ?mixed {\n if (isSerializedType(this)) {\n return val;\n }\n\n let type;\n let value;\n\n if (isSerializedType(val)) {\n type = val.__type__;\n value = val.__val__;\n } else {\n type = determineType(val);\n value = val;\n }\n\n if (!type) {\n return value;\n }\n\n // $FlowFixMe\n const deserializer = deserializers[type] || DESERIALIZER[type];\n\n if (!deserializer) {\n return value;\n }\n\n return deserializer(value, key);\n }\n\n return JSON.parse(str, replacer);\n}\n","/* @flow */\n\nexport * from './serialize';\nexport * from './deserialize';\nexport * from './serializers';\nexport * from './constants';\nexport * from './common';\nexport * from './types';\n","/* @flow */\n\nimport { TYPE } from './constants';\n\n// export something to force webpack to see this as an ES module\nexport const TYPES = true;\n\n// eslint-disable-next-line flowtype/require-exact-type\nexport type Thenable = {\n then : (onSuccess? : (val? : mixed) => mixed, onError? : (err? : mixed) => mixed) => Thenable,\n catch : (onError? : (err? : mixed) => mixed) => Thenable\n};\n\n// eslint-disable-next-line flowtype/require-exact-type\nexport type NativeSerializedType, V : mixed> = {\n __type__ : T,\n __val__ : V\n};\n\nexport type CustomSerializedType = {|\n __type__ : T,\n __val__ : V\n|};\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://universal-serialize/webpack/universalModuleDefinition","webpack://universal-serialize/webpack/bootstrap","webpack://universal-serialize/./src/constants.js","webpack://universal-serialize/./src/common.js","webpack://universal-serialize/./src/serializers/function.js","webpack://universal-serialize/./src/serializers/error.js","webpack://universal-serialize/./src/serializers/promise.js","webpack://universal-serialize/./src/serializers/regex.js","webpack://universal-serialize/./src/serializers/date.js","webpack://universal-serialize/./src/serializers/array.js","webpack://universal-serialize/./src/serializers/object.js","webpack://universal-serialize/./src/serializers/string.js","webpack://universal-serialize/./src/serializers/number.js","webpack://universal-serialize/./src/serializers/boolean.js","webpack://universal-serialize/./src/serializers/null.js","webpack://universal-serialize/./src/serialize.js","webpack://universal-serialize/./src/deserialize.js","webpack://universal-serialize/./src/types.js"],"names":["root","factory","exports","module","define","amd","self","this","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","hasOwnProperty","p","s","TYPE","FUNCTION","ERROR","PROMISE","REGEX","DATE","ARRAY","OBJECT","STRING","NUMBER","BOOLEAN","NULL","UNDEFINED","isSerializedType","item","__type__","determineType","val","Array","isArray","Error","then","toString","serializeType","type","__val__","serializeFunction","deserializeFunction","serializeError","message","stack","code","deserializeError","error","serializePromise","deserializePromise","serializeRegex","source","deserializeRegex","RegExp","serializeDate","toJSON","deserializeDate","Date","serializeArray","deserializeArray","serializeObject","deserializeObject","serializeString","deserializeString","serializeNumber","deserializeNumber","serializeBoolean","deserializeBoolean","serializeNull","deserializeNull","SERIALIZER","defaultSerializers","serialize","obj","serializers","result","JSON","stringify","serializer","DESERIALIZER","defaultDeserializers","deserialize","str","deserializers","parse","deserializer","TYPES"],"mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,sBAAuB,GAAIH,GACR,iBAAZC,QACdA,QAAQ,uBAAyBD,IAEjCD,EAAK,uBAAyBC,IARhC,CASoB,oBAATK,KAAuBA,KAAOC,MAAO,WAChD,O,YCTE,IAAIC,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUR,QAGnC,IAAIC,EAASK,EAAiBE,GAAY,CACzCC,EAAGD,EACHE,GAAG,EACHV,QAAS,IAUV,OANAW,EAAQH,GAAUI,KAAKX,EAAOD,QAASC,EAAQA,EAAOD,QAASO,GAG/DN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nD,OAAKwC,EAIEA,EAAW/C,EAAKzB,GAHZyB,KAQf,YAAsB,IAAX4C,EACA7D,EAAKY,UAGTiD,ECjDX,IAAMI,IAA4B,MAC5BjE,EAAKC,UAAa0B,EADU,EAE5B3B,EAAKE,OAAa8B,EAFU,EAG5BhC,EAAKG,SAAagC,EAHU,EAI5BnC,EAAKI,OAAakC,EAJU,EAK5BtC,EAAKK,MAAaqC,EALU,EAM5B1C,EAAKM,OAAauC,EANU,EAO5B7C,EAAKO,QAAawC,EAPU,EAQ5B/C,EAAKQ,QAAayC,EARU,EAS5BjD,EAAKS,QAAa0C,EATU,EAU5BnD,EAAKU,SAAa2C,EAVU,EAW5BrD,EAAKW,MAAa4C,EAXU,GAe5BW,EAAuC,GAEtC,SAASC,EAAqCC,EAAcC,GAC/D,QADyH,IAA1DA,MAAgCH,GAC3FE,IAAQpE,EAAKY,UAmCjB,OAAOkD,KAAKQ,MAAMF,GA9BlB,SAAkB5E,EAAKyB,GACnB,GAAIJ,EAAiBhD,MACjB,OAAOoD,EAGX,IAAIO,EACAtC,EAUJ,GARI2B,EAAiBI,IACjBO,EAAOP,EAAIF,SACX7B,EAAQ+B,EAAIQ,UAEZD,EAAOR,EAAcC,GACrB/B,EAAQ+B,IAGPO,EACD,OAAOtC,EAIX,IAAMqF,EAAeF,EAAc7C,IAASyC,EAAazC,GAEzD,OAAK+C,EAIEA,EAAarF,EAAOM,GAHhBN,KChFZ,IAAMsF,GAAQ","file":"universalSerialize.min.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"universal-serialize\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"universal-serialize\"] = factory();\n\telse\n\t\troot[\"universal-serialize\"] = factory();\n})((typeof self !== 'undefined' ? self : this), function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","/* @flow */\n\nexport const TYPE = {\n FUNCTION: ('function' : 'function'),\n ERROR: ('error' : 'error'),\n PROMISE: ('promise' : 'promise'),\n REGEX: ('regex' : 'regex'),\n DATE: ('date' : 'date'),\n ARRAY: ('array' : 'array'),\n OBJECT: ('object' : 'object'),\n STRING: ('string' : 'string'),\n NUMBER: ('number' : 'number'),\n BOOLEAN: ('boolean' : 'boolean'),\n NULL: ('null' : 'null'),\n UNDEFINED: ('undefined' : 'undefined')\n};\n","/* @flow */\n\nimport { TYPE } from './constants';\nimport type { CustomSerializedType } from './types';\n\nexport function isSerializedType(item : mixed) : boolean {\n return (typeof item === 'object' && item !== null && typeof item.__type__ === 'string');\n}\n\nexport function determineType(val : mixed) : $Values | void {\n if (typeof val === 'undefined') {\n return TYPE.UNDEFINED;\n }\n\n if (val === null) {\n return TYPE.NULL;\n }\n\n if (Array.isArray(val)) {\n return TYPE.ARRAY;\n }\n\n if (typeof val === 'function') {\n return TYPE.FUNCTION;\n }\n\n if (typeof val === 'object') {\n\n if (val instanceof Error) {\n return TYPE.ERROR;\n }\n\n if (typeof val.then === 'function') {\n return TYPE.PROMISE;\n }\n\n if (Object.prototype.toString.call(val) === '[object RegExp]') {\n return TYPE.REGEX;\n }\n\n if (Object.prototype.toString.call(val) === '[object Date]') {\n return TYPE.DATE;\n }\n\n return TYPE.OBJECT;\n }\n\n if (typeof val === 'string') {\n return TYPE.STRING;\n }\n\n if (typeof val === 'number') {\n return TYPE.NUMBER;\n }\n\n if (typeof val === 'boolean') {\n return TYPE.BOOLEAN;\n }\n}\n\nexport function serializeType(type : T, val : V) : CustomSerializedType {\n return {\n __type__: type,\n __val__: val\n };\n}\n","/* @flow */\n\nexport type SerializedFunction = void;\n\nexport function serializeFunction() : SerializedFunction {\n // pass\n}\n\nexport function deserializeFunction() {\n throw new Error(`Function serialization is not implemented; nothing to deserialize`);\n}\n","/* @flow */\n\nimport { serializeType } from '../common';\nimport { TYPE } from '../constants';\nimport type { NativeSerializedType } from '../types';\n\nexport type SerializedError = {|\n message : string,\n stack : string,\n code : string | number | void\n|};\n\n// $FlowFixMe\nexport function serializeError({ message, stack, code } : Error) : NativeSerializedType {\n return serializeType(TYPE.ERROR, { message, stack, code });\n}\n\nexport function deserializeError({ message, stack, code } : SerializedError) : Error {\n const error = new Error(message);\n // $FlowFixMe\n error.code = code;\n error.stack = `${ stack }\\n\\n${ error.stack }`;\n return error;\n}\n","/* @flow */\n\nexport type SerializedPromise = void;\n\nexport function serializePromise() : SerializedPromise {\n // pass\n}\n\nexport function deserializePromise() {\n throw new Error(`Promise serialization is not implemented; nothing to deserialize`);\n}\n","/* @flow */\n\nimport { serializeType } from '../common';\nimport { TYPE } from '../constants';\nimport type { NativeSerializedType } from '../types';\n\nexport type SerializedRegex = string;\n\nexport function serializeRegex(val : RegExp) : NativeSerializedType {\n return serializeType(TYPE.REGEX, val.source);\n}\n\nexport function deserializeRegex(val : string) : RegExp {\n // eslint-disable-next-line security/detect-non-literal-regexp\n return new RegExp(val);\n}\n","/* @flow */\n\nimport { serializeType } from '../common';\nimport { TYPE } from '../constants';\nimport type { NativeSerializedType } from '../types';\n\nexport type SerializedDate = string;\n\nexport function serializeDate(val : Date) : NativeSerializedType {\n return serializeType(TYPE.DATE, val.toJSON());\n}\n\nexport function deserializeDate(val : string) : Date {\n return new Date(val);\n}\n","/* @flow */\n\nexport type SerializedArray = $ReadOnlyArray;\n\nexport function serializeArray(val : $ReadOnlyArray) : SerializedArray {\n return val;\n}\n\nexport function deserializeArray(val : SerializedArray) : $ReadOnlyArray {\n return val;\n}\n","/* @flow */\n\nexport type SerializedObject = Object;\n\nexport function serializeObject(val : Object) : SerializedObject {\n return val;\n}\n\nexport function deserializeObject(val : SerializedObject) : Object {\n return val;\n}\n","/* @flow */\n\nexport type SerializedString = string;\n\nexport function serializeString(val : string) : SerializedString {\n return val;\n}\n\nexport function deserializeString(val : SerializedString) : string {\n return val;\n}\n","/* @flow */\n\nexport type SerializedNumber = number;\n\nexport function serializeNumber(val : number) : SerializedNumber {\n return val;\n}\n\nexport function deserializeNumber(val : SerializedNumber) : number {\n return val;\n}\n","/* @flow */\n\nexport type SerializedBoolean = boolean;\n\nexport function serializeBoolean(val : boolean) : SerializedBoolean {\n return val;\n}\n\nexport function deserializeBoolean(val : SerializedBoolean) : boolean {\n return val;\n}\n","/* @flow */\n\nexport type SerializedNull = null;\n\nexport function serializeNull(val : null) : SerializedNull {\n return val;\n}\n\nexport function deserializeNull(val : SerializedNull) : null {\n return val;\n}\n","/* @flow */\n\nimport { TYPE } from './constants';\nimport type { Thenable, CustomSerializedType, NativeSerializedType } from './types';\nimport { determineType, isSerializedType } from './common';\nimport {\n serializeFunction,\n serializeError, type SerializedError,\n serializePromise,\n serializeRegex, type SerializedRegex,\n serializeDate, type SerializedDate,\n serializeArray,\n serializeObject,\n serializeString,\n serializeNumber,\n serializeBoolean,\n serializeNull\n} from './serializers';\n\ntype NativeSerializer> = (value : V, key : string) => NativeSerializedType;\ntype CustomSerializer = (value : V, key : string) => CustomSerializedType;\ntype PrimitiveSerializer = (value : V, key : string) => S;\ntype CustomOrPrimitiveSerializer = CustomSerializer | PrimitiveSerializer;\ntype NativeOrCustomOrPrimitiveSerializer = NativeSerializer | CustomOrPrimitiveSerializer;\n\ntype Serializers = {|\n function? : CustomOrPrimitiveSerializer,\n error? : NativeOrCustomOrPrimitiveSerializer,\n promise? : CustomOrPrimitiveSerializer,\n regex? : NativeOrCustomOrPrimitiveSerializer,\n date? : NativeOrCustomOrPrimitiveSerializer,\n array? : CustomOrPrimitiveSerializer<$ReadOnlyArray, typeof TYPE.ARRAY>,\n object? : CustomOrPrimitiveSerializer,\n string? : CustomOrPrimitiveSerializer,\n number? : CustomOrPrimitiveSerializer,\n boolean? : CustomOrPrimitiveSerializer,\n null? : CustomOrPrimitiveSerializer\n|};\n\nconst SERIALIZER : Serializers = {\n [ TYPE.FUNCTION ]: serializeFunction,\n [ TYPE.ERROR ]: serializeError,\n [ TYPE.PROMISE ]: serializePromise,\n [ TYPE.REGEX ]: serializeRegex,\n [ TYPE.DATE ]: serializeDate,\n [ TYPE.ARRAY ]: serializeArray,\n [ TYPE.OBJECT ]: serializeObject,\n [ TYPE.STRING ]: serializeString,\n [ TYPE.NUMBER ]: serializeNumber,\n [ TYPE.BOOLEAN ]: serializeBoolean,\n [ TYPE.NULL ]: serializeNull\n};\n\n// $FlowFixMe\nconst defaultSerializers : Serializers = {};\n\nexport function serialize(obj : T, serializers : Serializers = defaultSerializers) : string {\n\n function replacer(key) : ?mixed {\n const val = this[key];\n\n if (isSerializedType(this)) {\n return val;\n }\n \n const type = determineType(val);\n\n if (!type) {\n return val;\n }\n\n // $FlowFixMe\n const serializer = serializers[type] || SERIALIZER[type];\n\n if (!serializer) {\n return val;\n }\n\n return serializer(val, key);\n }\n\n const result = JSON.stringify(obj, replacer);\n\n if (typeof result === 'undefined') {\n return TYPE.UNDEFINED;\n }\n\n return result;\n}\n","/* @flow */\n\nimport type { Thenable } from './types';\nimport { TYPE } from './constants';\nimport { determineType, isSerializedType } from './common';\nimport {\n deserializeFunction,\n deserializeError, type SerializedError,\n deserializePromise,\n deserializeRegex, type SerializedRegex,\n deserializeDate, type SerializedDate,\n deserializeArray,\n deserializeObject,\n deserializeString,\n deserializeNumber,\n deserializeBoolean,\n deserializeNull\n} from './serializers';\n\ntype Deserializer = (serializedValue : S, key : string) => V;\ntype PrimitiveDeserializer = (serializedValue : S, key : string) => V;\n\ntype Deserializers = {\n function? : Deserializer,\n error? : Deserializer,\n promise? : Deserializer,\n regex? : Deserializer,\n date? : Deserializer,\n array? : PrimitiveDeserializer<$ReadOnlyArray>,\n object? : PrimitiveDeserializer,\n string? : PrimitiveDeserializer,\n number? : PrimitiveDeserializer,\n boolean? : PrimitiveDeserializer,\n null? : PrimitiveDeserializer,\n [string] : Deserializer\n};\n\n// $FlowFixMe\nconst DESERIALIZER : Deserializers = {\n [ TYPE.FUNCTION ]: deserializeFunction,\n [ TYPE.ERROR ]: deserializeError,\n [ TYPE.PROMISE ]: deserializePromise,\n [ TYPE.REGEX ]: deserializeRegex,\n [ TYPE.DATE ]: deserializeDate,\n [ TYPE.ARRAY ]: deserializeArray,\n [ TYPE.OBJECT ]: deserializeObject,\n [ TYPE.STRING ]: deserializeString,\n [ TYPE.NUMBER ]: deserializeNumber,\n [ TYPE.BOOLEAN ]: deserializeBoolean,\n [ TYPE.NULL ]: deserializeNull\n};\n\n// $FlowFixMe\nconst defaultDeserializers : Deserializers = {};\n\nexport function deserialize(str : string, deserializers : Deserializers = defaultDeserializers) : T {\n if (str === TYPE.UNDEFINED) {\n // $FlowFixMe\n return;\n }\n\n function replacer(key, val) : ?mixed {\n if (isSerializedType(this)) {\n return val;\n }\n\n let type;\n let value;\n\n if (isSerializedType(val)) {\n type = val.__type__;\n value = val.__val__;\n } else {\n type = determineType(val);\n value = val;\n }\n\n if (!type) {\n return value;\n }\n\n // $FlowFixMe\n const deserializer = deserializers[type] || DESERIALIZER[type];\n\n if (!deserializer) {\n return value;\n }\n\n return deserializer(value, key);\n }\n\n return JSON.parse(str, replacer);\n}\n","/* @flow */\n\nimport { TYPE } from './constants';\n\n// export something to force webpack to see this as an ES module\nexport const TYPES = true;\n\n// eslint-disable-next-line flowtype/require-exact-type\nexport type Thenable = {\n then : (onSuccess? : (val? : mixed) => mixed, onError? : (err? : mixed) => mixed) => Thenable,\n catch : (onError? : (err? : mixed) => mixed) => Thenable\n};\n\n// eslint-disable-next-line flowtype/require-exact-type\nexport type NativeSerializedType, V : mixed> = {\n __type__ : T,\n __val__ : V\n};\n\nexport type CustomSerializedType = {|\n __type__ : T,\n __val__ : V\n|};\n"],"sourceRoot":""} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 94a39d3..0000000 --- a/index.js +++ /dev/null @@ -1,4 +0,0 @@ -/* @flow */ - -// $FlowFixMe -module.exports = require('./dist/universal-serialize'); // eslint-disable-line import/no-commonjs diff --git a/package.json b/package.json index e19172b..d3db9db 100644 --- a/package.json +++ b/package.json @@ -2,17 +2,21 @@ "name": "universal-serialize", "version": "1.0.7", "description": "Javascript module template.", - "main": "index.js", + "main": "lib/index.js", + "module": "es/index.js", + "sideEffects": false, "scripts": { "setup": "npm install && npm run flow-typed", "lint": "eslint src/ test/ *.js --ext .js,.jsx", "flow-typed": "rm -rf ./flow-typed && flow-typed install && flow-typed install mocha@4", "flow": "flow", "karma": "cross-env NODE_ENV=test babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/karma start", - "babel": "babel src/ --out-dir dist/module", + "babel": "babel src --delete-dir-on-start", + "babel:cjs": "npm run babel -- --out-dir lib --env-name cjs", + "babel:es": "npm run babel -- --out-dir es --env-name esm", "webpack": "babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --progress", "test": "npm run lint && npm run flow-typed && npm run flow && npm run karma", - "build": "npm run test && npm run babel && npm run webpack", + "build": "npm run test && npm run babel:cjs && npm run babel:es && npm run webpack", "release": "./publish.sh", "release:patch": "./publish.sh patch", "release:minor": "./publish.sh minor", @@ -23,6 +27,8 @@ }, "files": [ "dist/", + "es/", + "lib/", "src/" ], "browserslist": [ @@ -49,5 +55,8 @@ "devDependencies": { "flow-bin": "^0.85", "grumbler-scripts": "^3" + }, + "dependencies": { + "@babel/runtime": "^7.9.2" } }