Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typeson

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typeson - npm Package Compare versions

Comparing version 5.14.1 to 5.15.0

5

CHANGES.md
# typeson CHANGES
## 5.15.0
- Enhancement: Allow cloning during encapsulation of (non-registered)
classes using `Symbol.toStringTag` (#17)
## 5.14.1

@@ -4,0 +9,0 @@

2

dist/typeson-commonjs2.min.js

@@ -1,1 +0,1 @@

"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach((function(t){_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_nonIterableRest()}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function _iterableToArrayLimit(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],r=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==s.return||s.return()}finally{if(o)throw i}}return n}}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var TypesonPromise=function TypesonPromise(e){_classCallCheck(this,TypesonPromise),this.p=new Promise(e)};TypesonPromise.__typeson__type__="TypesonPromise","undefined"!=typeof Symbol&&(TypesonPromise.prototype[Symbol.toStringTag]="TypesonPromise"),TypesonPromise.prototype.then=function(e,t){var n=this;return new TypesonPromise((function(r,o){n.p.then((function(t){r(e?e(t):t)})).catch((function(e){return t?t(e):Promise.reject(e)})).then(r,o)}))},TypesonPromise.prototype.catch=function(e){return this.then(null,e)},TypesonPromise.resolve=function(e){return new TypesonPromise((function(t){t(e)}))},TypesonPromise.reject=function(e){return new TypesonPromise((function(t,n){n(e)}))},["all","race"].forEach((function(e){TypesonPromise[e]=function(t){return new TypesonPromise((function(n,r){Promise[e](t.map((function(e){return e.p}))).then(n,r)}))}}));var _ref={},toStr=_ref.toString,hasOwn={}.hasOwnProperty,getProto=Object.getPrototypeOf,fnToString=hasOwn.toString;function isThenable(e,t){return isObject(e)&&"function"==typeof e.then&&(!t||"function"==typeof e.catch)}function toStringTag(e){return toStr.call(e).slice(8,-1)}function hasConstructorOf(e,t){if(!e||"object"!==_typeof(e))return!1;var n=getProto(e);if(!n)return!1;var r=hasOwn.call(n,"constructor")&&n.constructor;return"function"!=typeof r?null===t:t===r||(null!==t&&fnToString.call(r)===fnToString.call(t)||"function"==typeof t&&"string"==typeof r.__typeson__type__&&r.__typeson__type__===t.__typeson__type__)}function isPlainObject(e){return!(!e||"Object"!==toStringTag(e))&&(!getProto(e)||hasConstructorOf(e,Object))}function isUserObject(e){if(!e||"Object"!==toStringTag(e))return!1;var t=getProto(e);return!t||(hasConstructorOf(e,Object)||isUserObject(t))}function isObject(e){return e&&"object"===_typeof(e)}function escapeKeyPathComponent(e){return e.replace(/~/g,"~0").replace(/\./g,"~1")}function unescapeKeyPathComponent(e){return e.replace(/~1/g,".").replace(/~0/g,"~")}function getByKeyPath(e,t){if(""===t)return e;var n=t.indexOf(".");if(n>-1){var r=e[unescapeKeyPathComponent(t.slice(0,n))];return void 0===r?void 0:getByKeyPath(r,t.slice(n+1))}return e[unescapeKeyPathComponent(t)]}function setAtKeyPath(e,t,n){if(""===t)return n;var r=t.indexOf(".");return r>-1?setAtKeyPath(e[unescapeKeyPathComponent(t.slice(0,r))],t.slice(r+1),n):(e[unescapeKeyPathComponent(t)]=n,e)}function getJSONType(e){return null===e?"null":Array.isArray(e)?"array":_typeof(e)}var keys=Object.keys,isArray=Array.isArray,hasOwn$1={}.hasOwnProperty,internalStateObjPropsToIgnore=["type","replaced","iterateIn","iterateUnsetNumeric"];function nestedPathsFirst(e,t){var n=e.keypath.match(/\./g),r=e.keypath.match(/\./g);return n&&(n=n.length),r&&(r=r.length),n>r?-1:n<r?1:e.keypath<t.keypath?-1:e.keypath>t.keypath}var Typeson=function(){function Typeson(e){_classCallCheck(this,Typeson),this.options=e,this.plainObjectReplacers=[],this.nonplainObjectReplacers=[],this.revivers={},this.types={}}return _createClass(Typeson,[{key:"stringify",value:function stringify(e,t,n,r){r=_objectSpread2({},this.options,{},r,{stringification:!0});var o=this.encapsulate(e,null,r);return isArray(o)?JSON.stringify(o[0],t,n):o.then((function(e){return JSON.stringify(e,t,n)}))}},{key:"stringifySync",value:function stringifySync(e,t,n,r){return this.stringify(e,t,n,_objectSpread2({throwOnBadSyncType:!0},r,{sync:!0}))}},{key:"stringifyAsync",value:function stringifyAsync(e,t,n,r){return this.stringify(e,t,n,_objectSpread2({throwOnBadSyncType:!0},r,{sync:!1}))}},{key:"parse",value:function parse(e,t,n){return n=_objectSpread2({},this.options,{},n,{parse:!0}),this.revive(JSON.parse(e,t),n)}},{key:"parseSync",value:function parseSync(e,t,n){return this.parse(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!0}))}},{key:"parseAsync",value:function parseAsync(e,t,n){return this.parse(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!1}))}},{key:"specialTypeNames",value:function specialTypeNames(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.returnTypeNames=!0,this.encapsulate(e,t,n)}},{key:"rootTypeName",value:function rootTypeName(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.iterateNone=!0,this.encapsulate(e,t,n)}},{key:"encapsulate",value:function encapsulate(e,t,n){var r=(n=_objectSpread2({sync:!0},this.options,{},n)).sync,o=this,i={},a=[],s=[],c=[],u=!("cyclic"in n)||n.cyclic,p=n.encapsulateObserver,y=_encapsulate("",e,u,t||{},c);function finish(e){var t=Object.values(i);if(n.iterateNone)return t.length?t[0]:Typeson.getJSONType(e);if(t.length){if(n.returnTypeNames)return _toConsumableArray(new Set(t));e&&isPlainObject(e)&&!hasOwn$1.call(e,"$types")?e.$types=i:e={$:e,$types:{$:i}}}else isObject(e)&&hasOwn$1.call(e,"$types")&&(e={$:e,$types:!0});return!n.returnTypeNames&&e}function _adaptBuiltinStateObjectProperties(e,t,n){Object.assign(e,t);var r=internalStateObjPropsToIgnore.map((function(t){var n=e[t];return delete e[t],n}));n(),internalStateObjPropsToIgnore.forEach((function(t,n){e[t]=r[n]}))}function _encapsulate(e,t,r,c,u,y,l){var f,h={},v=_typeof(t),d=p?function(n){var o=l||c.type||Typeson.getJSONType(t);p(Object.assign(n||h,{keypath:e,value:t,cyclic:r,stateObj:c,promisesData:u,resolvingTypesonPromise:y,awaitingTypesonPromise:hasConstructorOf(t,TypesonPromise)},void 0!==o?{type:o}:{}))}:null;if(["string","boolean","number","undefined"].includes(v))return void 0===t||"number"===v&&(isNaN(t)||t===-1/0||t===1/0)?(f=replace(e,t,c,u,!1,y,d))!==t&&(h={replaced:f}):f=t,d&&d(),f;if(null===t)return d&&d(),t;if(r&&!c.iterateIn&&!c.iterateUnsetNumeric){var b=a.indexOf(t);if(!(b<0))return i[e]="#",d&&d({cyclicKeypath:s[b]}),"#"+s[b];!0===r&&(a.push(t),s.push(e))}var O,m=isPlainObject(t),T=isArray(t),P=(m||T)&&(!o.plainObjectReplacers.length||c.replaced)||c.iterateIn?t:replace(e,t,c,u,m||T,null,d);if(P!==t?(f=P,h={replaced:P}):T&&"object"!==c.iterateIn||"array"===c.iterateIn?(O=new Array(t.length),h={clone:O}):m||"object"===c.iterateIn?(O={},c.addLength&&(O.length=t.length),h={clone:O}):""===e&&hasConstructorOf(t,TypesonPromise)?(u.push([e,t,r,c,void 0,void 0,c.type]),f=t):f=t,d&&d(),n.iterateNone)return O||f;if(!O)return f;if(c.iterateIn){var g=function _loop(n){var o={ownKeys:hasOwn$1.call(t,n)};_adaptBuiltinStateObjectProperties(c,o,(function(){var o=e+(e?".":"")+escapeKeyPathComponent(n),i=_encapsulate(o,t[n],Boolean(r),c,u,y);hasConstructorOf(i,TypesonPromise)?u.push([o,i,Boolean(r),c,O,n,c.type]):void 0!==i&&(O[n]=i)}))};for(var _ in t)g(_);d&&d({endIterateIn:!0,end:!0})}else keys(t).forEach((function(n){var o=e+(e?".":"")+escapeKeyPathComponent(n);_adaptBuiltinStateObjectProperties(c,{ownKeys:!0},(function(){var e=_encapsulate(o,t[n],Boolean(r),c,u,y);hasConstructorOf(e,TypesonPromise)?u.push([o,e,Boolean(r),c,O,n,c.type]):void 0!==e&&(O[n]=e)}))})),d&&d({endIterateOwn:!0,end:!0});if(c.iterateUnsetNumeric){for(var j=t.length,S=function _loop2(n){if(!(n in t)){var o=e+(e?".":"")+n;_adaptBuiltinStateObjectProperties(c,{ownKeys:!1},(function(){var e=_encapsulate(o,void 0,Boolean(r),c,u,y);hasConstructorOf(e,TypesonPromise)?u.push([o,e,Boolean(r),c,O,n,c.type]):void 0!==e&&(O[n]=e)}))}},w=0;w<j;w++)S(w);d&&d({endIterateUnsetNumeric:!0,end:!0})}return O}function replace(e,t,n,a,s,c,p){for(var y=s?o.plainObjectReplacers:o.nonplainObjectReplacers,l=y.length;l--;){var f=y[l];if(f.test(t,n)){var h=f.type;if(o.revivers[h]){var v=i[e];i[e]=v?[h].concat(v):h}return Object.assign(n,{type:h,replaced:!0}),!r&&f.replaceAsync||f.replace?(p&&p({replacing:!0}),_encapsulate(e,f[r||!f.replaceAsync?"replace":"replaceAsync"](t,n),u&&"readonly",n,a,c,h)):(p&&p({typeDetected:!0}),_encapsulate(e,t,u&&"readonly",n,a,c,h))}}return t}return c.length?r&&n.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():Promise.resolve(function checkPromises(e,t){var n;return regeneratorRuntime.async((function checkPromises$(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,regeneratorRuntime.awrap(Promise.all(t.map((function(e){return e[1].p}))));case 2:return n=r.sent,r.next=5,regeneratorRuntime.awrap(Promise.all(n.map((function _callee(n){var r,o,i,a,s,c,u,p,y,l,f,h,v,d;return regeneratorRuntime.async((function _callee$(b){for(;;)switch(b.prev=b.next){case 0:if(r=[],o=t.splice(0,1),i=_slicedToArray(o,1),a=i[0],s=_slicedToArray(a,7),c=s[0],u=s[2],p=s[3],y=s[4],l=s[5],f=s[6],h=_encapsulate(c,n,u,p,r,!0,f),v=hasConstructorOf(h,TypesonPromise),!c||!v){b.next=11;break}return b.next=8,regeneratorRuntime.awrap(h.p);case 8:return d=b.sent,y[l]=d,b.abrupt("return",checkPromises(e,r));case 11:return c?y[l]=h:e=v?h.p:h,b.abrupt("return",checkPromises(e,r));case 13:case"end":return b.stop()}}))}))));case 5:return r.abrupt("return",e);case 6:case"end":return r.stop()}}))}(y,c)).then(finish):!r&&n.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():n.stringification&&r?[finish(y)]:r?finish(y):Promise.resolve(finish(y))}},{key:"encapsulateSync",value:function encapsulateSync(e,t,n){return this.encapsulate(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!0}))}},{key:"encapsulateAsync",value:function encapsulateAsync(e,t,n){return this.encapsulate(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!1}))}},{key:"revive",value:function revive(e,t){var n=e&&e.$types;if(!n)return e;if(!0===n)return e.$;var r=(t=_objectSpread2({sync:!0},this.options,{},t)).sync,o=[],i={},a=!0;n.$&&isPlainObject(n.$)&&(e=e.$,n=n.$,a=!1);var s=this;function _revive(e,t,c,u,p){if(!a||"$types"!==e){var y=n[e];if(isArray(t)||isPlainObject(t)){var l=isArray(t)?new Array(t.length):{};for(keys(t).forEach((function(n){var r=_revive(e+(e?".":"")+escapeKeyPathComponent(n),t[n],c||l,l,n);hasConstructorOf(r,Undefined)?l[n]=void 0:void 0!==r&&(l[n]=r)})),t=l;o.length;){var f=_slicedToArray(o[0],4),h=f[0],v=f[1],d=f[2],b=f[3],O=getByKeyPath(h,v);if(hasConstructorOf(O,Undefined))d[b]=void 0;else{if(void 0===O)break;d[b]=O}o.splice(0,1)}}if(!y)return t;if("#"===y){var m=getByKeyPath(c,t.slice(1));return void 0===m&&o.push([c,t.slice(1),u,p]),m}return[].concat(y).reduce((function reducer(e,t){if(hasConstructorOf(e,TypesonPromise))return e.then((function(e){return reducer(e,t)}));var n=_slicedToArray(s.revivers[t],1)[0];if(!n)throw new Error("Unregistered type: "+t);return n[r&&n.revive?"revive":!r&&n.reviveAsync?"reviveAsync":"revive"](e,i)}),t)}}function checkUndefined(e){return hasConstructorOf(e,Undefined)?void 0:e}var c,u=function revivePlainObjects(){var t=[];if(Object.entries(n).forEach((function(e){var r=_slicedToArray(e,2),o=r[0],i=r[1];"#"!==i&&[].concat(i).forEach((function(e){_slicedToArray(s.revivers[e],2)[1].plain&&(t.push({keypath:o,type:e}),delete n[o])}))})),t.length)return t.sort(nestedPathsFirst).reduce((function reducer(t,n){var o=n.keypath,a=n.type;if(hasConstructorOf(t,TypesonPromise))return t.then((function(e){return reducer(e,a)}));var c=getByKeyPath(e,o);if(hasConstructorOf(c,TypesonPromise))return c.then((function(e){return reducer(e,a)}));var u=_slicedToArray(s.revivers[a],1)[0];if(!u)throw new Error("Unregistered type: "+a);void 0!==(c=u[r&&u.revive?"revive":!r&&u.reviveAsync?"reviveAsync":"revive"](c,i))&&(hasConstructorOf(c,Undefined)&&(c=void 0),setAtKeyPath(e,o,c)===c&&(e=c))}),void 0)}();return isThenable(c=hasConstructorOf(u,TypesonPromise)?u.then((function(){return _revive("",e,null)})):_revive("",e,null))?r&&t.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():hasConstructorOf(c,TypesonPromise)?c.p.then(checkUndefined):c:!r&&t.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():r?checkUndefined(c):Promise.resolve(checkUndefined(c))}},{key:"reviveSync",value:function reviveSync(e,t){return this.revive(e,_objectSpread2({throwOnBadSyncType:!0},t,{sync:!0}))}},{key:"reviveAsync",value:function reviveAsync(e,t){return this.revive(e,_objectSpread2({throwOnBadSyncType:!0},t,{sync:!1}))}},{key:"register",value:function register(e,t){return t=t||{},[].concat(e).forEach((function R(e){var n=this;if(isArray(e))return e.map((function(e){return R.call(n,e)}));e&&keys(e).forEach((function(n){if("#"===n)throw new TypeError("# cannot be used as a type name as it is reserved for cyclic objects");if(Typeson.JSON_TYPES.includes(n))throw new TypeError("Plain JSON object types are reserved as type names");var r=e[n],o=r.testPlainObjects?this.plainObjectReplacers:this.nonplainObjectReplacers,i=o.filter((function(e){return e.type===n}));if(i.length&&(o.splice(o.indexOf(i[0]),1),delete this.revivers[n],delete this.types[n]),r){if("function"==typeof r){var a=r;r={test:function test(e){return e&&e.constructor===a},replace:function replace(e){return _objectSpread2({},e)},revive:function revive(e){return Object.assign(Object.create(a.prototype),e)}}}else if(isArray(r)){var s=_slicedToArray(r,3);r={test:s[0],replace:s[1],revive:s[2]}}var c={type:n,test:r.test.bind(r)};r.replace&&(c.replace=r.replace.bind(r)),r.replaceAsync&&(c.replaceAsync=r.replaceAsync.bind(r));var u="number"==typeof t.fallback?t.fallback:t.fallback?0:1/0;if(r.testPlainObjects?this.plainObjectReplacers.splice(u,0,c):this.nonplainObjectReplacers.splice(u,0,c),r.revive||r.reviveAsync){var p={};r.revive&&(p.revive=r.revive.bind(r)),r.reviveAsync&&(p.reviveAsync=r.reviveAsync.bind(r)),this.revivers[n]=[p,{plain:r.testPlainObjects}]}this.types[n]=r}}),this)}),this),this}}]),Typeson}(),Undefined=function Undefined(){_classCallCheck(this,Undefined)};Undefined.__typeson__type__="TypesonUndefined",Typeson.Undefined=Undefined,Typeson.Promise=TypesonPromise,Typeson.isThenable=isThenable,Typeson.toStringTag=toStringTag,Typeson.hasConstructorOf=hasConstructorOf,Typeson.isObject=isObject,Typeson.isPlainObject=isPlainObject,Typeson.isUserObject=isUserObject,Typeson.escapeKeyPathComponent=escapeKeyPathComponent,Typeson.unescapeKeyPathComponent=unescapeKeyPathComponent,Typeson.getByKeyPath=getByKeyPath,Typeson.getJSONType=getJSONType,Typeson.JSON_TYPES=["null","boolean","number","string","array","object"],module.exports=Typeson;
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach((function(t){_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_nonIterableRest()}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function _iterableToArrayLimit(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],r=!0,o=!1,i=void 0;try{for(var s,a=e[Symbol.iterator]();!(r=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}var TypesonPromise=function TypesonPromise(e){_classCallCheck(this,TypesonPromise),this.p=new Promise(e)};TypesonPromise.__typeson__type__="TypesonPromise","undefined"!=typeof Symbol&&(TypesonPromise.prototype[Symbol.toStringTag]="TypesonPromise"),TypesonPromise.prototype.then=function(e,t){var n=this;return new TypesonPromise((function(r,o){n.p.then((function(t){r(e?e(t):t)})).catch((function(e){return t?t(e):Promise.reject(e)})).then(r,o)}))},TypesonPromise.prototype.catch=function(e){return this.then(null,e)},TypesonPromise.resolve=function(e){return new TypesonPromise((function(t){t(e)}))},TypesonPromise.reject=function(e){return new TypesonPromise((function(t,n){n(e)}))},["all","race"].forEach((function(e){TypesonPromise[e]=function(t){return new TypesonPromise((function(n,r){Promise[e](t.map((function(e){return e.p}))).then(n,r)}))}}));var _ref={},toStr=_ref.toString,hasOwn={}.hasOwnProperty,getProto=Object.getPrototypeOf,fnToString=hasOwn.toString;function isThenable(e,t){return isObject(e)&&"function"==typeof e.then&&(!t||"function"==typeof e.catch)}function toStringTag(e){return toStr.call(e).slice(8,-1)}function hasConstructorOf(e,t){if(!e||"object"!==_typeof(e))return!1;var n=getProto(e);if(!n)return!1;var r=hasOwn.call(n,"constructor")&&n.constructor;return"function"!=typeof r?null===t:t===r||(null!==t&&fnToString.call(r)===fnToString.call(t)||"function"==typeof t&&"string"==typeof r.__typeson__type__&&r.__typeson__type__===t.__typeson__type__)}function isPlainObject(e){return!(!e||"Object"!==toStringTag(e))&&(!getProto(e)||hasConstructorOf(e,Object))}function isUserObject(e){if(!e||"Object"!==toStringTag(e))return!1;var t=getProto(e);return!t||(hasConstructorOf(e,Object)||isUserObject(t))}function isObject(e){return e&&"object"===_typeof(e)}function escapeKeyPathComponent(e){return e.replace(/~/g,"~0").replace(/\./g,"~1")}function unescapeKeyPathComponent(e){return e.replace(/~1/g,".").replace(/~0/g,"~")}function getByKeyPath(e,t){if(""===t)return e;var n=t.indexOf(".");if(n>-1){var r=e[unescapeKeyPathComponent(t.slice(0,n))];return void 0===r?void 0:getByKeyPath(r,t.slice(n+1))}return e[unescapeKeyPathComponent(t)]}function setAtKeyPath(e,t,n){if(""===t)return n;var r=t.indexOf(".");return r>-1?setAtKeyPath(e[unescapeKeyPathComponent(t.slice(0,r))],t.slice(r+1),n):(e[unescapeKeyPathComponent(t)]=n,e)}function getJSONType(e){return null===e?"null":Array.isArray(e)?"array":_typeof(e)}var keys=Object.keys,isArray=Array.isArray,hasOwn$1={}.hasOwnProperty,internalStateObjPropsToIgnore=["type","replaced","iterateIn","iterateUnsetNumeric"];function nestedPathsFirst(e,t){var n=e.keypath.match(/\./g),r=e.keypath.match(/\./g);return n&&(n=n.length),r&&(r=r.length),n>r?-1:n<r?1:e.keypath<t.keypath?-1:e.keypath>t.keypath}var Typeson=function(){function Typeson(e){_classCallCheck(this,Typeson),this.options=e,this.plainObjectReplacers=[],this.nonplainObjectReplacers=[],this.revivers={},this.types={}}return _createClass(Typeson,[{key:"stringify",value:function stringify(e,t,n,r){r=_objectSpread2({},this.options,{},r,{stringification:!0});var o=this.encapsulate(e,null,r);return isArray(o)?JSON.stringify(o[0],t,n):o.then((function(e){return JSON.stringify(e,t,n)}))}},{key:"stringifySync",value:function stringifySync(e,t,n,r){return this.stringify(e,t,n,_objectSpread2({throwOnBadSyncType:!0},r,{sync:!0}))}},{key:"stringifyAsync",value:function stringifyAsync(e,t,n,r){return this.stringify(e,t,n,_objectSpread2({throwOnBadSyncType:!0},r,{sync:!1}))}},{key:"parse",value:function parse(e,t,n){return n=_objectSpread2({},this.options,{},n,{parse:!0}),this.revive(JSON.parse(e,t),n)}},{key:"parseSync",value:function parseSync(e,t,n){return this.parse(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!0}))}},{key:"parseAsync",value:function parseAsync(e,t,n){return this.parse(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!1}))}},{key:"specialTypeNames",value:function specialTypeNames(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.returnTypeNames=!0,this.encapsulate(e,t,n)}},{key:"rootTypeName",value:function rootTypeName(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.iterateNone=!0,this.encapsulate(e,t,n)}},{key:"encapsulate",value:function encapsulate(e,t,n){var r=(n=_objectSpread2({sync:!0},this.options,{},n)).sync,o=this,i={},s=[],a=[],c=[],u=!("cyclic"in n)||n.cyclic,y=n.encapsulateObserver,p=_encapsulate("",e,u,t||{},c);function finish(e){var t=Object.values(i);if(n.iterateNone)return t.length?t[0]:Typeson.getJSONType(e);if(t.length){if(n.returnTypeNames)return _toConsumableArray(new Set(t));e&&isPlainObject(e)&&!hasOwn$1.call(e,"$types")?e.$types=i:e={$:e,$types:{$:i}}}else isObject(e)&&hasOwn$1.call(e,"$types")&&(e={$:e,$types:!0});return!n.returnTypeNames&&e}function _adaptBuiltinStateObjectProperties(e,t,n){Object.assign(e,t);var r=internalStateObjPropsToIgnore.map((function(t){var n=e[t];return delete e[t],n}));n(),internalStateObjPropsToIgnore.forEach((function(t,n){e[t]=r[n]}))}function _encapsulate(e,t,r,c,u,p,l){var f,h={},v=_typeof(t),d=y?function(n){var o=l||c.type||Typeson.getJSONType(t);y(Object.assign(n||h,{keypath:e,value:t,cyclic:r,stateObj:c,promisesData:u,resolvingTypesonPromise:p,awaitingTypesonPromise:hasConstructorOf(t,TypesonPromise)},void 0!==o?{type:o}:{}))}:null;if(["string","boolean","number","undefined"].includes(v))return void 0===t||"number"===v&&(isNaN(t)||t===-1/0||t===1/0)?(f=replace(e,t,c,u,!1,p,d))!==t&&(h={replaced:f}):f=t,d&&d(),f;if(null===t)return d&&d(),t;if(r&&!c.iterateIn&&!c.iterateUnsetNumeric){var b=s.indexOf(t);if(!(b<0))return i[e]="#",d&&d({cyclicKeypath:a[b]}),"#"+a[b];!0===r&&(s.push(t),a.push(e))}var O,m=isPlainObject(t),T=isArray(t),P=(m||T)&&(!o.plainObjectReplacers.length||c.replaced)||c.iterateIn?t:replace(e,t,c,u,m||T,null,d);if(P!==t?(f=P,h={replaced:P}):T&&"object"!==c.iterateIn||"array"===c.iterateIn?(O=new Array(t.length),h={clone:O}):""===e&&hasConstructorOf(t,TypesonPromise)?(u.push([e,t,r,c,void 0,void 0,c.type]),f=t):(["function","symbol"].includes(_typeof(t))||"toJSON"in t||hasConstructorOf(t,TypesonPromise)||hasConstructorOf(t,Promise))&&!m&&"object"!==c.iterateIn?f=t:(O={},c.addLength&&(O.length=t.length),h={clone:O}),d&&d(),n.iterateNone)return O||f;if(!O)return f;if(c.iterateIn){var g=function _loop(n){var o={ownKeys:hasOwn$1.call(t,n)};_adaptBuiltinStateObjectProperties(c,o,(function(){var o=e+(e?".":"")+escapeKeyPathComponent(n),i=_encapsulate(o,t[n],Boolean(r),c,u,p);hasConstructorOf(i,TypesonPromise)?u.push([o,i,Boolean(r),c,O,n,c.type]):void 0!==i&&(O[n]=i)}))};for(var _ in t)g(_);d&&d({endIterateIn:!0,end:!0})}else keys(t).forEach((function(n){var o=e+(e?".":"")+escapeKeyPathComponent(n);_adaptBuiltinStateObjectProperties(c,{ownKeys:!0},(function(){var e=_encapsulate(o,t[n],Boolean(r),c,u,p);hasConstructorOf(e,TypesonPromise)?u.push([o,e,Boolean(r),c,O,n,c.type]):void 0!==e&&(O[n]=e)}))})),d&&d({endIterateOwn:!0,end:!0});if(c.iterateUnsetNumeric){for(var j=t.length,S=function _loop2(n){if(!(n in t)){var o=e+(e?".":"")+n;_adaptBuiltinStateObjectProperties(c,{ownKeys:!1},(function(){var e=_encapsulate(o,void 0,Boolean(r),c,u,p);hasConstructorOf(e,TypesonPromise)?u.push([o,e,Boolean(r),c,O,n,c.type]):void 0!==e&&(O[n]=e)}))}},w=0;w<j;w++)S(w);d&&d({endIterateUnsetNumeric:!0,end:!0})}return O}function replace(e,t,n,s,a,c,y){for(var p=a?o.plainObjectReplacers:o.nonplainObjectReplacers,l=p.length;l--;){var f=p[l];if(f.test(t,n)){var h=f.type;if(o.revivers[h]){var v=i[e];i[e]=v?[h].concat(v):h}return Object.assign(n,{type:h,replaced:!0}),!r&&f.replaceAsync||f.replace?(y&&y({replacing:!0}),_encapsulate(e,f[r||!f.replaceAsync?"replace":"replaceAsync"](t,n),u&&"readonly",n,s,c,h)):(y&&y({typeDetected:!0}),_encapsulate(e,t,u&&"readonly",n,s,c,h))}}return t}return c.length?r&&n.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():Promise.resolve(function checkPromises(e,t){var n;return regeneratorRuntime.async((function checkPromises$(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,regeneratorRuntime.awrap(Promise.all(t.map((function(e){return e[1].p}))));case 2:return n=r.sent,r.next=5,regeneratorRuntime.awrap(Promise.all(n.map((function _callee(n){var r,o,i,s,a,c,u,y,p,l,f,h,v,d;return regeneratorRuntime.async((function _callee$(b){for(;;)switch(b.prev=b.next){case 0:if(r=[],o=t.splice(0,1),i=_slicedToArray(o,1),s=i[0],a=_slicedToArray(s,7),c=a[0],u=a[2],y=a[3],p=a[4],l=a[5],f=a[6],h=_encapsulate(c,n,u,y,r,!0,f),v=hasConstructorOf(h,TypesonPromise),!c||!v){b.next=11;break}return b.next=8,regeneratorRuntime.awrap(h.p);case 8:return d=b.sent,p[l]=d,b.abrupt("return",checkPromises(e,r));case 11:return c?p[l]=h:e=v?h.p:h,b.abrupt("return",checkPromises(e,r));case 13:case"end":return b.stop()}}))}))));case 5:return r.abrupt("return",e);case 6:case"end":return r.stop()}}))}(p,c)).then(finish):!r&&n.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():n.stringification&&r?[finish(p)]:r?finish(p):Promise.resolve(finish(p))}},{key:"encapsulateSync",value:function encapsulateSync(e,t,n){return this.encapsulate(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!0}))}},{key:"encapsulateAsync",value:function encapsulateAsync(e,t,n){return this.encapsulate(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!1}))}},{key:"revive",value:function revive(e,t){var n=e&&e.$types;if(!n)return e;if(!0===n)return e.$;var r=(t=_objectSpread2({sync:!0},this.options,{},t)).sync,o=[],i={},s=!0;n.$&&isPlainObject(n.$)&&(e=e.$,n=n.$,s=!1);var a=this;function _revive(e,t,c,u,y){if(!s||"$types"!==e){var p=n[e];if(isArray(t)||isPlainObject(t)){var l=isArray(t)?new Array(t.length):{};for(keys(t).forEach((function(n){var r=_revive(e+(e?".":"")+escapeKeyPathComponent(n),t[n],c||l,l,n);hasConstructorOf(r,Undefined)?l[n]=void 0:void 0!==r&&(l[n]=r)})),t=l;o.length;){var f=_slicedToArray(o[0],4),h=f[0],v=f[1],d=f[2],b=f[3],O=getByKeyPath(h,v);if(hasConstructorOf(O,Undefined))d[b]=void 0;else{if(void 0===O)break;d[b]=O}o.splice(0,1)}}if(!p)return t;if("#"===p){var m=getByKeyPath(c,t.slice(1));return void 0===m&&o.push([c,t.slice(1),u,y]),m}return[].concat(p).reduce((function reducer(e,t){if(hasConstructorOf(e,TypesonPromise))return e.then((function(e){return reducer(e,t)}));var n=_slicedToArray(a.revivers[t],1)[0];if(!n)throw new Error("Unregistered type: "+t);return n[r&&n.revive?"revive":!r&&n.reviveAsync?"reviveAsync":"revive"](e,i)}),t)}}function checkUndefined(e){return hasConstructorOf(e,Undefined)?void 0:e}var c,u=function revivePlainObjects(){var t=[];if(Object.entries(n).forEach((function(e){var r=_slicedToArray(e,2),o=r[0],i=r[1];"#"!==i&&[].concat(i).forEach((function(e){_slicedToArray(a.revivers[e],2)[1].plain&&(t.push({keypath:o,type:e}),delete n[o])}))})),t.length)return t.sort(nestedPathsFirst).reduce((function reducer(t,n){var o=n.keypath,s=n.type;if(hasConstructorOf(t,TypesonPromise))return t.then((function(e){return reducer(e,s)}));var c=getByKeyPath(e,o);if(hasConstructorOf(c,TypesonPromise))return c.then((function(e){return reducer(e,s)}));var u=_slicedToArray(a.revivers[s],1)[0];if(!u)throw new Error("Unregistered type: "+s);void 0!==(c=u[r&&u.revive?"revive":!r&&u.reviveAsync?"reviveAsync":"revive"](c,i))&&(hasConstructorOf(c,Undefined)&&(c=void 0),setAtKeyPath(e,o,c)===c&&(e=c))}),void 0)}();return isThenable(c=hasConstructorOf(u,TypesonPromise)?u.then((function(){return _revive("",e,null)})):_revive("",e,null))?r&&t.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():hasConstructorOf(c,TypesonPromise)?c.p.then(checkUndefined):c:!r&&t.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():r?checkUndefined(c):Promise.resolve(checkUndefined(c))}},{key:"reviveSync",value:function reviveSync(e,t){return this.revive(e,_objectSpread2({throwOnBadSyncType:!0},t,{sync:!0}))}},{key:"reviveAsync",value:function reviveAsync(e,t){return this.revive(e,_objectSpread2({throwOnBadSyncType:!0},t,{sync:!1}))}},{key:"register",value:function register(e,t){return t=t||{},[].concat(e).forEach((function R(e){var n=this;if(isArray(e))return e.map((function(e){return R.call(n,e)}));e&&keys(e).forEach((function(n){if("#"===n)throw new TypeError("# cannot be used as a type name as it is reserved for cyclic objects");if(Typeson.JSON_TYPES.includes(n))throw new TypeError("Plain JSON object types are reserved as type names");var r=e[n],o=r.testPlainObjects?this.plainObjectReplacers:this.nonplainObjectReplacers,i=o.filter((function(e){return e.type===n}));if(i.length&&(o.splice(o.indexOf(i[0]),1),delete this.revivers[n],delete this.types[n]),r){if("function"==typeof r){var s=r;r={test:function test(e){return e&&e.constructor===s},replace:function replace(e){return _objectSpread2({},e)},revive:function revive(e){return Object.assign(Object.create(s.prototype),e)}}}else if(isArray(r)){var a=_slicedToArray(r,3);r={test:a[0],replace:a[1],revive:a[2]}}var c={type:n,test:r.test.bind(r)};r.replace&&(c.replace=r.replace.bind(r)),r.replaceAsync&&(c.replaceAsync=r.replaceAsync.bind(r));var u="number"==typeof t.fallback?t.fallback:t.fallback?0:1/0;if(r.testPlainObjects?this.plainObjectReplacers.splice(u,0,c):this.nonplainObjectReplacers.splice(u,0,c),r.revive||r.reviveAsync){var y={};r.revive&&(y.revive=r.revive.bind(r)),r.reviveAsync&&(y.reviveAsync=r.reviveAsync.bind(r)),this.revivers[n]=[y,{plain:r.testPlainObjects}]}this.types[n]=r}}),this)}),this),this}}]),Typeson}(),Undefined=function Undefined(){_classCallCheck(this,Undefined)};Undefined.__typeson__type__="TypesonUndefined",Typeson.Undefined=Undefined,Typeson.Promise=TypesonPromise,Typeson.isThenable=isThenable,Typeson.toStringTag=toStringTag,Typeson.hasConstructorOf=hasConstructorOf,Typeson.isObject=isObject,Typeson.isPlainObject=isPlainObject,Typeson.isUserObject=isUserObject,Typeson.escapeKeyPathComponent=escapeKeyPathComponent,Typeson.unescapeKeyPathComponent=unescapeKeyPathComponent,Typeson.getByKeyPath=getByKeyPath,Typeson.getJSONType=getJSONType,Typeson.JSON_TYPES=["null","boolean","number","string","array","object"],module.exports=Typeson;

@@ -168,2 +168,4 @@ function _typeof(obj) {

/* istanbul ignore else */
if (typeof Symbol !== 'undefined') {

@@ -952,3 +954,6 @@ // Ensure `isUserObject` will return `false` for `TypesonPromise`

};
} else if (isPlainObj || stateObj.iterateIn === 'object') {
} else if (keypath === '' && hasConstructorOf(value, TypesonPromise)) {
promisesData.push([keypath, value, cyclic, stateObj, undefined, undefined, stateObj.type]);
ret = value;
} else if (!['function', 'symbol'].includes(_typeof(value)) && !('toJSON' in value) && !hasConstructorOf(value, TypesonPromise) && !hasConstructorOf(value, Promise) || isPlainObj || stateObj.iterateIn === 'object') {
clone = {};

@@ -963,5 +968,2 @@

};
} else if (keypath === '' && hasConstructorOf(value, TypesonPromise)) {
promisesData.push([keypath, value, cyclic, stateObj, undefined, undefined, stateObj.type]);
ret = value;
} else {

@@ -968,0 +970,0 @@ ret = value; // Only clone vanilla objects and arrays

@@ -1,1 +0,1 @@

function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach((function(t){_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _slicedToArray(e,t){return function _arrayWithHoles(e){if(Array.isArray(e))return e}(e)||function _iterableToArrayLimit(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var n=[],r=!0,i=!1,a=void 0;try{for(var o,c=e[Symbol.iterator]();!(r=(o=c.next()).done)&&(n.push(o.value),!t||n.length!==t);r=!0);}catch(e){i=!0,a=e}finally{try{r||null==c.return||c.return()}finally{if(i)throw a}}return n}(e,t)||function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function _toConsumableArray(e){return function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var e=function TypesonPromise(e){_classCallCheck(this,TypesonPromise),this.p=new Promise(e)};e.__typeson__type__="TypesonPromise","undefined"!=typeof Symbol&&(e.prototype[Symbol.toStringTag]="TypesonPromise"),e.prototype.then=function(t,n){var r=this;return new e((function(e,i){r.p.then((function(n){e(t?t(n):n)})).catch((function(e){return n?n(e):Promise.reject(e)})).then(e,i)}))},e.prototype.catch=function(e){return this.then(null,e)},e.resolve=function(t){return new e((function(e){e(t)}))},e.reject=function(t){return new e((function(e,n){n(t)}))},["all","race"].forEach((function(t){e[t]=function(n){return new e((function(e,r){Promise[t](n.map((function(e){return e.p}))).then(e,r)}))}}));var t={}.toString,n={}.hasOwnProperty,r=Object.getPrototypeOf,i=n.toString;function isThenable(e,t){return isObject(e)&&"function"==typeof e.then&&(!t||"function"==typeof e.catch)}function toStringTag(e){return t.call(e).slice(8,-1)}function hasConstructorOf(e,t){if(!e||"object"!==_typeof(e))return!1;var a=r(e);if(!a)return!1;var o=n.call(a,"constructor")&&a.constructor;return"function"!=typeof o?null===t:t===o||(null!==t&&i.call(o)===i.call(t)||"function"==typeof t&&"string"==typeof o.__typeson__type__&&o.__typeson__type__===t.__typeson__type__)}function isPlainObject(e){return!(!e||"Object"!==toStringTag(e))&&(!r(e)||hasConstructorOf(e,Object))}function isObject(e){return e&&"object"===_typeof(e)}function escapeKeyPathComponent(e){return e.replace(/~/g,"~0").replace(/\./g,"~1")}function unescapeKeyPathComponent(e){return e.replace(/~1/g,".").replace(/~0/g,"~")}function getByKeyPath(e,t){if(""===t)return e;var n=t.indexOf(".");if(n>-1){var r=e[unescapeKeyPathComponent(t.slice(0,n))];return void 0===r?void 0:getByKeyPath(r,t.slice(n+1))}return e[unescapeKeyPathComponent(t)]}var a=Object.keys,o=Array.isArray,c={}.hasOwnProperty,s=["type","replaced","iterateIn","iterateUnsetNumeric"];function nestedPathsFirst(e,t){var n=e.keypath.match(/\./g),r=e.keypath.match(/\./g);return n&&(n=n.length),r&&(r=r.length),n>r?-1:n<r?1:e.keypath<t.keypath?-1:e.keypath>t.keypath}var u=function(){function Typeson(e){_classCallCheck(this,Typeson),this.options=e,this.plainObjectReplacers=[],this.nonplainObjectReplacers=[],this.revivers={},this.types={}}return function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}(Typeson,[{key:"stringify",value:function stringify(e,t,n,r){r=_objectSpread2({},this.options,{},r,{stringification:!0});var i=this.encapsulate(e,null,r);return o(i)?JSON.stringify(i[0],t,n):i.then((function(e){return JSON.stringify(e,t,n)}))}},{key:"stringifySync",value:function stringifySync(e,t,n,r){return this.stringify(e,t,n,_objectSpread2({throwOnBadSyncType:!0},r,{sync:!0}))}},{key:"stringifyAsync",value:function stringifyAsync(e,t,n,r){return this.stringify(e,t,n,_objectSpread2({throwOnBadSyncType:!0},r,{sync:!1}))}},{key:"parse",value:function parse(e,t,n){return n=_objectSpread2({},this.options,{},n,{parse:!0}),this.revive(JSON.parse(e,t),n)}},{key:"parseSync",value:function parseSync(e,t,n){return this.parse(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!0}))}},{key:"parseAsync",value:function parseAsync(e,t,n){return this.parse(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!1}))}},{key:"specialTypeNames",value:function specialTypeNames(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.returnTypeNames=!0,this.encapsulate(e,t,n)}},{key:"rootTypeName",value:function rootTypeName(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.iterateNone=!0,this.encapsulate(e,t,n)}},{key:"encapsulate",value:function encapsulate(t,n,r){var i=(r=_objectSpread2({sync:!0},this.options,{},r)).sync,u=this,p={},y=[],l=[],f=[],h=!("cyclic"in r)||r.cyclic,v=r.encapsulateObserver,d=_encapsulate("",t,h,n||{},f);function finish(e){var t=Object.values(p);if(r.iterateNone)return t.length?t[0]:Typeson.getJSONType(e);if(t.length){if(r.returnTypeNames)return _toConsumableArray(new Set(t));e&&isPlainObject(e)&&!c.call(e,"$types")?e.$types=p:e={$:e,$types:{$:p}}}else isObject(e)&&c.call(e,"$types")&&(e={$:e,$types:!0});return!r.returnTypeNames&&e}function _adaptBuiltinStateObjectProperties(e,t,n){Object.assign(e,t);var r=s.map((function(t){var n=e[t];return delete e[t],n}));n(),s.forEach((function(t,n){e[t]=r[n]}))}function _encapsulate(t,n,i,s,f,h,d){var b,O={},_=_typeof(n),g=v?function(r){var a=d||s.type||Typeson.getJSONType(n);v(Object.assign(r||O,{keypath:t,value:n,cyclic:i,stateObj:s,promisesData:f,resolvingTypesonPromise:h,awaitingTypesonPromise:hasConstructorOf(n,e)},void 0!==a?{type:a}:{}))}:null;if(["string","boolean","number","undefined"].includes(_))return void 0===n||"number"===_&&(isNaN(n)||n===-1/0||n===1/0)?(b=replace(t,n,s,f,!1,h,g))!==n&&(O={replaced:b}):b=n,g&&g(),b;if(null===n)return g&&g(),n;if(i&&!s.iterateIn&&!s.iterateUnsetNumeric){var m=y.indexOf(n);if(!(m<0))return p[t]="#",g&&g({cyclicKeypath:l[m]}),"#"+l[m];!0===i&&(y.push(n),l.push(t))}var j,P=isPlainObject(n),S=o(n),T=(P||S)&&(!u.plainObjectReplacers.length||s.replaced)||s.iterateIn?n:replace(t,n,s,f,P||S,null,g);if(T!==n?(b=T,O={replaced:T}):S&&"object"!==s.iterateIn||"array"===s.iterateIn?(j=new Array(n.length),O={clone:j}):P||"object"===s.iterateIn?(j={},s.addLength&&(j.length=n.length),O={clone:j}):""===t&&hasConstructorOf(n,e)?(f.push([t,n,i,s,void 0,void 0,s.type]),b=n):b=n,g&&g(),r.iterateNone)return j||b;if(!j)return b;if(s.iterateIn){var w=function _loop(r){var a={ownKeys:c.call(n,r)};_adaptBuiltinStateObjectProperties(s,a,(function(){var a=t+(t?".":"")+escapeKeyPathComponent(r),o=_encapsulate(a,n[r],Boolean(i),s,f,h);hasConstructorOf(o,e)?f.push([a,o,Boolean(i),s,j,r,s.type]):void 0!==o&&(j[r]=o)}))};for(var A in n)w(A);g&&g({endIterateIn:!0,end:!0})}else a(n).forEach((function(r){var a=t+(t?".":"")+escapeKeyPathComponent(r);_adaptBuiltinStateObjectProperties(s,{ownKeys:!0},(function(){var t=_encapsulate(a,n[r],Boolean(i),s,f,h);hasConstructorOf(t,e)?f.push([a,t,Boolean(i),s,j,r,s.type]):void 0!==t&&(j[r]=t)}))})),g&&g({endIterateOwn:!0,end:!0});if(s.iterateUnsetNumeric){for(var C=n.length,k=function _loop2(r){if(!(r in n)){var a=t+(t?".":"")+r;_adaptBuiltinStateObjectProperties(s,{ownKeys:!1},(function(){var t=_encapsulate(a,void 0,Boolean(i),s,f,h);hasConstructorOf(t,e)?f.push([a,t,Boolean(i),s,j,r,s.type]):void 0!==t&&(j[r]=t)}))}},B=0;B<C;B++)k(B);g&&g({endIterateUnsetNumeric:!0,end:!0})}return j}function replace(e,t,n,r,a,o,c){for(var s=a?u.plainObjectReplacers:u.nonplainObjectReplacers,y=s.length;y--;){var l=s[y];if(l.test(t,n)){var f=l.type;if(u.revivers[f]){var v=p[e];p[e]=v?[f].concat(v):f}return Object.assign(n,{type:f,replaced:!0}),!i&&l.replaceAsync||l.replace?(c&&c({replacing:!0}),_encapsulate(e,l[i||!l.replaceAsync?"replace":"replaceAsync"](t,n),h&&"readonly",n,r,o,f)):(c&&c({typeDetected:!0}),_encapsulate(e,t,h&&"readonly",n,r,o,f))}}return t}return f.length?i&&r.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():Promise.resolve(function checkPromises(t,n){var r;return regeneratorRuntime.async((function checkPromises$(i){for(;;)switch(i.prev=i.next){case 0:return i.next=2,regeneratorRuntime.awrap(Promise.all(n.map((function(e){return e[1].p}))));case 2:return r=i.sent,i.next=5,regeneratorRuntime.awrap(Promise.all(r.map((function _callee(r){var i,a,o,c,s,u,p,y,l,f,h,v,d,b;return regeneratorRuntime.async((function _callee$(O){for(;;)switch(O.prev=O.next){case 0:if(i=[],a=n.splice(0,1),o=_slicedToArray(a,1),c=o[0],s=_slicedToArray(c,7),u=s[0],p=s[2],y=s[3],l=s[4],f=s[5],h=s[6],v=_encapsulate(u,r,p,y,i,!0,h),d=hasConstructorOf(v,e),!u||!d){O.next=11;break}return O.next=8,regeneratorRuntime.awrap(v.p);case 8:return b=O.sent,l[f]=b,O.abrupt("return",checkPromises(t,i));case 11:return u?l[f]=v:t=d?v.p:v,O.abrupt("return",checkPromises(t,i));case 13:case"end":return O.stop()}}))}))));case 5:return i.abrupt("return",t);case 6:case"end":return i.stop()}}))}(d,f)).then(finish):!i&&r.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():r.stringification&&i?[finish(d)]:i?finish(d):Promise.resolve(finish(d))}},{key:"encapsulateSync",value:function encapsulateSync(e,t,n){return this.encapsulate(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!0}))}},{key:"encapsulateAsync",value:function encapsulateAsync(e,t,n){return this.encapsulate(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!1}))}},{key:"revive",value:function revive(t,n){var r=t&&t.$types;if(!r)return t;if(!0===r)return t.$;var i=(n=_objectSpread2({sync:!0},this.options,{},n)).sync,c=[],s={},u=!0;r.$&&isPlainObject(r.$)&&(t=t.$,r=r.$,u=!1);var y=this;function _revive(t,n,l,f,h){if(!u||"$types"!==t){var v=r[t];if(o(n)||isPlainObject(n)){var d=o(n)?new Array(n.length):{};for(a(n).forEach((function(e){var r=_revive(t+(t?".":"")+escapeKeyPathComponent(e),n[e],l||d,d,e);hasConstructorOf(r,p)?d[e]=void 0:void 0!==r&&(d[e]=r)})),n=d;c.length;){var b=_slicedToArray(c[0],4),O=b[0],_=b[1],g=b[2],m=b[3],j=getByKeyPath(O,_);if(hasConstructorOf(j,p))g[m]=void 0;else{if(void 0===j)break;g[m]=j}c.splice(0,1)}}if(!v)return n;if("#"===v){var P=getByKeyPath(l,n.slice(1));return void 0===P&&c.push([l,n.slice(1),f,h]),P}return[].concat(v).reduce((function reducer(t,n){if(hasConstructorOf(t,e))return t.then((function(e){return reducer(e,n)}));var r=_slicedToArray(y.revivers[n],1)[0];if(!r)throw new Error("Unregistered type: "+n);return r[i&&r.revive?"revive":!i&&r.reviveAsync?"reviveAsync":"revive"](t,s)}),n)}}function checkUndefined(e){return hasConstructorOf(e,p)?void 0:e}var l,f=function revivePlainObjects(){var n=[];if(Object.entries(r).forEach((function(e){var t=_slicedToArray(e,2),i=t[0],a=t[1];"#"!==a&&[].concat(a).forEach((function(e){_slicedToArray(y.revivers[e],2)[1].plain&&(n.push({keypath:i,type:e}),delete r[i])}))})),n.length)return n.sort(nestedPathsFirst).reduce((function reducer(n,r){var a=r.keypath,o=r.type;if(hasConstructorOf(n,e))return n.then((function(e){return reducer(e,o)}));var c=getByKeyPath(t,a);if(hasConstructorOf(c,e))return c.then((function(e){return reducer(e,o)}));var u=_slicedToArray(y.revivers[o],1)[0];if(!u)throw new Error("Unregistered type: "+o);void 0!==(c=u[i&&u.revive?"revive":!i&&u.reviveAsync?"reviveAsync":"revive"](c,s))&&(hasConstructorOf(c,p)&&(c=void 0),function setAtKeyPath(e,t,n){if(""===t)return n;var r=t.indexOf(".");return r>-1?setAtKeyPath(e[unescapeKeyPathComponent(t.slice(0,r))],t.slice(r+1),n):(e[unescapeKeyPathComponent(t)]=n,e)}(t,a,c)===c&&(t=c))}),void 0)}();return isThenable(l=hasConstructorOf(f,e)?f.then((function(){return _revive("",t,null)})):_revive("",t,null))?i&&n.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():hasConstructorOf(l,e)?l.p.then(checkUndefined):l:!i&&n.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():i?checkUndefined(l):Promise.resolve(checkUndefined(l))}},{key:"reviveSync",value:function reviveSync(e,t){return this.revive(e,_objectSpread2({throwOnBadSyncType:!0},t,{sync:!0}))}},{key:"reviveAsync",value:function reviveAsync(e,t){return this.revive(e,_objectSpread2({throwOnBadSyncType:!0},t,{sync:!1}))}},{key:"register",value:function register(e,t){return t=t||{},[].concat(e).forEach((function R(e){var n=this;if(o(e))return e.map((function(e){return R.call(n,e)}));e&&a(e).forEach((function(n){if("#"===n)throw new TypeError("# cannot be used as a type name as it is reserved for cyclic objects");if(Typeson.JSON_TYPES.includes(n))throw new TypeError("Plain JSON object types are reserved as type names");var r=e[n],i=r.testPlainObjects?this.plainObjectReplacers:this.nonplainObjectReplacers,a=i.filter((function(e){return e.type===n}));if(a.length&&(i.splice(i.indexOf(a[0]),1),delete this.revivers[n],delete this.types[n]),r){if("function"==typeof r){var c=r;r={test:function test(e){return e&&e.constructor===c},replace:function replace(e){return _objectSpread2({},e)},revive:function revive(e){return Object.assign(Object.create(c.prototype),e)}}}else if(o(r)){var s=_slicedToArray(r,3);r={test:s[0],replace:s[1],revive:s[2]}}var u={type:n,test:r.test.bind(r)};r.replace&&(u.replace=r.replace.bind(r)),r.replaceAsync&&(u.replaceAsync=r.replaceAsync.bind(r));var p="number"==typeof t.fallback?t.fallback:t.fallback?0:1/0;if(r.testPlainObjects?this.plainObjectReplacers.splice(p,0,u):this.nonplainObjectReplacers.splice(p,0,u),r.revive||r.reviveAsync){var y={};r.revive&&(y.revive=r.revive.bind(r)),r.reviveAsync&&(y.reviveAsync=r.reviveAsync.bind(r)),this.revivers[n]=[y,{plain:r.testPlainObjects}]}this.types[n]=r}}),this)}),this),this}}]),Typeson}(),p=function Undefined(){_classCallCheck(this,Undefined)};p.__typeson__type__="TypesonUndefined",u.Undefined=p,u.Promise=e,u.isThenable=isThenable,u.toStringTag=toStringTag,u.hasConstructorOf=hasConstructorOf,u.isObject=isObject,u.isPlainObject=isPlainObject,u.isUserObject=function isUserObject(e){if(!e||"Object"!==toStringTag(e))return!1;var t=r(e);return!t||(hasConstructorOf(e,Object)||isUserObject(t))},u.escapeKeyPathComponent=escapeKeyPathComponent,u.unescapeKeyPathComponent=unescapeKeyPathComponent,u.getByKeyPath=getByKeyPath,u.getJSONType=function getJSONType(e){return null===e?"null":Array.isArray(e)?"array":_typeof(e)},u.JSON_TYPES=["null","boolean","number","string","array","object"];export default u;
function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach((function(t){_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _slicedToArray(e,t){return function _arrayWithHoles(e){if(Array.isArray(e))return e}(e)||function _iterableToArrayLimit(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var n=[],r=!0,i=!1,a=void 0;try{for(var o,c=e[Symbol.iterator]();!(r=(o=c.next()).done)&&(n.push(o.value),!t||n.length!==t);r=!0);}catch(e){i=!0,a=e}finally{try{r||null==c.return||c.return()}finally{if(i)throw a}}return n}(e,t)||function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function _toConsumableArray(e){return function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var e=function TypesonPromise(e){_classCallCheck(this,TypesonPromise),this.p=new Promise(e)};e.__typeson__type__="TypesonPromise","undefined"!=typeof Symbol&&(e.prototype[Symbol.toStringTag]="TypesonPromise"),e.prototype.then=function(t,n){var r=this;return new e((function(e,i){r.p.then((function(n){e(t?t(n):n)})).catch((function(e){return n?n(e):Promise.reject(e)})).then(e,i)}))},e.prototype.catch=function(e){return this.then(null,e)},e.resolve=function(t){return new e((function(e){e(t)}))},e.reject=function(t){return new e((function(e,n){n(t)}))},["all","race"].forEach((function(t){e[t]=function(n){return new e((function(e,r){Promise[t](n.map((function(e){return e.p}))).then(e,r)}))}}));var t={}.toString,n={}.hasOwnProperty,r=Object.getPrototypeOf,i=n.toString;function isThenable(e,t){return isObject(e)&&"function"==typeof e.then&&(!t||"function"==typeof e.catch)}function toStringTag(e){return t.call(e).slice(8,-1)}function hasConstructorOf(e,t){if(!e||"object"!==_typeof(e))return!1;var a=r(e);if(!a)return!1;var o=n.call(a,"constructor")&&a.constructor;return"function"!=typeof o?null===t:t===o||(null!==t&&i.call(o)===i.call(t)||"function"==typeof t&&"string"==typeof o.__typeson__type__&&o.__typeson__type__===t.__typeson__type__)}function isPlainObject(e){return!(!e||"Object"!==toStringTag(e))&&(!r(e)||hasConstructorOf(e,Object))}function isObject(e){return e&&"object"===_typeof(e)}function escapeKeyPathComponent(e){return e.replace(/~/g,"~0").replace(/\./g,"~1")}function unescapeKeyPathComponent(e){return e.replace(/~1/g,".").replace(/~0/g,"~")}function getByKeyPath(e,t){if(""===t)return e;var n=t.indexOf(".");if(n>-1){var r=e[unescapeKeyPathComponent(t.slice(0,n))];return void 0===r?void 0:getByKeyPath(r,t.slice(n+1))}return e[unescapeKeyPathComponent(t)]}var a=Object.keys,o=Array.isArray,c={}.hasOwnProperty,s=["type","replaced","iterateIn","iterateUnsetNumeric"];function nestedPathsFirst(e,t){var n=e.keypath.match(/\./g),r=e.keypath.match(/\./g);return n&&(n=n.length),r&&(r=r.length),n>r?-1:n<r?1:e.keypath<t.keypath?-1:e.keypath>t.keypath}var u=function(){function Typeson(e){_classCallCheck(this,Typeson),this.options=e,this.plainObjectReplacers=[],this.nonplainObjectReplacers=[],this.revivers={},this.types={}}return function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}(Typeson,[{key:"stringify",value:function stringify(e,t,n,r){r=_objectSpread2({},this.options,{},r,{stringification:!0});var i=this.encapsulate(e,null,r);return o(i)?JSON.stringify(i[0],t,n):i.then((function(e){return JSON.stringify(e,t,n)}))}},{key:"stringifySync",value:function stringifySync(e,t,n,r){return this.stringify(e,t,n,_objectSpread2({throwOnBadSyncType:!0},r,{sync:!0}))}},{key:"stringifyAsync",value:function stringifyAsync(e,t,n,r){return this.stringify(e,t,n,_objectSpread2({throwOnBadSyncType:!0},r,{sync:!1}))}},{key:"parse",value:function parse(e,t,n){return n=_objectSpread2({},this.options,{},n,{parse:!0}),this.revive(JSON.parse(e,t),n)}},{key:"parseSync",value:function parseSync(e,t,n){return this.parse(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!0}))}},{key:"parseAsync",value:function parseAsync(e,t,n){return this.parse(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!1}))}},{key:"specialTypeNames",value:function specialTypeNames(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.returnTypeNames=!0,this.encapsulate(e,t,n)}},{key:"rootTypeName",value:function rootTypeName(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.iterateNone=!0,this.encapsulate(e,t,n)}},{key:"encapsulate",value:function encapsulate(t,n,r){var i=(r=_objectSpread2({sync:!0},this.options,{},r)).sync,u=this,p={},y=[],l=[],f=[],h=!("cyclic"in r)||r.cyclic,v=r.encapsulateObserver,d=_encapsulate("",t,h,n||{},f);function finish(e){var t=Object.values(p);if(r.iterateNone)return t.length?t[0]:Typeson.getJSONType(e);if(t.length){if(r.returnTypeNames)return _toConsumableArray(new Set(t));e&&isPlainObject(e)&&!c.call(e,"$types")?e.$types=p:e={$:e,$types:{$:p}}}else isObject(e)&&c.call(e,"$types")&&(e={$:e,$types:!0});return!r.returnTypeNames&&e}function _adaptBuiltinStateObjectProperties(e,t,n){Object.assign(e,t);var r=s.map((function(t){var n=e[t];return delete e[t],n}));n(),s.forEach((function(t,n){e[t]=r[n]}))}function _encapsulate(t,n,i,s,f,h,d){var b,O={},_=_typeof(n),g=v?function(r){var a=d||s.type||Typeson.getJSONType(n);v(Object.assign(r||O,{keypath:t,value:n,cyclic:i,stateObj:s,promisesData:f,resolvingTypesonPromise:h,awaitingTypesonPromise:hasConstructorOf(n,e)},void 0!==a?{type:a}:{}))}:null;if(["string","boolean","number","undefined"].includes(_))return void 0===n||"number"===_&&(isNaN(n)||n===-1/0||n===1/0)?(b=replace(t,n,s,f,!1,h,g))!==n&&(O={replaced:b}):b=n,g&&g(),b;if(null===n)return g&&g(),n;if(i&&!s.iterateIn&&!s.iterateUnsetNumeric){var m=y.indexOf(n);if(!(m<0))return p[t]="#",g&&g({cyclicKeypath:l[m]}),"#"+l[m];!0===i&&(y.push(n),l.push(t))}var j,P=isPlainObject(n),S=o(n),T=(P||S)&&(!u.plainObjectReplacers.length||s.replaced)||s.iterateIn?n:replace(t,n,s,f,P||S,null,g);if(T!==n?(b=T,O={replaced:T}):S&&"object"!==s.iterateIn||"array"===s.iterateIn?(j=new Array(n.length),O={clone:j}):""===t&&hasConstructorOf(n,e)?(f.push([t,n,i,s,void 0,void 0,s.type]),b=n):(["function","symbol"].includes(_typeof(n))||"toJSON"in n||hasConstructorOf(n,e)||hasConstructorOf(n,Promise))&&!P&&"object"!==s.iterateIn?b=n:(j={},s.addLength&&(j.length=n.length),O={clone:j}),g&&g(),r.iterateNone)return j||b;if(!j)return b;if(s.iterateIn){var w=function _loop(r){var a={ownKeys:c.call(n,r)};_adaptBuiltinStateObjectProperties(s,a,(function(){var a=t+(t?".":"")+escapeKeyPathComponent(r),o=_encapsulate(a,n[r],Boolean(i),s,f,h);hasConstructorOf(o,e)?f.push([a,o,Boolean(i),s,j,r,s.type]):void 0!==o&&(j[r]=o)}))};for(var A in n)w(A);g&&g({endIterateIn:!0,end:!0})}else a(n).forEach((function(r){var a=t+(t?".":"")+escapeKeyPathComponent(r);_adaptBuiltinStateObjectProperties(s,{ownKeys:!0},(function(){var t=_encapsulate(a,n[r],Boolean(i),s,f,h);hasConstructorOf(t,e)?f.push([a,t,Boolean(i),s,j,r,s.type]):void 0!==t&&(j[r]=t)}))})),g&&g({endIterateOwn:!0,end:!0});if(s.iterateUnsetNumeric){for(var C=n.length,k=function _loop2(r){if(!(r in n)){var a=t+(t?".":"")+r;_adaptBuiltinStateObjectProperties(s,{ownKeys:!1},(function(){var t=_encapsulate(a,void 0,Boolean(i),s,f,h);hasConstructorOf(t,e)?f.push([a,t,Boolean(i),s,j,r,s.type]):void 0!==t&&(j[r]=t)}))}},B=0;B<C;B++)k(B);g&&g({endIterateUnsetNumeric:!0,end:!0})}return j}function replace(e,t,n,r,a,o,c){for(var s=a?u.plainObjectReplacers:u.nonplainObjectReplacers,y=s.length;y--;){var l=s[y];if(l.test(t,n)){var f=l.type;if(u.revivers[f]){var v=p[e];p[e]=v?[f].concat(v):f}return Object.assign(n,{type:f,replaced:!0}),!i&&l.replaceAsync||l.replace?(c&&c({replacing:!0}),_encapsulate(e,l[i||!l.replaceAsync?"replace":"replaceAsync"](t,n),h&&"readonly",n,r,o,f)):(c&&c({typeDetected:!0}),_encapsulate(e,t,h&&"readonly",n,r,o,f))}}return t}return f.length?i&&r.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():Promise.resolve(function checkPromises(t,n){var r;return regeneratorRuntime.async((function checkPromises$(i){for(;;)switch(i.prev=i.next){case 0:return i.next=2,regeneratorRuntime.awrap(Promise.all(n.map((function(e){return e[1].p}))));case 2:return r=i.sent,i.next=5,regeneratorRuntime.awrap(Promise.all(r.map((function _callee(r){var i,a,o,c,s,u,p,y,l,f,h,v,d,b;return regeneratorRuntime.async((function _callee$(O){for(;;)switch(O.prev=O.next){case 0:if(i=[],a=n.splice(0,1),o=_slicedToArray(a,1),c=o[0],s=_slicedToArray(c,7),u=s[0],p=s[2],y=s[3],l=s[4],f=s[5],h=s[6],v=_encapsulate(u,r,p,y,i,!0,h),d=hasConstructorOf(v,e),!u||!d){O.next=11;break}return O.next=8,regeneratorRuntime.awrap(v.p);case 8:return b=O.sent,l[f]=b,O.abrupt("return",checkPromises(t,i));case 11:return u?l[f]=v:t=d?v.p:v,O.abrupt("return",checkPromises(t,i));case 13:case"end":return O.stop()}}))}))));case 5:return i.abrupt("return",t);case 6:case"end":return i.stop()}}))}(d,f)).then(finish):!i&&r.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():r.stringification&&i?[finish(d)]:i?finish(d):Promise.resolve(finish(d))}},{key:"encapsulateSync",value:function encapsulateSync(e,t,n){return this.encapsulate(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!0}))}},{key:"encapsulateAsync",value:function encapsulateAsync(e,t,n){return this.encapsulate(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!1}))}},{key:"revive",value:function revive(t,n){var r=t&&t.$types;if(!r)return t;if(!0===r)return t.$;var i=(n=_objectSpread2({sync:!0},this.options,{},n)).sync,c=[],s={},u=!0;r.$&&isPlainObject(r.$)&&(t=t.$,r=r.$,u=!1);var y=this;function _revive(t,n,l,f,h){if(!u||"$types"!==t){var v=r[t];if(o(n)||isPlainObject(n)){var d=o(n)?new Array(n.length):{};for(a(n).forEach((function(e){var r=_revive(t+(t?".":"")+escapeKeyPathComponent(e),n[e],l||d,d,e);hasConstructorOf(r,p)?d[e]=void 0:void 0!==r&&(d[e]=r)})),n=d;c.length;){var b=_slicedToArray(c[0],4),O=b[0],_=b[1],g=b[2],m=b[3],j=getByKeyPath(O,_);if(hasConstructorOf(j,p))g[m]=void 0;else{if(void 0===j)break;g[m]=j}c.splice(0,1)}}if(!v)return n;if("#"===v){var P=getByKeyPath(l,n.slice(1));return void 0===P&&c.push([l,n.slice(1),f,h]),P}return[].concat(v).reduce((function reducer(t,n){if(hasConstructorOf(t,e))return t.then((function(e){return reducer(e,n)}));var r=_slicedToArray(y.revivers[n],1)[0];if(!r)throw new Error("Unregistered type: "+n);return r[i&&r.revive?"revive":!i&&r.reviveAsync?"reviveAsync":"revive"](t,s)}),n)}}function checkUndefined(e){return hasConstructorOf(e,p)?void 0:e}var l,f=function revivePlainObjects(){var n=[];if(Object.entries(r).forEach((function(e){var t=_slicedToArray(e,2),i=t[0],a=t[1];"#"!==a&&[].concat(a).forEach((function(e){_slicedToArray(y.revivers[e],2)[1].plain&&(n.push({keypath:i,type:e}),delete r[i])}))})),n.length)return n.sort(nestedPathsFirst).reduce((function reducer(n,r){var a=r.keypath,o=r.type;if(hasConstructorOf(n,e))return n.then((function(e){return reducer(e,o)}));var c=getByKeyPath(t,a);if(hasConstructorOf(c,e))return c.then((function(e){return reducer(e,o)}));var u=_slicedToArray(y.revivers[o],1)[0];if(!u)throw new Error("Unregistered type: "+o);void 0!==(c=u[i&&u.revive?"revive":!i&&u.reviveAsync?"reviveAsync":"revive"](c,s))&&(hasConstructorOf(c,p)&&(c=void 0),function setAtKeyPath(e,t,n){if(""===t)return n;var r=t.indexOf(".");return r>-1?setAtKeyPath(e[unescapeKeyPathComponent(t.slice(0,r))],t.slice(r+1),n):(e[unescapeKeyPathComponent(t)]=n,e)}(t,a,c)===c&&(t=c))}),void 0)}();return isThenable(l=hasConstructorOf(f,e)?f.then((function(){return _revive("",t,null)})):_revive("",t,null))?i&&n.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():hasConstructorOf(l,e)?l.p.then(checkUndefined):l:!i&&n.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():i?checkUndefined(l):Promise.resolve(checkUndefined(l))}},{key:"reviveSync",value:function reviveSync(e,t){return this.revive(e,_objectSpread2({throwOnBadSyncType:!0},t,{sync:!0}))}},{key:"reviveAsync",value:function reviveAsync(e,t){return this.revive(e,_objectSpread2({throwOnBadSyncType:!0},t,{sync:!1}))}},{key:"register",value:function register(e,t){return t=t||{},[].concat(e).forEach((function R(e){var n=this;if(o(e))return e.map((function(e){return R.call(n,e)}));e&&a(e).forEach((function(n){if("#"===n)throw new TypeError("# cannot be used as a type name as it is reserved for cyclic objects");if(Typeson.JSON_TYPES.includes(n))throw new TypeError("Plain JSON object types are reserved as type names");var r=e[n],i=r.testPlainObjects?this.plainObjectReplacers:this.nonplainObjectReplacers,a=i.filter((function(e){return e.type===n}));if(a.length&&(i.splice(i.indexOf(a[0]),1),delete this.revivers[n],delete this.types[n]),r){if("function"==typeof r){var c=r;r={test:function test(e){return e&&e.constructor===c},replace:function replace(e){return _objectSpread2({},e)},revive:function revive(e){return Object.assign(Object.create(c.prototype),e)}}}else if(o(r)){var s=_slicedToArray(r,3);r={test:s[0],replace:s[1],revive:s[2]}}var u={type:n,test:r.test.bind(r)};r.replace&&(u.replace=r.replace.bind(r)),r.replaceAsync&&(u.replaceAsync=r.replaceAsync.bind(r));var p="number"==typeof t.fallback?t.fallback:t.fallback?0:1/0;if(r.testPlainObjects?this.plainObjectReplacers.splice(p,0,u):this.nonplainObjectReplacers.splice(p,0,u),r.revive||r.reviveAsync){var y={};r.revive&&(y.revive=r.revive.bind(r)),r.reviveAsync&&(y.reviveAsync=r.reviveAsync.bind(r)),this.revivers[n]=[y,{plain:r.testPlainObjects}]}this.types[n]=r}}),this)}),this),this}}]),Typeson}(),p=function Undefined(){_classCallCheck(this,Undefined)};p.__typeson__type__="TypesonUndefined",u.Undefined=p,u.Promise=e,u.isThenable=isThenable,u.toStringTag=toStringTag,u.hasConstructorOf=hasConstructorOf,u.isObject=isObject,u.isPlainObject=isPlainObject,u.isUserObject=function isUserObject(e){if(!e||"Object"!==toStringTag(e))return!1;var t=r(e);return!t||(hasConstructorOf(e,Object)||isUserObject(t))},u.escapeKeyPathComponent=escapeKeyPathComponent,u.unescapeKeyPathComponent=unescapeKeyPathComponent,u.getByKeyPath=getByKeyPath,u.getJSONType=function getJSONType(e){return null===e?"null":Array.isArray(e)?"array":_typeof(e)},u.JSON_TYPES=["null","boolean","number","string","array","object"];export default u;

@@ -174,2 +174,4 @@ (function (global, factory) {

/* istanbul ignore else */
if (typeof Symbol !== 'undefined') {

@@ -958,3 +960,6 @@ // Ensure `isUserObject` will return `false` for `TypesonPromise`

};
} else if (isPlainObj || stateObj.iterateIn === 'object') {
} else if (keypath === '' && hasConstructorOf(value, TypesonPromise)) {
promisesData.push([keypath, value, cyclic, stateObj, undefined, undefined, stateObj.type]);
ret = value;
} else if (!['function', 'symbol'].includes(_typeof(value)) && !('toJSON' in value) && !hasConstructorOf(value, TypesonPromise) && !hasConstructorOf(value, Promise) || isPlainObj || stateObj.iterateIn === 'object') {
clone = {};

@@ -969,5 +974,2 @@

};
} else if (keypath === '' && hasConstructorOf(value, TypesonPromise)) {
promisesData.push([keypath, value, cyclic, stateObj, undefined, undefined, stateObj.type]);
ret = value;
} else {

@@ -974,0 +976,0 @@ ret = value; // Only clone vanilla objects and arrays

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Typeson=t()}(this,(function(){"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach((function(t){_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _slicedToArray(e,t){return function _arrayWithHoles(e){if(Array.isArray(e))return e}(e)||function _iterableToArrayLimit(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var n=[],r=!0,i=!1,o=void 0;try{for(var a,c=e[Symbol.iterator]();!(r=(a=c.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==c.return||c.return()}finally{if(i)throw o}}return n}(e,t)||function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function _toConsumableArray(e){return function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var e=function TypesonPromise(e){_classCallCheck(this,TypesonPromise),this.p=new Promise(e)};e.__typeson__type__="TypesonPromise","undefined"!=typeof Symbol&&(e.prototype[Symbol.toStringTag]="TypesonPromise"),e.prototype.then=function(t,n){var r=this;return new e((function(e,i){r.p.then((function(n){e(t?t(n):n)})).catch((function(e){return n?n(e):Promise.reject(e)})).then(e,i)}))},e.prototype.catch=function(e){return this.then(null,e)},e.resolve=function(t){return new e((function(e){e(t)}))},e.reject=function(t){return new e((function(e,n){n(t)}))},["all","race"].forEach((function(t){e[t]=function(n){return new e((function(e,r){Promise[t](n.map((function(e){return e.p}))).then(e,r)}))}}));var t={}.toString,n={}.hasOwnProperty,r=Object.getPrototypeOf,i=n.toString;function isThenable(e,t){return isObject(e)&&"function"==typeof e.then&&(!t||"function"==typeof e.catch)}function toStringTag(e){return t.call(e).slice(8,-1)}function hasConstructorOf(e,t){if(!e||"object"!==_typeof(e))return!1;var o=r(e);if(!o)return!1;var a=n.call(o,"constructor")&&o.constructor;return"function"!=typeof a?null===t:t===a||(null!==t&&i.call(a)===i.call(t)||"function"==typeof t&&"string"==typeof a.__typeson__type__&&a.__typeson__type__===t.__typeson__type__)}function isPlainObject(e){return!(!e||"Object"!==toStringTag(e))&&(!r(e)||hasConstructorOf(e,Object))}function isObject(e){return e&&"object"===_typeof(e)}function escapeKeyPathComponent(e){return e.replace(/~/g,"~0").replace(/\./g,"~1")}function unescapeKeyPathComponent(e){return e.replace(/~1/g,".").replace(/~0/g,"~")}function getByKeyPath(e,t){if(""===t)return e;var n=t.indexOf(".");if(n>-1){var r=e[unescapeKeyPathComponent(t.slice(0,n))];return void 0===r?void 0:getByKeyPath(r,t.slice(n+1))}return e[unescapeKeyPathComponent(t)]}var o=Object.keys,a=Array.isArray,c={}.hasOwnProperty,s=["type","replaced","iterateIn","iterateUnsetNumeric"];function nestedPathsFirst(e,t){var n=e.keypath.match(/\./g),r=e.keypath.match(/\./g);return n&&(n=n.length),r&&(r=r.length),n>r?-1:n<r?1:e.keypath<t.keypath?-1:e.keypath>t.keypath}var u=function(){function Typeson(e){_classCallCheck(this,Typeson),this.options=e,this.plainObjectReplacers=[],this.nonplainObjectReplacers=[],this.revivers={},this.types={}}return function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}(Typeson,[{key:"stringify",value:function stringify(e,t,n,r){r=_objectSpread2({},this.options,{},r,{stringification:!0});var i=this.encapsulate(e,null,r);return a(i)?JSON.stringify(i[0],t,n):i.then((function(e){return JSON.stringify(e,t,n)}))}},{key:"stringifySync",value:function stringifySync(e,t,n,r){return this.stringify(e,t,n,_objectSpread2({throwOnBadSyncType:!0},r,{sync:!0}))}},{key:"stringifyAsync",value:function stringifyAsync(e,t,n,r){return this.stringify(e,t,n,_objectSpread2({throwOnBadSyncType:!0},r,{sync:!1}))}},{key:"parse",value:function parse(e,t,n){return n=_objectSpread2({},this.options,{},n,{parse:!0}),this.revive(JSON.parse(e,t),n)}},{key:"parseSync",value:function parseSync(e,t,n){return this.parse(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!0}))}},{key:"parseAsync",value:function parseAsync(e,t,n){return this.parse(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!1}))}},{key:"specialTypeNames",value:function specialTypeNames(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.returnTypeNames=!0,this.encapsulate(e,t,n)}},{key:"rootTypeName",value:function rootTypeName(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.iterateNone=!0,this.encapsulate(e,t,n)}},{key:"encapsulate",value:function encapsulate(t,n,r){var i=(r=_objectSpread2({sync:!0},this.options,{},r)).sync,u=this,p={},y=[],l=[],f=[],h=!("cyclic"in r)||r.cyclic,v=r.encapsulateObserver,d=_encapsulate("",t,h,n||{},f);function finish(e){var t=Object.values(p);if(r.iterateNone)return t.length?t[0]:Typeson.getJSONType(e);if(t.length){if(r.returnTypeNames)return _toConsumableArray(new Set(t));e&&isPlainObject(e)&&!c.call(e,"$types")?e.$types=p:e={$:e,$types:{$:p}}}else isObject(e)&&c.call(e,"$types")&&(e={$:e,$types:!0});return!r.returnTypeNames&&e}function _adaptBuiltinStateObjectProperties(e,t,n){Object.assign(e,t);var r=s.map((function(t){var n=e[t];return delete e[t],n}));n(),s.forEach((function(t,n){e[t]=r[n]}))}function _encapsulate(t,n,i,s,f,h,d){var b,O={},_=_typeof(n),g=v?function(r){var o=d||s.type||Typeson.getJSONType(n);v(Object.assign(r||O,{keypath:t,value:n,cyclic:i,stateObj:s,promisesData:f,resolvingTypesonPromise:h,awaitingTypesonPromise:hasConstructorOf(n,e)},void 0!==o?{type:o}:{}))}:null;if(["string","boolean","number","undefined"].includes(_))return void 0===n||"number"===_&&(isNaN(n)||n===-1/0||n===1/0)?(b=replace(t,n,s,f,!1,h,g))!==n&&(O={replaced:b}):b=n,g&&g(),b;if(null===n)return g&&g(),n;if(i&&!s.iterateIn&&!s.iterateUnsetNumeric){var m=y.indexOf(n);if(!(m<0))return p[t]="#",g&&g({cyclicKeypath:l[m]}),"#"+l[m];!0===i&&(y.push(n),l.push(t))}var j,P=isPlainObject(n),S=a(n),T=(P||S)&&(!u.plainObjectReplacers.length||s.replaced)||s.iterateIn?n:replace(t,n,s,f,P||S,null,g);if(T!==n?(b=T,O={replaced:T}):S&&"object"!==s.iterateIn||"array"===s.iterateIn?(j=new Array(n.length),O={clone:j}):P||"object"===s.iterateIn?(j={},s.addLength&&(j.length=n.length),O={clone:j}):""===t&&hasConstructorOf(n,e)?(f.push([t,n,i,s,void 0,void 0,s.type]),b=n):b=n,g&&g(),r.iterateNone)return j||b;if(!j)return b;if(s.iterateIn){var w=function _loop(r){var o={ownKeys:c.call(n,r)};_adaptBuiltinStateObjectProperties(s,o,(function(){var o=t+(t?".":"")+escapeKeyPathComponent(r),a=_encapsulate(o,n[r],Boolean(i),s,f,h);hasConstructorOf(a,e)?f.push([o,a,Boolean(i),s,j,r,s.type]):void 0!==a&&(j[r]=a)}))};for(var A in n)w(A);g&&g({endIterateIn:!0,end:!0})}else o(n).forEach((function(r){var o=t+(t?".":"")+escapeKeyPathComponent(r);_adaptBuiltinStateObjectProperties(s,{ownKeys:!0},(function(){var t=_encapsulate(o,n[r],Boolean(i),s,f,h);hasConstructorOf(t,e)?f.push([o,t,Boolean(i),s,j,r,s.type]):void 0!==t&&(j[r]=t)}))})),g&&g({endIterateOwn:!0,end:!0});if(s.iterateUnsetNumeric){for(var C=n.length,k=function _loop2(r){if(!(r in n)){var o=t+(t?".":"")+r;_adaptBuiltinStateObjectProperties(s,{ownKeys:!1},(function(){var t=_encapsulate(o,void 0,Boolean(i),s,f,h);hasConstructorOf(t,e)?f.push([o,t,Boolean(i),s,j,r,s.type]):void 0!==t&&(j[r]=t)}))}},B=0;B<C;B++)k(B);g&&g({endIterateUnsetNumeric:!0,end:!0})}return j}function replace(e,t,n,r,o,a,c){for(var s=o?u.plainObjectReplacers:u.nonplainObjectReplacers,y=s.length;y--;){var l=s[y];if(l.test(t,n)){var f=l.type;if(u.revivers[f]){var v=p[e];p[e]=v?[f].concat(v):f}return Object.assign(n,{type:f,replaced:!0}),!i&&l.replaceAsync||l.replace?(c&&c({replacing:!0}),_encapsulate(e,l[i||!l.replaceAsync?"replace":"replaceAsync"](t,n),h&&"readonly",n,r,a,f)):(c&&c({typeDetected:!0}),_encapsulate(e,t,h&&"readonly",n,r,a,f))}}return t}return f.length?i&&r.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():Promise.resolve(function checkPromises(t,n){var r;return regeneratorRuntime.async((function checkPromises$(i){for(;;)switch(i.prev=i.next){case 0:return i.next=2,regeneratorRuntime.awrap(Promise.all(n.map((function(e){return e[1].p}))));case 2:return r=i.sent,i.next=5,regeneratorRuntime.awrap(Promise.all(r.map((function _callee(r){var i,o,a,c,s,u,p,y,l,f,h,v,d,b;return regeneratorRuntime.async((function _callee$(O){for(;;)switch(O.prev=O.next){case 0:if(i=[],o=n.splice(0,1),a=_slicedToArray(o,1),c=a[0],s=_slicedToArray(c,7),u=s[0],p=s[2],y=s[3],l=s[4],f=s[5],h=s[6],v=_encapsulate(u,r,p,y,i,!0,h),d=hasConstructorOf(v,e),!u||!d){O.next=11;break}return O.next=8,regeneratorRuntime.awrap(v.p);case 8:return b=O.sent,l[f]=b,O.abrupt("return",checkPromises(t,i));case 11:return u?l[f]=v:t=d?v.p:v,O.abrupt("return",checkPromises(t,i));case 13:case"end":return O.stop()}}))}))));case 5:return i.abrupt("return",t);case 6:case"end":return i.stop()}}))}(d,f)).then(finish):!i&&r.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():r.stringification&&i?[finish(d)]:i?finish(d):Promise.resolve(finish(d))}},{key:"encapsulateSync",value:function encapsulateSync(e,t,n){return this.encapsulate(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!0}))}},{key:"encapsulateAsync",value:function encapsulateAsync(e,t,n){return this.encapsulate(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!1}))}},{key:"revive",value:function revive(t,n){var r=t&&t.$types;if(!r)return t;if(!0===r)return t.$;var i=(n=_objectSpread2({sync:!0},this.options,{},n)).sync,c=[],s={},u=!0;r.$&&isPlainObject(r.$)&&(t=t.$,r=r.$,u=!1);var y=this;function _revive(t,n,l,f,h){if(!u||"$types"!==t){var v=r[t];if(a(n)||isPlainObject(n)){var d=a(n)?new Array(n.length):{};for(o(n).forEach((function(e){var r=_revive(t+(t?".":"")+escapeKeyPathComponent(e),n[e],l||d,d,e);hasConstructorOf(r,p)?d[e]=void 0:void 0!==r&&(d[e]=r)})),n=d;c.length;){var b=_slicedToArray(c[0],4),O=b[0],_=b[1],g=b[2],m=b[3],j=getByKeyPath(O,_);if(hasConstructorOf(j,p))g[m]=void 0;else{if(void 0===j)break;g[m]=j}c.splice(0,1)}}if(!v)return n;if("#"===v){var P=getByKeyPath(l,n.slice(1));return void 0===P&&c.push([l,n.slice(1),f,h]),P}return[].concat(v).reduce((function reducer(t,n){if(hasConstructorOf(t,e))return t.then((function(e){return reducer(e,n)}));var r=_slicedToArray(y.revivers[n],1)[0];if(!r)throw new Error("Unregistered type: "+n);return r[i&&r.revive?"revive":!i&&r.reviveAsync?"reviveAsync":"revive"](t,s)}),n)}}function checkUndefined(e){return hasConstructorOf(e,p)?void 0:e}var l,f=function revivePlainObjects(){var n=[];if(Object.entries(r).forEach((function(e){var t=_slicedToArray(e,2),i=t[0],o=t[1];"#"!==o&&[].concat(o).forEach((function(e){_slicedToArray(y.revivers[e],2)[1].plain&&(n.push({keypath:i,type:e}),delete r[i])}))})),n.length)return n.sort(nestedPathsFirst).reduce((function reducer(n,r){var o=r.keypath,a=r.type;if(hasConstructorOf(n,e))return n.then((function(e){return reducer(e,a)}));var c=getByKeyPath(t,o);if(hasConstructorOf(c,e))return c.then((function(e){return reducer(e,a)}));var u=_slicedToArray(y.revivers[a],1)[0];if(!u)throw new Error("Unregistered type: "+a);void 0!==(c=u[i&&u.revive?"revive":!i&&u.reviveAsync?"reviveAsync":"revive"](c,s))&&(hasConstructorOf(c,p)&&(c=void 0),function setAtKeyPath(e,t,n){if(""===t)return n;var r=t.indexOf(".");return r>-1?setAtKeyPath(e[unescapeKeyPathComponent(t.slice(0,r))],t.slice(r+1),n):(e[unescapeKeyPathComponent(t)]=n,e)}(t,o,c)===c&&(t=c))}),void 0)}();return isThenable(l=hasConstructorOf(f,e)?f.then((function(){return _revive("",t,null)})):_revive("",t,null))?i&&n.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():hasConstructorOf(l,e)?l.p.then(checkUndefined):l:!i&&n.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():i?checkUndefined(l):Promise.resolve(checkUndefined(l))}},{key:"reviveSync",value:function reviveSync(e,t){return this.revive(e,_objectSpread2({throwOnBadSyncType:!0},t,{sync:!0}))}},{key:"reviveAsync",value:function reviveAsync(e,t){return this.revive(e,_objectSpread2({throwOnBadSyncType:!0},t,{sync:!1}))}},{key:"register",value:function register(e,t){return t=t||{},[].concat(e).forEach((function R(e){var n=this;if(a(e))return e.map((function(e){return R.call(n,e)}));e&&o(e).forEach((function(n){if("#"===n)throw new TypeError("# cannot be used as a type name as it is reserved for cyclic objects");if(Typeson.JSON_TYPES.includes(n))throw new TypeError("Plain JSON object types are reserved as type names");var r=e[n],i=r.testPlainObjects?this.plainObjectReplacers:this.nonplainObjectReplacers,o=i.filter((function(e){return e.type===n}));if(o.length&&(i.splice(i.indexOf(o[0]),1),delete this.revivers[n],delete this.types[n]),r){if("function"==typeof r){var c=r;r={test:function test(e){return e&&e.constructor===c},replace:function replace(e){return _objectSpread2({},e)},revive:function revive(e){return Object.assign(Object.create(c.prototype),e)}}}else if(a(r)){var s=_slicedToArray(r,3);r={test:s[0],replace:s[1],revive:s[2]}}var u={type:n,test:r.test.bind(r)};r.replace&&(u.replace=r.replace.bind(r)),r.replaceAsync&&(u.replaceAsync=r.replaceAsync.bind(r));var p="number"==typeof t.fallback?t.fallback:t.fallback?0:1/0;if(r.testPlainObjects?this.plainObjectReplacers.splice(p,0,u):this.nonplainObjectReplacers.splice(p,0,u),r.revive||r.reviveAsync){var y={};r.revive&&(y.revive=r.revive.bind(r)),r.reviveAsync&&(y.reviveAsync=r.reviveAsync.bind(r)),this.revivers[n]=[y,{plain:r.testPlainObjects}]}this.types[n]=r}}),this)}),this),this}}]),Typeson}(),p=function Undefined(){_classCallCheck(this,Undefined)};return p.__typeson__type__="TypesonUndefined",u.Undefined=p,u.Promise=e,u.isThenable=isThenable,u.toStringTag=toStringTag,u.hasConstructorOf=hasConstructorOf,u.isObject=isObject,u.isPlainObject=isPlainObject,u.isUserObject=function isUserObject(e){if(!e||"Object"!==toStringTag(e))return!1;var t=r(e);return!t||(hasConstructorOf(e,Object)||isUserObject(t))},u.escapeKeyPathComponent=escapeKeyPathComponent,u.unescapeKeyPathComponent=unescapeKeyPathComponent,u.getByKeyPath=getByKeyPath,u.getJSONType=function getJSONType(e){return null===e?"null":Array.isArray(e)?"array":_typeof(e)},u.JSON_TYPES=["null","boolean","number","string","array","object"],u}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Typeson=t()}(this,(function(){"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach((function(t){_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _slicedToArray(e,t){return function _arrayWithHoles(e){if(Array.isArray(e))return e}(e)||function _iterableToArrayLimit(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var n=[],r=!0,i=!1,o=void 0;try{for(var a,c=e[Symbol.iterator]();!(r=(a=c.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==c.return||c.return()}finally{if(i)throw o}}return n}(e,t)||function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function _toConsumableArray(e){return function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var e=function TypesonPromise(e){_classCallCheck(this,TypesonPromise),this.p=new Promise(e)};e.__typeson__type__="TypesonPromise","undefined"!=typeof Symbol&&(e.prototype[Symbol.toStringTag]="TypesonPromise"),e.prototype.then=function(t,n){var r=this;return new e((function(e,i){r.p.then((function(n){e(t?t(n):n)})).catch((function(e){return n?n(e):Promise.reject(e)})).then(e,i)}))},e.prototype.catch=function(e){return this.then(null,e)},e.resolve=function(t){return new e((function(e){e(t)}))},e.reject=function(t){return new e((function(e,n){n(t)}))},["all","race"].forEach((function(t){e[t]=function(n){return new e((function(e,r){Promise[t](n.map((function(e){return e.p}))).then(e,r)}))}}));var t={}.toString,n={}.hasOwnProperty,r=Object.getPrototypeOf,i=n.toString;function isThenable(e,t){return isObject(e)&&"function"==typeof e.then&&(!t||"function"==typeof e.catch)}function toStringTag(e){return t.call(e).slice(8,-1)}function hasConstructorOf(e,t){if(!e||"object"!==_typeof(e))return!1;var o=r(e);if(!o)return!1;var a=n.call(o,"constructor")&&o.constructor;return"function"!=typeof a?null===t:t===a||(null!==t&&i.call(a)===i.call(t)||"function"==typeof t&&"string"==typeof a.__typeson__type__&&a.__typeson__type__===t.__typeson__type__)}function isPlainObject(e){return!(!e||"Object"!==toStringTag(e))&&(!r(e)||hasConstructorOf(e,Object))}function isObject(e){return e&&"object"===_typeof(e)}function escapeKeyPathComponent(e){return e.replace(/~/g,"~0").replace(/\./g,"~1")}function unescapeKeyPathComponent(e){return e.replace(/~1/g,".").replace(/~0/g,"~")}function getByKeyPath(e,t){if(""===t)return e;var n=t.indexOf(".");if(n>-1){var r=e[unescapeKeyPathComponent(t.slice(0,n))];return void 0===r?void 0:getByKeyPath(r,t.slice(n+1))}return e[unescapeKeyPathComponent(t)]}var o=Object.keys,a=Array.isArray,c={}.hasOwnProperty,s=["type","replaced","iterateIn","iterateUnsetNumeric"];function nestedPathsFirst(e,t){var n=e.keypath.match(/\./g),r=e.keypath.match(/\./g);return n&&(n=n.length),r&&(r=r.length),n>r?-1:n<r?1:e.keypath<t.keypath?-1:e.keypath>t.keypath}var u=function(){function Typeson(e){_classCallCheck(this,Typeson),this.options=e,this.plainObjectReplacers=[],this.nonplainObjectReplacers=[],this.revivers={},this.types={}}return function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}(Typeson,[{key:"stringify",value:function stringify(e,t,n,r){r=_objectSpread2({},this.options,{},r,{stringification:!0});var i=this.encapsulate(e,null,r);return a(i)?JSON.stringify(i[0],t,n):i.then((function(e){return JSON.stringify(e,t,n)}))}},{key:"stringifySync",value:function stringifySync(e,t,n,r){return this.stringify(e,t,n,_objectSpread2({throwOnBadSyncType:!0},r,{sync:!0}))}},{key:"stringifyAsync",value:function stringifyAsync(e,t,n,r){return this.stringify(e,t,n,_objectSpread2({throwOnBadSyncType:!0},r,{sync:!1}))}},{key:"parse",value:function parse(e,t,n){return n=_objectSpread2({},this.options,{},n,{parse:!0}),this.revive(JSON.parse(e,t),n)}},{key:"parseSync",value:function parseSync(e,t,n){return this.parse(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!0}))}},{key:"parseAsync",value:function parseAsync(e,t,n){return this.parse(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!1}))}},{key:"specialTypeNames",value:function specialTypeNames(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.returnTypeNames=!0,this.encapsulate(e,t,n)}},{key:"rootTypeName",value:function rootTypeName(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.iterateNone=!0,this.encapsulate(e,t,n)}},{key:"encapsulate",value:function encapsulate(t,n,r){var i=(r=_objectSpread2({sync:!0},this.options,{},r)).sync,u=this,p={},y=[],l=[],f=[],h=!("cyclic"in r)||r.cyclic,v=r.encapsulateObserver,d=_encapsulate("",t,h,n||{},f);function finish(e){var t=Object.values(p);if(r.iterateNone)return t.length?t[0]:Typeson.getJSONType(e);if(t.length){if(r.returnTypeNames)return _toConsumableArray(new Set(t));e&&isPlainObject(e)&&!c.call(e,"$types")?e.$types=p:e={$:e,$types:{$:p}}}else isObject(e)&&c.call(e,"$types")&&(e={$:e,$types:!0});return!r.returnTypeNames&&e}function _adaptBuiltinStateObjectProperties(e,t,n){Object.assign(e,t);var r=s.map((function(t){var n=e[t];return delete e[t],n}));n(),s.forEach((function(t,n){e[t]=r[n]}))}function _encapsulate(t,n,i,s,f,h,d){var b,O={},_=_typeof(n),g=v?function(r){var o=d||s.type||Typeson.getJSONType(n);v(Object.assign(r||O,{keypath:t,value:n,cyclic:i,stateObj:s,promisesData:f,resolvingTypesonPromise:h,awaitingTypesonPromise:hasConstructorOf(n,e)},void 0!==o?{type:o}:{}))}:null;if(["string","boolean","number","undefined"].includes(_))return void 0===n||"number"===_&&(isNaN(n)||n===-1/0||n===1/0)?(b=replace(t,n,s,f,!1,h,g))!==n&&(O={replaced:b}):b=n,g&&g(),b;if(null===n)return g&&g(),n;if(i&&!s.iterateIn&&!s.iterateUnsetNumeric){var m=y.indexOf(n);if(!(m<0))return p[t]="#",g&&g({cyclicKeypath:l[m]}),"#"+l[m];!0===i&&(y.push(n),l.push(t))}var j,P=isPlainObject(n),S=a(n),T=(P||S)&&(!u.plainObjectReplacers.length||s.replaced)||s.iterateIn?n:replace(t,n,s,f,P||S,null,g);if(T!==n?(b=T,O={replaced:T}):S&&"object"!==s.iterateIn||"array"===s.iterateIn?(j=new Array(n.length),O={clone:j}):""===t&&hasConstructorOf(n,e)?(f.push([t,n,i,s,void 0,void 0,s.type]),b=n):(["function","symbol"].includes(_typeof(n))||"toJSON"in n||hasConstructorOf(n,e)||hasConstructorOf(n,Promise))&&!P&&"object"!==s.iterateIn?b=n:(j={},s.addLength&&(j.length=n.length),O={clone:j}),g&&g(),r.iterateNone)return j||b;if(!j)return b;if(s.iterateIn){var w=function _loop(r){var o={ownKeys:c.call(n,r)};_adaptBuiltinStateObjectProperties(s,o,(function(){var o=t+(t?".":"")+escapeKeyPathComponent(r),a=_encapsulate(o,n[r],Boolean(i),s,f,h);hasConstructorOf(a,e)?f.push([o,a,Boolean(i),s,j,r,s.type]):void 0!==a&&(j[r]=a)}))};for(var A in n)w(A);g&&g({endIterateIn:!0,end:!0})}else o(n).forEach((function(r){var o=t+(t?".":"")+escapeKeyPathComponent(r);_adaptBuiltinStateObjectProperties(s,{ownKeys:!0},(function(){var t=_encapsulate(o,n[r],Boolean(i),s,f,h);hasConstructorOf(t,e)?f.push([o,t,Boolean(i),s,j,r,s.type]):void 0!==t&&(j[r]=t)}))})),g&&g({endIterateOwn:!0,end:!0});if(s.iterateUnsetNumeric){for(var C=n.length,k=function _loop2(r){if(!(r in n)){var o=t+(t?".":"")+r;_adaptBuiltinStateObjectProperties(s,{ownKeys:!1},(function(){var t=_encapsulate(o,void 0,Boolean(i),s,f,h);hasConstructorOf(t,e)?f.push([o,t,Boolean(i),s,j,r,s.type]):void 0!==t&&(j[r]=t)}))}},B=0;B<C;B++)k(B);g&&g({endIterateUnsetNumeric:!0,end:!0})}return j}function replace(e,t,n,r,o,a,c){for(var s=o?u.plainObjectReplacers:u.nonplainObjectReplacers,y=s.length;y--;){var l=s[y];if(l.test(t,n)){var f=l.type;if(u.revivers[f]){var v=p[e];p[e]=v?[f].concat(v):f}return Object.assign(n,{type:f,replaced:!0}),!i&&l.replaceAsync||l.replace?(c&&c({replacing:!0}),_encapsulate(e,l[i||!l.replaceAsync?"replace":"replaceAsync"](t,n),h&&"readonly",n,r,a,f)):(c&&c({typeDetected:!0}),_encapsulate(e,t,h&&"readonly",n,r,a,f))}}return t}return f.length?i&&r.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():Promise.resolve(function checkPromises(t,n){var r;return regeneratorRuntime.async((function checkPromises$(i){for(;;)switch(i.prev=i.next){case 0:return i.next=2,regeneratorRuntime.awrap(Promise.all(n.map((function(e){return e[1].p}))));case 2:return r=i.sent,i.next=5,regeneratorRuntime.awrap(Promise.all(r.map((function _callee(r){var i,o,a,c,s,u,p,y,l,f,h,v,d,b;return regeneratorRuntime.async((function _callee$(O){for(;;)switch(O.prev=O.next){case 0:if(i=[],o=n.splice(0,1),a=_slicedToArray(o,1),c=a[0],s=_slicedToArray(c,7),u=s[0],p=s[2],y=s[3],l=s[4],f=s[5],h=s[6],v=_encapsulate(u,r,p,y,i,!0,h),d=hasConstructorOf(v,e),!u||!d){O.next=11;break}return O.next=8,regeneratorRuntime.awrap(v.p);case 8:return b=O.sent,l[f]=b,O.abrupt("return",checkPromises(t,i));case 11:return u?l[f]=v:t=d?v.p:v,O.abrupt("return",checkPromises(t,i));case 13:case"end":return O.stop()}}))}))));case 5:return i.abrupt("return",t);case 6:case"end":return i.stop()}}))}(d,f)).then(finish):!i&&r.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():r.stringification&&i?[finish(d)]:i?finish(d):Promise.resolve(finish(d))}},{key:"encapsulateSync",value:function encapsulateSync(e,t,n){return this.encapsulate(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!0}))}},{key:"encapsulateAsync",value:function encapsulateAsync(e,t,n){return this.encapsulate(e,t,_objectSpread2({throwOnBadSyncType:!0},n,{sync:!1}))}},{key:"revive",value:function revive(t,n){var r=t&&t.$types;if(!r)return t;if(!0===r)return t.$;var i=(n=_objectSpread2({sync:!0},this.options,{},n)).sync,c=[],s={},u=!0;r.$&&isPlainObject(r.$)&&(t=t.$,r=r.$,u=!1);var y=this;function _revive(t,n,l,f,h){if(!u||"$types"!==t){var v=r[t];if(a(n)||isPlainObject(n)){var d=a(n)?new Array(n.length):{};for(o(n).forEach((function(e){var r=_revive(t+(t?".":"")+escapeKeyPathComponent(e),n[e],l||d,d,e);hasConstructorOf(r,p)?d[e]=void 0:void 0!==r&&(d[e]=r)})),n=d;c.length;){var b=_slicedToArray(c[0],4),O=b[0],_=b[1],g=b[2],m=b[3],j=getByKeyPath(O,_);if(hasConstructorOf(j,p))g[m]=void 0;else{if(void 0===j)break;g[m]=j}c.splice(0,1)}}if(!v)return n;if("#"===v){var P=getByKeyPath(l,n.slice(1));return void 0===P&&c.push([l,n.slice(1),f,h]),P}return[].concat(v).reduce((function reducer(t,n){if(hasConstructorOf(t,e))return t.then((function(e){return reducer(e,n)}));var r=_slicedToArray(y.revivers[n],1)[0];if(!r)throw new Error("Unregistered type: "+n);return r[i&&r.revive?"revive":!i&&r.reviveAsync?"reviveAsync":"revive"](t,s)}),n)}}function checkUndefined(e){return hasConstructorOf(e,p)?void 0:e}var l,f=function revivePlainObjects(){var n=[];if(Object.entries(r).forEach((function(e){var t=_slicedToArray(e,2),i=t[0],o=t[1];"#"!==o&&[].concat(o).forEach((function(e){_slicedToArray(y.revivers[e],2)[1].plain&&(n.push({keypath:i,type:e}),delete r[i])}))})),n.length)return n.sort(nestedPathsFirst).reduce((function reducer(n,r){var o=r.keypath,a=r.type;if(hasConstructorOf(n,e))return n.then((function(e){return reducer(e,a)}));var c=getByKeyPath(t,o);if(hasConstructorOf(c,e))return c.then((function(e){return reducer(e,a)}));var u=_slicedToArray(y.revivers[a],1)[0];if(!u)throw new Error("Unregistered type: "+a);void 0!==(c=u[i&&u.revive?"revive":!i&&u.reviveAsync?"reviveAsync":"revive"](c,s))&&(hasConstructorOf(c,p)&&(c=void 0),function setAtKeyPath(e,t,n){if(""===t)return n;var r=t.indexOf(".");return r>-1?setAtKeyPath(e[unescapeKeyPathComponent(t.slice(0,r))],t.slice(r+1),n):(e[unescapeKeyPathComponent(t)]=n,e)}(t,o,c)===c&&(t=c))}),void 0)}();return isThenable(l=hasConstructorOf(f,e)?f.then((function(){return _revive("",t,null)})):_revive("",t,null))?i&&n.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():hasConstructorOf(l,e)?l.p.then(checkUndefined):l:!i&&n.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():i?checkUndefined(l):Promise.resolve(checkUndefined(l))}},{key:"reviveSync",value:function reviveSync(e,t){return this.revive(e,_objectSpread2({throwOnBadSyncType:!0},t,{sync:!0}))}},{key:"reviveAsync",value:function reviveAsync(e,t){return this.revive(e,_objectSpread2({throwOnBadSyncType:!0},t,{sync:!1}))}},{key:"register",value:function register(e,t){return t=t||{},[].concat(e).forEach((function R(e){var n=this;if(a(e))return e.map((function(e){return R.call(n,e)}));e&&o(e).forEach((function(n){if("#"===n)throw new TypeError("# cannot be used as a type name as it is reserved for cyclic objects");if(Typeson.JSON_TYPES.includes(n))throw new TypeError("Plain JSON object types are reserved as type names");var r=e[n],i=r.testPlainObjects?this.plainObjectReplacers:this.nonplainObjectReplacers,o=i.filter((function(e){return e.type===n}));if(o.length&&(i.splice(i.indexOf(o[0]),1),delete this.revivers[n],delete this.types[n]),r){if("function"==typeof r){var c=r;r={test:function test(e){return e&&e.constructor===c},replace:function replace(e){return _objectSpread2({},e)},revive:function revive(e){return Object.assign(Object.create(c.prototype),e)}}}else if(a(r)){var s=_slicedToArray(r,3);r={test:s[0],replace:s[1],revive:s[2]}}var u={type:n,test:r.test.bind(r)};r.replace&&(u.replace=r.replace.bind(r)),r.replaceAsync&&(u.replaceAsync=r.replaceAsync.bind(r));var p="number"==typeof t.fallback?t.fallback:t.fallback?0:1/0;if(r.testPlainObjects?this.plainObjectReplacers.splice(p,0,u):this.nonplainObjectReplacers.splice(p,0,u),r.revive||r.reviveAsync){var y={};r.revive&&(y.revive=r.revive.bind(r)),r.reviveAsync&&(y.reviveAsync=r.reviveAsync.bind(r)),this.revivers[n]=[y,{plain:r.testPlainObjects}]}this.types[n]=r}}),this)}),this),this}}]),Typeson}(),p=function Undefined(){_classCallCheck(this,Undefined)};return p.__typeson__type__="TypesonUndefined",u.Undefined=p,u.Promise=e,u.isThenable=isThenable,u.toStringTag=toStringTag,u.hasConstructorOf=hasConstructorOf,u.isObject=isObject,u.isPlainObject=isPlainObject,u.isUserObject=function isUserObject(e){if(!e||"Object"!==toStringTag(e))return!1;var t=r(e);return!t||(hasConstructorOf(e,Object)||isUserObject(t))},u.escapeKeyPathComponent=escapeKeyPathComponent,u.unescapeKeyPathComponent=unescapeKeyPathComponent,u.getByKeyPath=getByKeyPath,u.getJSONType=function getJSONType(e){return null===e?"null":Array.isArray(e)?"array":_typeof(e)},u.JSON_TYPES=["null","boolean","number","string","array","object"],u}));
{
"name": "typeson",
"version": "5.14.1",
"version": "5.15.0",
"description": "Preserves types over JSON, BSON or socket.io",

@@ -21,3 +21,6 @@ "main": "./dist/typeson-commonjs2.min.js",

"nyc": {
"exclude": ["instrumented/**", "test/**"]
"exclude": [
"instrumented/**",
"test/**"
]
},

@@ -24,0 +27,0 @@ "repository": {

@@ -453,2 +453,3 @@ /* eslint-disable node/no-unsupported-features/es-syntax, no-shadow */

);
let clone;

@@ -465,8 +466,2 @@ if (replaced !== value) {

observerData = {clone};
} else if (isPlainObj || stateObj.iterateIn === 'object') {
clone = {};
if (stateObj.addLength) {
clone.length = value.length;
}
observerData = {clone};
} else if (keypath === '' &&

@@ -480,2 +475,17 @@ hasConstructorOf(value, TypesonPromise)

ret = value;
} else if (
(
!['function', 'symbol'].includes(typeof value) &&
!('toJSON' in value) &&
!hasConstructorOf(value, TypesonPromise) &&
!hasConstructorOf(value, Promise)
) ||
isPlainObj ||
stateObj.iterateIn === 'object'
) {
clone = {};
if (stateObj.addLength) {
clone.length = value.length;
}
observerData = {clone};
} else {

@@ -482,0 +492,0 @@ ret = value; // Only clone vanilla objects and arrays

@@ -18,2 +18,3 @@ /**

// Note: core-js-bundle provides a `Symbol` polyfill
/* istanbul ignore else */
if (typeof Symbol !== 'undefined') {

@@ -20,0 +21,0 @@ // Ensure `isUserObject` will return `false` for `TypesonPromise`

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc