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.7.1 to 5.8.0

8

CHANGES.md
# typeson
## 5.8.0
- Enhancement: Except for `type` and `replaced` states, preserve state
object keys (including user-supplied ones) within replacers; add tests
- Enhancement: Pass a state object as the second argument to revivers;
add tests
- npm: Update devDeps
## 5.7.1

@@ -4,0 +12,0 @@

2

dist/typeson-commonjs2.js

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

"use strict";function isThenable(e,n){return Typeson.isObject(e)&&"function"==typeof e.then&&(!n||"function"==typeof e.catch)}function toStringTag(e){return toString.call(e).slice(8,-1)}function hasConstructorOf(e,n){if(!e||"object"!==(void 0===e?"undefined":_typeof(e)))return!1;var t=getProto(e);if(!t)return!1;var r=hasOwn.call(t,"constructor")&&t.constructor;return"function"!=typeof r?null===n:"function"==typeof r&&null!==n&&fnToString.call(r)===fnToString.call(n)}function isPlainObject(e){if(!e||"Object"!==toStringTag(e))return!1;return!getProto(e)||hasConstructorOf(e,Object)}function isUserObject(e){if(!e||"Object"!==toStringTag(e))return!1;var n=getProto(e);return!n||(hasConstructorOf(e,Object)||isUserObject(n))}function isObject(e){return e&&"object"===(void 0===e?"undefined":_typeof(e))}function Typeson(e){var n=[],t=[],r={},i=this.types={},o=this.stringify=function(n,t,r,i){i=Object.assign({},e,i,{stringification:!0});var o=c(n,null,i);return isArray(o)?JSON.stringify(o[0],t,r):o.then(function(e){return JSON.stringify(e,t,r)})};this.stringifySync=function(e,n,t,r){return o(e,n,t,Object.assign({},{throwOnBadSyncType:!0},r,{sync:!0}))},this.stringifyAsync=function(e,n,t,r){return o(e,n,t,Object.assign({},{throwOnBadSyncType:!0},r,{sync:!1}))};var s=this.parse=function(n,t,r){return r=Object.assign({},e,r,{parse:!0}),a(JSON.parse(n,t),r)};this.parseSync=function(e,n,t){return s(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!0}))},this.parseAsync=function(e,n,t){return s(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!1}))},this.specialTypeNames=function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.returnTypeNames=!0,this.encapsulate(e,n,t)},this.rootTypeName=function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.iterateNone=!0,this.encapsulate(e,n,t)};var c=this.encapsulate=function(i,o,s){function finish(e){var n=Object.values(a);if(s.iterateNone)return n.length?n[0]:Typeson.getJSONType(e);if(n.length){if(s.returnTypeNames)return[].concat(toConsumableArray(new Set(n)));e&&isPlainObject(e)&&!e.hasOwnProperty("$types")?e.$types=a:e={$:e,$types:{$:a}}}else isObject(e)&&e.hasOwnProperty("$types")&&(e={$:e,$types:!0});return!s.returnTypeNames&&e}function checkPromises(e,n){return Promise.all(n.map(function(e){return e[1].p})).then(function(t){return Promise.all(t.map(function(t){var r=[],i=n.splice(0,1)[0],o=slicedToArray(i,7),s=o[0],c=o[2],a=o[3],u=o[4],y=o[5],p=o[6],f=_encapsulate(s,t,c,a,r,!0,p),l=hasConstructorOf(f,TypesonPromise);return s&&l?f.p.then(function(n){return u[y]=n,checkPromises(e,r)}):(s?u[y]=f:e=l?f.p:f,checkPromises(e,r))}))}).then(function(){return e})}function _encapsulate(e,t,r,i,o,c,p){var f=void 0,h={},v=void 0===t?"undefined":_typeof(t),d=l?function(n){var s=p||i.type||Typeson.getJSONType(t);l(Object.assign(n||h,{keypath:e,value:t,cyclic:r,stateObj:i,promisesData:o,resolvingTypesonPromise:c,awaitingTypesonPromise:hasConstructorOf(t,TypesonPromise)},void 0!==s?{type:s}:{}))}:null;if(v in{string:1,boolean:1,number:1,undefined:1})return void 0===t||"number"===v&&(isNaN(t)||t===-1/0||t===1/0)?(f=replace(e,t,i,o,!1,c,d))!==t&&(h={replaced:f}):f=t,d&&d(),f;if(null===t)return d&&d(),t;if(r&&!i.iterateIn&&!i.iterateUnsetNumeric){var b=u.indexOf(t);if(!(b<0))return a[e]="#",d&&d({cyclicKeypath:y[b]}),"#"+y[b];!0===r&&(u.push(t),y.push(e))}var O=isPlainObject(t),m=isArray(t),T=(O||m)&&(!n.length||i.replaced)||i.iterateIn?t:replace(e,t,i,o,O||m,null,d),g=void 0;if(T!==t?(f=T,h={replaced:T}):m||"array"===i.iterateIn?(g=new Array(t.length),h={clone:g}):O||"object"===i.iterateIn?h={clone:g={}}:""===e&&hasConstructorOf(t,TypesonPromise)?(o.push([e,t,r,i,void 0,void 0,i.type]),f=t):f=t,d&&d(),s.iterateNone)return g||f;if(!g)return f;if(i.iterateIn){for(var P in t){var j={ownKeys:t.hasOwnProperty(P)},w=e+(e?".":"")+escapeKeyPathComponent(P),S=_encapsulate(w,t[P],!!r,j,o,c);hasConstructorOf(S,TypesonPromise)?o.push([w,S,!!r,j,g,P,j.type]):void 0!==S&&(g[P]=S)}d&&d({endIterateIn:!0,end:!0})}else keys(t).forEach(function(n){var i=e+(e?".":"")+escapeKeyPathComponent(n),s={ownKeys:!0},a=_encapsulate(i,t[n],!!r,s,o,c);hasConstructorOf(a,TypesonPromise)?o.push([i,a,!!r,s,g,n,s.type]):void 0!==a&&(g[n]=a)}),d&&d({endIterateOwn:!0,end:!0});if(i.iterateUnsetNumeric){for(var A=t.length,C=0;C<A;C++)if(!(C in t)){var N=e+(e?".":"")+C,K={ownKeys:!1},B=_encapsulate(N,void 0,!!r,K,o,c);hasConstructorOf(B,TypesonPromise)?o.push([N,B,!!r,K,g,C,K.type]):void 0!==B&&(g[C]=B)}d&&d({endIterateUnsetNumeric:!0,end:!0})}return g}function replace(e,i,o,s,u,y,p){for(var l=u?n:t,h=l.length;h--;){var v=l[h];if(v.test(i,o)){var d=v.type;if(r[d]){var b=a[e];a[e]=b?[d].concat(b):d}if(o=Object.assign(o,{type:d,replaced:!0}),(c||!v.replaceAsync)&&!v.replace)return p&&p({typeDetected:!0}),_encapsulate(e,i,f&&"readonly",o,s,y,d);p&&p({replacing:!0});return _encapsulate(e,v[c||!v.replaceAsync?"replace":"replaceAsync"](i,o),f&&"readonly",o,s,y,d)}}return i}var c=(s=Object.assign({sync:!0},e,s)).sync,a={},u=[],y=[],p=[],f=!(s&&"cyclic"in s)||s.cyclic,l=s.encapsulateObserver,h=_encapsulate("",i,f,o||{},p);return p.length?c&&s.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():Promise.resolve(checkPromises(h,p)).then(finish):!c&&s.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():s.stringification&&c?[finish(h)]:c?finish(h):Promise.resolve(finish(h))};this.encapsulateSync=function(e,n,t){return c(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!0}))},this.encapsulateAsync=function(e,n,t){return c(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!1}))};var a=this.revive=function(n,t){function _revive(e,n,t,i,a,u){if(!s||"$types"!==e){var y=o[e];if(isArray(n)||isPlainObject(n)){var p=isArray(n)?new Array(n.length):{};for(keys(n).forEach(function(r){var o=_revive(e+(e?".":"")+escapeKeyPathComponent(r),n[r],t||p,i,p,r);hasConstructorOf(o,Undefined)?p[r]=void 0:void 0!==o&&(p[r]=o)}),n=p;c.length;){var f=slicedToArray(c[0],4),l=f[0],h=f[1],v=f[2],d=f[3],b=getByKeyPath(l,h);if(hasConstructorOf(b,Undefined))v[d]=void 0;else{if(void 0===b)break;v[d]=b}c.splice(0,1)}}if(!y)return n;if("#"===y){var O=getByKeyPath(t,n.substr(1));return void 0===O&&c.push([t,n.substr(1),a,u]),O}var m=i.sync;return[].concat(y).reduce(function(e,n){var t=r[n];if(!t)throw new Error("Unregistered type: "+n);return t[m&&t.revive?"revive":!m&&t.reviveAsync?"reviveAsync":"revive"](e)},n)}}var i=(t=Object.assign({sync:!0},e,t)).sync,o=n&&n.$types,s=!0;if(!o)return n;if(!0===o)return n.$;o.$&&isPlainObject(o.$)&&(n=n.$,o=o.$,s=!1);var c=[],a=_revive("",n,null,t);return a=hasConstructorOf(a,Undefined)?void 0:a,isThenable(a)?i&&t.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():a:!i&&t.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():i?a:Promise.resolve(a)};this.reviveSync=function(e,n){return a(e,Object.assign({},{throwOnBadSyncType:!0},n,{sync:!0}))},this.reviveAsync=function(e,n){return a(e,Object.assign({},{throwOnBadSyncType:!0},n,{sync:!1}))},this.register=function(e,o){return o=o||{},[].concat(e).forEach(function R(e){if(isArray(e))return e.map(R);e&&keys(e).forEach(function(s){if("#"===s)throw new TypeError("# cannot be used as a type name as it is reserved for cyclic objects");if(Typeson.JSON_TYPES.includes(s))throw new TypeError("Plain JSON object types are reserved as type names");var c=e[s],a=c.testPlainObjects?n:t,u=a.filter(function(e){return e.type===s});if(u.length&&(a.splice(a.indexOf(u[0]),1),delete r[s],delete i[s]),c){if("function"==typeof c){var y=c;c={test:function test(e){return e&&e.constructor===y},replace:function replace(e){return assign({},e)},revive:function revive(e){return assign(Object.create(y.prototype),e)}}}else isArray(c)&&(c={test:c[0],replace:c[1],revive:c[2]});var p={type:s,test:c.test.bind(c)};c.replace&&(p.replace=c.replace.bind(c)),c.replaceAsync&&(p.replaceAsync=c.replaceAsync.bind(c));var f="number"==typeof o.fallback?o.fallback:o.fallback?0:1/0;if(c.testPlainObjects?n.splice(f,0,p):t.splice(f,0,p),c.revive||c.reviveAsync){var l={};c.revive&&(l.revive=c.revive.bind(c)),c.reviveAsync&&(l.reviveAsync=c.reviveAsync.bind(c)),r[s]=l}i[s]=c}})}),this}}function assign(e,n){return keys(n).map(function(t){e[t]=n[t]}),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,n){if(""===n)return e;var t=n.indexOf(".");if(t>-1){var r=e[unescapeKeyPathComponent(n.substr(0,t))];return void 0===r?void 0:getByKeyPath(r,n.substr(t+1))}return e[unescapeKeyPathComponent(n)]}function Undefined(){}function TypesonPromise(e){this.p=new Promise(e)}var _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},slicedToArray=function(){return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function sliceIterator(e,n){var t=[],r=!0,i=!1,o=void 0;try{for(var s,c=e[Symbol.iterator]();!(r=(s=c.next()).done)&&(t.push(s.value),!n||t.length!==n);r=!0);}catch(e){i=!0,o=e}finally{try{!r&&c.return&&c.return()}finally{if(i)throw o}}return t}(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),toConsumableArray=function(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)},keys=Object.keys,isArray=Array.isArray,toString={}.toString,getProto=Object.getPrototypeOf,hasOwn={}.hasOwnProperty,fnToString=hasOwn.toString;TypesonPromise.prototype.then=function(e,n){var t=this;return new TypesonPromise(function(r,i){t.p.then(function(n){r(e?e(n):n)},function(e){t.p.catch(function(e){return n?n(e):Promise.reject(e)}).then(r,i)})})},TypesonPromise.prototype.catch=function(e){return this.then(null,e)},TypesonPromise.resolve=function(e){return new TypesonPromise(function(n){n(e)})},TypesonPromise.reject=function(e){return new TypesonPromise(function(n,t){t(e)})},["all","race"].map(function(e){TypesonPromise[e]=function(n){return new TypesonPromise(function(t,r){Promise[e](n.map(function(e){return e.p})).then(t,r)})}}),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=function(e){return null===e?"null":isArray(e)?"array":void 0===e?"undefined":_typeof(e)},Typeson.JSON_TYPES=["null","boolean","number","string","array","object"],module.exports=Typeson;
"use strict";function isThenable(e,n){return Typeson.isObject(e)&&"function"==typeof e.then&&(!n||"function"==typeof e.catch)}function toStringTag(e){return toString.call(e).slice(8,-1)}function hasConstructorOf(e,n){if(!e||"object"!==(void 0===e?"undefined":_typeof(e)))return!1;var t=getProto(e);if(!t)return!1;var r=hasOwn.call(t,"constructor")&&t.constructor;return"function"!=typeof r?null===n:"function"==typeof r&&null!==n&&fnToString.call(r)===fnToString.call(n)}function isPlainObject(e){if(!e||"Object"!==toStringTag(e))return!1;return!getProto(e)||hasConstructorOf(e,Object)}function isUserObject(e){if(!e||"Object"!==toStringTag(e))return!1;var n=getProto(e);return!n||(hasConstructorOf(e,Object)||isUserObject(n))}function isObject(e){return e&&"object"===(void 0===e?"undefined":_typeof(e))}function Typeson(e){var n=[],t=[],r={},i=this.types={},o=this.stringify=function(n,t,r,i){i=Object.assign({},e,i,{stringification:!0});var o=c(n,null,i);return isArray(o)?JSON.stringify(o[0],t,r):o.then(function(e){return JSON.stringify(e,t,r)})};this.stringifySync=function(e,n,t,r){return o(e,n,t,Object.assign({},{throwOnBadSyncType:!0},r,{sync:!0}))},this.stringifyAsync=function(e,n,t,r){return o(e,n,t,Object.assign({},{throwOnBadSyncType:!0},r,{sync:!1}))};var s=this.parse=function(n,t,r){return r=Object.assign({},e,r,{parse:!0}),a(JSON.parse(n,t),r)};this.parseSync=function(e,n,t){return s(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!0}))},this.parseAsync=function(e,n,t){return s(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!1}))},this.specialTypeNames=function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.returnTypeNames=!0,this.encapsulate(e,n,t)},this.rootTypeName=function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.iterateNone=!0,this.encapsulate(e,n,t)};var c=this.encapsulate=function(i,o,s){function finish(e){var n=Object.values(a);if(s.iterateNone)return n.length?n[0]:Typeson.getJSONType(e);if(n.length){if(s.returnTypeNames)return[].concat(toConsumableArray(new Set(n)));e&&isPlainObject(e)&&!e.hasOwnProperty("$types")?e.$types=a:e={$:e,$types:{$:a}}}else isObject(e)&&e.hasOwnProperty("$types")&&(e={$:e,$types:!0});return!s.returnTypeNames&&e}function checkPromises(e,n){return Promise.all(n.map(function(e){return e[1].p})).then(function(t){return Promise.all(t.map(function(t){var r=[],i=n.splice(0,1)[0],o=slicedToArray(i,7),s=o[0],c=o[2],a=o[3],u=o[4],y=o[5],p=o[6],f=_encapsulate(s,t,c,a,r,!0,p),l=hasConstructorOf(f,TypesonPromise);return s&&l?f.p.then(function(n){return u[y]=n,checkPromises(e,r)}):(s?u[y]=f:e=l?f.p:f,checkPromises(e,r))}))}).then(function(){return e})}function _removeStateObjectProperties(e){delete e.type,delete e.replaced}function _encapsulate(e,t,r,i,o,c,p){var f=void 0,h={},v=void 0===t?"undefined":_typeof(t),d=l?function(n){var s=p||i.type||Typeson.getJSONType(t);l(Object.assign(n||h,{keypath:e,value:t,cyclic:r,stateObj:i,promisesData:o,resolvingTypesonPromise:c,awaitingTypesonPromise:hasConstructorOf(t,TypesonPromise)},void 0!==s?{type:s}:{}))}:null;if(v in{string:1,boolean:1,number:1,undefined:1})return void 0===t||"number"===v&&(isNaN(t)||t===-1/0||t===1/0)?(f=replace(e,t,i,o,!1,c,d))!==t&&(h={replaced:f}):f=t,d&&d(),f;if(null===t)return d&&d(),t;if(r&&!i.iterateIn&&!i.iterateUnsetNumeric){var b=u.indexOf(t);if(!(b<0))return a[e]="#",d&&d({cyclicKeypath:y[b]}),"#"+y[b];!0===r&&(u.push(t),y.push(e))}var O=isPlainObject(t),m=isArray(t),g=(O||m)&&(!n.length||i.replaced)||i.iterateIn?t:replace(e,t,i,o,O||m,null,d),T=void 0;if(g!==t?(f=g,h={replaced:g}):m||"array"===i.iterateIn?(T=new Array(t.length),h={clone:T}):O||"object"===i.iterateIn?h={clone:T={}}:""===e&&hasConstructorOf(t,TypesonPromise)?(o.push([e,t,r,i,void 0,void 0,i.type]),f=t):f=t,d&&d(),s.iterateNone)return T||f;if(!T)return f;if(i.iterateIn){for(var P in t){var j=Object.assign(i,{ownKeys:t.hasOwnProperty(P)});_removeStateObjectProperties(j);var S=e+(e?".":"")+escapeKeyPathComponent(P),w=_encapsulate(S,t[P],!!r,j,o,c);hasConstructorOf(w,TypesonPromise)?o.push([S,w,!!r,j,T,P,j.type]):void 0!==w&&(T[P]=w)}d&&d({endIterateIn:!0,end:!0})}else keys(t).forEach(function(n){var s=e+(e?".":"")+escapeKeyPathComponent(n),a=Object.assign(i,{ownKeys:!0});_removeStateObjectProperties(a);var u=_encapsulate(s,t[n],!!r,a,o,c);hasConstructorOf(u,TypesonPromise)?o.push([s,u,!!r,a,T,n,a.type]):void 0!==u&&(T[n]=u)}),d&&d({endIterateOwn:!0,end:!0});if(i.iterateUnsetNumeric){for(var A=t.length,C=0;C<A;C++)if(!(C in t)){var N=e+(e?".":"")+C,_=Object.assign(i,{ownKeys:!1});_removeStateObjectProperties(_);var K=_encapsulate(N,void 0,!!r,_,o,c);hasConstructorOf(K,TypesonPromise)?o.push([N,K,!!r,_,T,C,_.type]):void 0!==K&&(T[C]=K)}d&&d({endIterateUnsetNumeric:!0,end:!0})}return T}function replace(e,i,o,s,u,y,p){for(var l=u?n:t,h=l.length;h--;){var v=l[h];if(v.test(i,o)){var d=v.type;if(r[d]){var b=a[e];a[e]=b?[d].concat(b):d}if(o=Object.assign(o,{type:d,replaced:!0}),(c||!v.replaceAsync)&&!v.replace)return p&&p({typeDetected:!0}),_encapsulate(e,i,f&&"readonly",o,s,y,d);p&&p({replacing:!0});return _encapsulate(e,v[c||!v.replaceAsync?"replace":"replaceAsync"](i,o),f&&"readonly",o,s,y,d)}}return i}var c=(s=Object.assign({sync:!0},e,s)).sync,a={},u=[],y=[],p=[],f=!(s&&"cyclic"in s)||s.cyclic,l=s.encapsulateObserver,h=_encapsulate("",i,f,o||{},p);return p.length?c&&s.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():Promise.resolve(checkPromises(h,p)).then(finish):!c&&s.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():s.stringification&&c?[finish(h)]:c?finish(h):Promise.resolve(finish(h))};this.encapsulateSync=function(e,n,t){return c(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!0}))},this.encapsulateAsync=function(e,n,t){return c(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!1}))};var a=this.revive=function(n,t){function _revive(e,n,t,i,u,y){if(!s||"$types"!==e){var p=o[e];if(isArray(n)||isPlainObject(n)){var f=isArray(n)?new Array(n.length):{};for(keys(n).forEach(function(r){var o=_revive(e+(e?".":"")+escapeKeyPathComponent(r),n[r],t||f,i,f,r);hasConstructorOf(o,Undefined)?f[r]=void 0:void 0!==o&&(f[r]=o)}),n=f;c.length;){var l=slicedToArray(c[0],4),h=l[0],v=l[1],d=l[2],b=l[3],O=getByKeyPath(h,v);if(hasConstructorOf(O,Undefined))d[b]=void 0;else{if(void 0===O)break;d[b]=O}c.splice(0,1)}}if(!p)return n;if("#"===p){var m=getByKeyPath(t,n.substr(1));return void 0===m&&c.push([t,n.substr(1),u,y]),m}var g=i.sync;return[].concat(p).reduce(function(e,n){var t=r[n];if(!t)throw new Error("Unregistered type: "+n);return t[g&&t.revive?"revive":!g&&t.reviveAsync?"reviveAsync":"revive"](e,a)},n)}}var i=(t=Object.assign({sync:!0},e,t)).sync,o=n&&n.$types,s=!0;if(!o)return n;if(!0===o)return n.$;o.$&&isPlainObject(o.$)&&(n=n.$,o=o.$,s=!1);var c=[],a={},u=_revive("",n,null,t);return u=hasConstructorOf(u,Undefined)?void 0:u,isThenable(u)?i&&t.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():u:!i&&t.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():i?u:Promise.resolve(u)};this.reviveSync=function(e,n){return a(e,Object.assign({},{throwOnBadSyncType:!0},n,{sync:!0}))},this.reviveAsync=function(e,n){return a(e,Object.assign({},{throwOnBadSyncType:!0},n,{sync:!1}))},this.register=function(e,o){return o=o||{},[].concat(e).forEach(function R(e){if(isArray(e))return e.map(R);e&&keys(e).forEach(function(s){if("#"===s)throw new TypeError("# cannot be used as a type name as it is reserved for cyclic objects");if(Typeson.JSON_TYPES.includes(s))throw new TypeError("Plain JSON object types are reserved as type names");var c=e[s],a=c.testPlainObjects?n:t,u=a.filter(function(e){return e.type===s});if(u.length&&(a.splice(a.indexOf(u[0]),1),delete r[s],delete i[s]),c){if("function"==typeof c){var y=c;c={test:function test(e){return e&&e.constructor===y},replace:function replace(e){return assign({},e)},revive:function revive(e){return assign(Object.create(y.prototype),e)}}}else isArray(c)&&(c={test:c[0],replace:c[1],revive:c[2]});var p={type:s,test:c.test.bind(c)};c.replace&&(p.replace=c.replace.bind(c)),c.replaceAsync&&(p.replaceAsync=c.replaceAsync.bind(c));var f="number"==typeof o.fallback?o.fallback:o.fallback?0:1/0;if(c.testPlainObjects?n.splice(f,0,p):t.splice(f,0,p),c.revive||c.reviveAsync){var l={};c.revive&&(l.revive=c.revive.bind(c)),c.reviveAsync&&(l.reviveAsync=c.reviveAsync.bind(c)),r[s]=l}i[s]=c}})}),this}}function assign(e,n){return keys(n).map(function(t){e[t]=n[t]}),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,n){if(""===n)return e;var t=n.indexOf(".");if(t>-1){var r=e[unescapeKeyPathComponent(n.substr(0,t))];return void 0===r?void 0:getByKeyPath(r,n.substr(t+1))}return e[unescapeKeyPathComponent(n)]}function Undefined(){}function TypesonPromise(e){this.p=new Promise(e)}var _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},slicedToArray=function(){return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function sliceIterator(e,n){var t=[],r=!0,i=!1,o=void 0;try{for(var s,c=e[Symbol.iterator]();!(r=(s=c.next()).done)&&(t.push(s.value),!n||t.length!==n);r=!0);}catch(e){i=!0,o=e}finally{try{!r&&c.return&&c.return()}finally{if(i)throw o}}return t}(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),toConsumableArray=function(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)},keys=Object.keys,isArray=Array.isArray,toString={}.toString,getProto=Object.getPrototypeOf,hasOwn={}.hasOwnProperty,fnToString=hasOwn.toString;TypesonPromise.prototype.then=function(e,n){var t=this;return new TypesonPromise(function(r,i){t.p.then(function(n){r(e?e(n):n)},function(e){t.p.catch(function(e){return n?n(e):Promise.reject(e)}).then(r,i)})})},TypesonPromise.prototype.catch=function(e){return this.then(null,e)},TypesonPromise.resolve=function(e){return new TypesonPromise(function(n){n(e)})},TypesonPromise.reject=function(e){return new TypesonPromise(function(n,t){t(e)})},["all","race"].map(function(e){TypesonPromise[e]=function(n){return new TypesonPromise(function(t,r){Promise[e](n.map(function(e){return e.p})).then(t,r)})}}),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=function(e){return null===e?"null":isArray(e)?"array":void 0===e?"undefined":_typeof(e)},Typeson.JSON_TYPES=["null","boolean","number","string","array","object"],module.exports=Typeson;

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

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.Typeson=n()}(this,function(){"use strict";function isThenable(e,n){return Typeson.isObject(e)&&"function"==typeof e.then&&(!n||"function"==typeof e.catch)}function toStringTag(e){return o.call(e).slice(8,-1)}function hasConstructorOf(n,t){if(!n||"object"!==(void 0===n?"undefined":e(n)))return!1;var r=s(n);if(!r)return!1;var i=c.call(r,"constructor")&&r.constructor;return"function"!=typeof i?null===t:"function"==typeof i&&null!==t&&a.call(i)===a.call(t)}function isPlainObject(e){if(!e||"Object"!==toStringTag(e))return!1;return!s(e)||hasConstructorOf(e,Object)}function isUserObject(e){if(!e||"Object"!==toStringTag(e))return!1;var n=s(e);return!n||(hasConstructorOf(e,Object)||isUserObject(n))}function isObject(n){return n&&"object"===(void 0===n?"undefined":e(n))}function Typeson(o){var s=[],c=[],a={},u=this.types={},y=this.stringify=function(e,n,t,r){r=Object.assign({},o,r,{stringification:!0});var s=f(e,null,r);return i(s)?JSON.stringify(s[0],n,t):s.then(function(e){return JSON.stringify(e,n,t)})};this.stringifySync=function(e,n,t,r){return y(e,n,t,Object.assign({},{throwOnBadSyncType:!0},r,{sync:!0}))},this.stringifyAsync=function(e,n,t,r){return y(e,n,t,Object.assign({},{throwOnBadSyncType:!0},r,{sync:!1}))};var p=this.parse=function(e,n,t){return t=Object.assign({},o,t,{parse:!0}),l(JSON.parse(e,n),t)};this.parseSync=function(e,n,t){return p(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!0}))},this.parseAsync=function(e,n,t){return p(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!1}))},this.specialTypeNames=function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.returnTypeNames=!0,this.encapsulate(e,n,t)},this.rootTypeName=function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.iterateNone=!0,this.encapsulate(e,n,t)};var f=this.encapsulate=function(u,y,p){function finish(e){var n=Object.values(l);if(p.iterateNone)return n.length?n[0]:Typeson.getJSONType(e);if(n.length){if(p.returnTypeNames)return[].concat(t(new Set(n)));e&&isPlainObject(e)&&!e.hasOwnProperty("$types")?e.$types=l:e={$:e,$types:{$:l}}}else isObject(e)&&e.hasOwnProperty("$types")&&(e={$:e,$types:!0});return!p.returnTypeNames&&e}function checkPromises(e,t){return Promise.all(t.map(function(e){return e[1].p})).then(function(r){return Promise.all(r.map(function(r){var i=[],o=t.splice(0,1)[0],s=n(o,7),c=s[0],a=s[2],u=s[3],y=s[4],p=s[5],f=s[6],l=_encapsulate(c,r,a,u,i,!0,f),h=hasConstructorOf(l,TypesonPromise);return c&&h?l.p.then(function(n){return y[p]=n,checkPromises(e,i)}):(c?y[p]=l:e=h?l.p:l,checkPromises(e,i))}))}).then(function(){return e})}function _encapsulate(n,t,o,c,a,u,y){var f=void 0,d={},b=void 0===t?"undefined":e(t),m=O?function(e){var r=y||c.type||Typeson.getJSONType(t);O(Object.assign(e||d,{keypath:n,value:t,cyclic:o,stateObj:c,promisesData:a,resolvingTypesonPromise:u,awaitingTypesonPromise:hasConstructorOf(t,TypesonPromise)},void 0!==r?{type:r}:{}))}:null;if(b in{string:1,boolean:1,number:1,undefined:1})return void 0===t||"number"===b&&(isNaN(t)||t===-1/0||t===1/0)?(f=replace(n,t,c,a,!1,u,m))!==t&&(d={replaced:f}):f=t,m&&m(),f;if(null===t)return m&&m(),t;if(o&&!c.iterateIn&&!c.iterateUnsetNumeric){var T=h.indexOf(t);if(!(T<0))return l[n]="#",m&&m({cyclicKeypath:v[T]}),"#"+v[T];!0===o&&(h.push(t),v.push(n))}var g=isPlainObject(t),P=i(t),j=(g||P)&&(!s.length||c.replaced)||c.iterateIn?t:replace(n,t,c,a,g||P,null,m),w=void 0;if(j!==t?(f=j,d={replaced:j}):P||"array"===c.iterateIn?(w=new Array(t.length),d={clone:w}):g||"object"===c.iterateIn?d={clone:w={}}:""===n&&hasConstructorOf(t,TypesonPromise)?(a.push([n,t,o,c,void 0,void 0,c.type]),f=t):f=t,m&&m(),p.iterateNone)return w||f;if(!w)return f;if(c.iterateIn){for(var S in t){var A={ownKeys:t.hasOwnProperty(S)},C=n+(n?".":"")+escapeKeyPathComponent(S),N=_encapsulate(C,t[S],!!o,A,a,u);hasConstructorOf(N,TypesonPromise)?a.push([C,N,!!o,A,w,S,A.type]):void 0!==N&&(w[S]=N)}m&&m({endIterateIn:!0,end:!0})}else r(t).forEach(function(e){var r=n+(n?".":"")+escapeKeyPathComponent(e),i={ownKeys:!0},s=_encapsulate(r,t[e],!!o,i,a,u);hasConstructorOf(s,TypesonPromise)?a.push([r,s,!!o,i,w,e,i.type]):void 0!==s&&(w[e]=s)}),m&&m({endIterateOwn:!0,end:!0});if(c.iterateUnsetNumeric){for(var K=t.length,B=0;B<K;B++)if(!(B in t)){var $=n+(n?".":"")+B,E={ownKeys:!1},U=_encapsulate($,void 0,!!o,E,a,u);hasConstructorOf(U,TypesonPromise)?a.push([$,U,!!o,E,w,B,E.type]):void 0!==U&&(w[B]=U)}m&&m({endIterateUnsetNumeric:!0,end:!0})}return w}function replace(e,n,t,r,i,o,u){for(var y=i?s:c,p=y.length;p--;){var h=y[p];if(h.test(n,t)){var v=h.type;if(a[v]){var d=l[e];l[e]=d?[v].concat(d):v}if(t=Object.assign(t,{type:v,replaced:!0}),(f||!h.replaceAsync)&&!h.replace)return u&&u({typeDetected:!0}),_encapsulate(e,n,b&&"readonly",t,r,o,v);u&&u({replacing:!0});return _encapsulate(e,h[f||!h.replaceAsync?"replace":"replaceAsync"](n,t),b&&"readonly",t,r,o,v)}}return n}var f=(p=Object.assign({sync:!0},o,p)).sync,l={},h=[],v=[],d=[],b=!(p&&"cyclic"in p)||p.cyclic,O=p.encapsulateObserver,m=_encapsulate("",u,b,y||{},d);return d.length?f&&p.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():Promise.resolve(checkPromises(m,d)).then(finish):!f&&p.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():p.stringification&&f?[finish(m)]:f?finish(m):Promise.resolve(finish(m))};this.encapsulateSync=function(e,n,t){return f(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!0}))},this.encapsulateAsync=function(e,n,t){return f(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!1}))};var l=this.revive=function(e,t){function _revive(e,t,o,s,p,f){if(!u||"$types"!==e){var l=c[e];if(i(t)||isPlainObject(t)){var h=i(t)?new Array(t.length):{};for(r(t).forEach(function(n){var r=_revive(e+(e?".":"")+escapeKeyPathComponent(n),t[n],o||h,s,h,n);hasConstructorOf(r,Undefined)?h[n]=void 0:void 0!==r&&(h[n]=r)}),t=h;y.length;){var v=n(y[0],4),d=v[0],b=v[1],O=v[2],m=v[3],T=getByKeyPath(d,b);if(hasConstructorOf(T,Undefined))O[m]=void 0;else{if(void 0===T)break;O[m]=T}y.splice(0,1)}}if(!l)return t;if("#"===l){var g=getByKeyPath(o,t.substr(1));return void 0===g&&y.push([o,t.substr(1),p,f]),g}var P=s.sync;return[].concat(l).reduce(function(e,n){var t=a[n];if(!t)throw new Error("Unregistered type: "+n);return t[P&&t.revive?"revive":!P&&t.reviveAsync?"reviveAsync":"revive"](e)},t)}}var s=(t=Object.assign({sync:!0},o,t)).sync,c=e&&e.$types,u=!0;if(!c)return e;if(!0===c)return e.$;c.$&&isPlainObject(c.$)&&(e=e.$,c=c.$,u=!1);var y=[],p=_revive("",e,null,t);return p=hasConstructorOf(p,Undefined)?void 0:p,isThenable(p)?s&&t.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():p:!s&&t.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():s?p:Promise.resolve(p)};this.reviveSync=function(e,n){return l(e,Object.assign({},{throwOnBadSyncType:!0},n,{sync:!0}))},this.reviveAsync=function(e,n){return l(e,Object.assign({},{throwOnBadSyncType:!0},n,{sync:!1}))},this.register=function(e,n){return n=n||{},[].concat(e).forEach(function R(e){if(i(e))return e.map(R);e&&r(e).forEach(function(t){if("#"===t)throw new TypeError("# cannot be used as a type name as it is reserved for cyclic objects");if(Typeson.JSON_TYPES.includes(t))throw new TypeError("Plain JSON object types are reserved as type names");var r=e[t],o=r.testPlainObjects?s:c,y=o.filter(function(e){return e.type===t});if(y.length&&(o.splice(o.indexOf(y[0]),1),delete a[t],delete u[t]),r){if("function"==typeof r){var p=r;r={test:function test(e){return e&&e.constructor===p},replace:function replace(e){return assign({},e)},revive:function revive(e){return assign(Object.create(p.prototype),e)}}}else i(r)&&(r={test:r[0],replace:r[1],revive:r[2]});var f={type:t,test:r.test.bind(r)};r.replace&&(f.replace=r.replace.bind(r)),r.replaceAsync&&(f.replaceAsync=r.replaceAsync.bind(r));var l="number"==typeof n.fallback?n.fallback:n.fallback?0:1/0;if(r.testPlainObjects?s.splice(l,0,f):c.splice(l,0,f),r.revive||r.reviveAsync){var h={};r.revive&&(h.revive=r.revive.bind(r)),r.reviveAsync&&(h.reviveAsync=r.reviveAsync.bind(r)),a[t]=h}u[t]=r}})}),this}}function assign(e,n){return r(n).map(function(t){e[t]=n[t]}),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,n){if(""===n)return e;var t=n.indexOf(".");if(t>-1){var r=e[unescapeKeyPathComponent(n.substr(0,t))];return void 0===r?void 0:getByKeyPath(r,n.substr(t+1))}return e[unescapeKeyPathComponent(n)]}function Undefined(){}function TypesonPromise(e){this.p=new Promise(e)}var e="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},n=function(){return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function sliceIterator(e,n){var t=[],r=!0,i=!1,o=void 0;try{for(var s,c=e[Symbol.iterator]();!(r=(s=c.next()).done)&&(t.push(s.value),!n||t.length!==n);r=!0);}catch(e){i=!0,o=e}finally{try{!r&&c.return&&c.return()}finally{if(i)throw o}}return t}(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),t=function(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)},r=Object.keys,i=Array.isArray,o={}.toString,s=Object.getPrototypeOf,c={}.hasOwnProperty,a=c.toString;return TypesonPromise.prototype.then=function(e,n){var t=this;return new TypesonPromise(function(r,i){t.p.then(function(n){r(e?e(n):n)},function(e){t.p.catch(function(e){return n?n(e):Promise.reject(e)}).then(r,i)})})},TypesonPromise.prototype.catch=function(e){return this.then(null,e)},TypesonPromise.resolve=function(e){return new TypesonPromise(function(n){n(e)})},TypesonPromise.reject=function(e){return new TypesonPromise(function(n,t){t(e)})},["all","race"].map(function(e){TypesonPromise[e]=function(n){return new TypesonPromise(function(t,r){Promise[e](n.map(function(e){return e.p})).then(t,r)})}}),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=function(n){return null===n?"null":i(n)?"array":void 0===n?"undefined":e(n)},Typeson.JSON_TYPES=["null","boolean","number","string","array","object"],Typeson});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.Typeson=n()}(this,function(){"use strict";function isThenable(e,n){return Typeson.isObject(e)&&"function"==typeof e.then&&(!n||"function"==typeof e.catch)}function toStringTag(e){return o.call(e).slice(8,-1)}function hasConstructorOf(n,t){if(!n||"object"!==(void 0===n?"undefined":e(n)))return!1;var r=s(n);if(!r)return!1;var i=c.call(r,"constructor")&&r.constructor;return"function"!=typeof i?null===t:"function"==typeof i&&null!==t&&a.call(i)===a.call(t)}function isPlainObject(e){if(!e||"Object"!==toStringTag(e))return!1;return!s(e)||hasConstructorOf(e,Object)}function isUserObject(e){if(!e||"Object"!==toStringTag(e))return!1;var n=s(e);return!n||(hasConstructorOf(e,Object)||isUserObject(n))}function isObject(n){return n&&"object"===(void 0===n?"undefined":e(n))}function Typeson(o){var s=[],c=[],a={},u=this.types={},y=this.stringify=function(e,n,t,r){r=Object.assign({},o,r,{stringification:!0});var s=f(e,null,r);return i(s)?JSON.stringify(s[0],n,t):s.then(function(e){return JSON.stringify(e,n,t)})};this.stringifySync=function(e,n,t,r){return y(e,n,t,Object.assign({},{throwOnBadSyncType:!0},r,{sync:!0}))},this.stringifyAsync=function(e,n,t,r){return y(e,n,t,Object.assign({},{throwOnBadSyncType:!0},r,{sync:!1}))};var p=this.parse=function(e,n,t){return t=Object.assign({},o,t,{parse:!0}),l(JSON.parse(e,n),t)};this.parseSync=function(e,n,t){return p(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!0}))},this.parseAsync=function(e,n,t){return p(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!1}))},this.specialTypeNames=function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.returnTypeNames=!0,this.encapsulate(e,n,t)},this.rootTypeName=function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.iterateNone=!0,this.encapsulate(e,n,t)};var f=this.encapsulate=function(u,y,p){function finish(e){var n=Object.values(l);if(p.iterateNone)return n.length?n[0]:Typeson.getJSONType(e);if(n.length){if(p.returnTypeNames)return[].concat(t(new Set(n)));e&&isPlainObject(e)&&!e.hasOwnProperty("$types")?e.$types=l:e={$:e,$types:{$:l}}}else isObject(e)&&e.hasOwnProperty("$types")&&(e={$:e,$types:!0});return!p.returnTypeNames&&e}function checkPromises(e,t){return Promise.all(t.map(function(e){return e[1].p})).then(function(r){return Promise.all(r.map(function(r){var i=[],o=t.splice(0,1)[0],s=n(o,7),c=s[0],a=s[2],u=s[3],y=s[4],p=s[5],f=s[6],l=_encapsulate(c,r,a,u,i,!0,f),h=hasConstructorOf(l,TypesonPromise);return c&&h?l.p.then(function(n){return y[p]=n,checkPromises(e,i)}):(c?y[p]=l:e=h?l.p:l,checkPromises(e,i))}))}).then(function(){return e})}function _removeStateObjectProperties(e){delete e.type,delete e.replaced}function _encapsulate(n,t,o,c,a,u,y){var f=void 0,d={},b=void 0===t?"undefined":e(t),m=O?function(e){var r=y||c.type||Typeson.getJSONType(t);O(Object.assign(e||d,{keypath:n,value:t,cyclic:o,stateObj:c,promisesData:a,resolvingTypesonPromise:u,awaitingTypesonPromise:hasConstructorOf(t,TypesonPromise)},void 0!==r?{type:r}:{}))}:null;if(b in{string:1,boolean:1,number:1,undefined:1})return void 0===t||"number"===b&&(isNaN(t)||t===-1/0||t===1/0)?(f=replace(n,t,c,a,!1,u,m))!==t&&(d={replaced:f}):f=t,m&&m(),f;if(null===t)return m&&m(),t;if(o&&!c.iterateIn&&!c.iterateUnsetNumeric){var T=h.indexOf(t);if(!(T<0))return l[n]="#",m&&m({cyclicKeypath:v[T]}),"#"+v[T];!0===o&&(h.push(t),v.push(n))}var g=isPlainObject(t),P=i(t),j=(g||P)&&(!s.length||c.replaced)||c.iterateIn?t:replace(n,t,c,a,g||P,null,m),S=void 0;if(j!==t?(f=j,d={replaced:j}):P||"array"===c.iterateIn?(S=new Array(t.length),d={clone:S}):g||"object"===c.iterateIn?d={clone:S={}}:""===n&&hasConstructorOf(t,TypesonPromise)?(a.push([n,t,o,c,void 0,void 0,c.type]),f=t):f=t,m&&m(),p.iterateNone)return S||f;if(!S)return f;if(c.iterateIn){for(var w in t){var A=Object.assign(c,{ownKeys:t.hasOwnProperty(w)});_removeStateObjectProperties(A);var C=n+(n?".":"")+escapeKeyPathComponent(w),N=_encapsulate(C,t[w],!!o,A,a,u);hasConstructorOf(N,TypesonPromise)?a.push([C,N,!!o,A,S,w,A.type]):void 0!==N&&(S[w]=N)}m&&m({endIterateIn:!0,end:!0})}else r(t).forEach(function(e){var r=n+(n?".":"")+escapeKeyPathComponent(e),i=Object.assign(c,{ownKeys:!0});_removeStateObjectProperties(i);var s=_encapsulate(r,t[e],!!o,i,a,u);hasConstructorOf(s,TypesonPromise)?a.push([r,s,!!o,i,S,e,i.type]):void 0!==s&&(S[e]=s)}),m&&m({endIterateOwn:!0,end:!0});if(c.iterateUnsetNumeric){for(var K=t.length,B=0;B<K;B++)if(!(B in t)){var _=n+(n?".":"")+B,$=Object.assign(c,{ownKeys:!1});_removeStateObjectProperties($);var E=_encapsulate(_,void 0,!!o,$,a,u);hasConstructorOf(E,TypesonPromise)?a.push([_,E,!!o,$,S,B,$.type]):void 0!==E&&(S[B]=E)}m&&m({endIterateUnsetNumeric:!0,end:!0})}return S}function replace(e,n,t,r,i,o,u){for(var y=i?s:c,p=y.length;p--;){var h=y[p];if(h.test(n,t)){var v=h.type;if(a[v]){var d=l[e];l[e]=d?[v].concat(d):v}if(t=Object.assign(t,{type:v,replaced:!0}),(f||!h.replaceAsync)&&!h.replace)return u&&u({typeDetected:!0}),_encapsulate(e,n,b&&"readonly",t,r,o,v);u&&u({replacing:!0});return _encapsulate(e,h[f||!h.replaceAsync?"replace":"replaceAsync"](n,t),b&&"readonly",t,r,o,v)}}return n}var f=(p=Object.assign({sync:!0},o,p)).sync,l={},h=[],v=[],d=[],b=!(p&&"cyclic"in p)||p.cyclic,O=p.encapsulateObserver,m=_encapsulate("",u,b,y||{},d);return d.length?f&&p.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():Promise.resolve(checkPromises(m,d)).then(finish):!f&&p.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():p.stringification&&f?[finish(m)]:f?finish(m):Promise.resolve(finish(m))};this.encapsulateSync=function(e,n,t){return f(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!0}))},this.encapsulateAsync=function(e,n,t){return f(e,n,Object.assign({},{throwOnBadSyncType:!0},t,{sync:!1}))};var l=this.revive=function(e,t){function _revive(e,t,o,s,f,l){if(!u||"$types"!==e){var h=c[e];if(i(t)||isPlainObject(t)){var v=i(t)?new Array(t.length):{};for(r(t).forEach(function(n){var r=_revive(e+(e?".":"")+escapeKeyPathComponent(n),t[n],o||v,s,v,n);hasConstructorOf(r,Undefined)?v[n]=void 0:void 0!==r&&(v[n]=r)}),t=v;y.length;){var d=n(y[0],4),b=d[0],O=d[1],m=d[2],T=d[3],g=getByKeyPath(b,O);if(hasConstructorOf(g,Undefined))m[T]=void 0;else{if(void 0===g)break;m[T]=g}y.splice(0,1)}}if(!h)return t;if("#"===h){var P=getByKeyPath(o,t.substr(1));return void 0===P&&y.push([o,t.substr(1),f,l]),P}var j=s.sync;return[].concat(h).reduce(function(e,n){var t=a[n];if(!t)throw new Error("Unregistered type: "+n);return t[j&&t.revive?"revive":!j&&t.reviveAsync?"reviveAsync":"revive"](e,p)},t)}}var s=(t=Object.assign({sync:!0},o,t)).sync,c=e&&e.$types,u=!0;if(!c)return e;if(!0===c)return e.$;c.$&&isPlainObject(c.$)&&(e=e.$,c=c.$,u=!1);var y=[],p={},f=_revive("",e,null,t);return f=hasConstructorOf(f,Undefined)?void 0:f,isThenable(f)?s&&t.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():f:!s&&t.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():s?f:Promise.resolve(f)};this.reviveSync=function(e,n){return l(e,Object.assign({},{throwOnBadSyncType:!0},n,{sync:!0}))},this.reviveAsync=function(e,n){return l(e,Object.assign({},{throwOnBadSyncType:!0},n,{sync:!1}))},this.register=function(e,n){return n=n||{},[].concat(e).forEach(function R(e){if(i(e))return e.map(R);e&&r(e).forEach(function(t){if("#"===t)throw new TypeError("# cannot be used as a type name as it is reserved for cyclic objects");if(Typeson.JSON_TYPES.includes(t))throw new TypeError("Plain JSON object types are reserved as type names");var r=e[t],o=r.testPlainObjects?s:c,y=o.filter(function(e){return e.type===t});if(y.length&&(o.splice(o.indexOf(y[0]),1),delete a[t],delete u[t]),r){if("function"==typeof r){var p=r;r={test:function test(e){return e&&e.constructor===p},replace:function replace(e){return assign({},e)},revive:function revive(e){return assign(Object.create(p.prototype),e)}}}else i(r)&&(r={test:r[0],replace:r[1],revive:r[2]});var f={type:t,test:r.test.bind(r)};r.replace&&(f.replace=r.replace.bind(r)),r.replaceAsync&&(f.replaceAsync=r.replaceAsync.bind(r));var l="number"==typeof n.fallback?n.fallback:n.fallback?0:1/0;if(r.testPlainObjects?s.splice(l,0,f):c.splice(l,0,f),r.revive||r.reviveAsync){var h={};r.revive&&(h.revive=r.revive.bind(r)),r.reviveAsync&&(h.reviveAsync=r.reviveAsync.bind(r)),a[t]=h}u[t]=r}})}),this}}function assign(e,n){return r(n).map(function(t){e[t]=n[t]}),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,n){if(""===n)return e;var t=n.indexOf(".");if(t>-1){var r=e[unescapeKeyPathComponent(n.substr(0,t))];return void 0===r?void 0:getByKeyPath(r,n.substr(t+1))}return e[unescapeKeyPathComponent(n)]}function Undefined(){}function TypesonPromise(e){this.p=new Promise(e)}var e="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},n=function(){return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function sliceIterator(e,n){var t=[],r=!0,i=!1,o=void 0;try{for(var s,c=e[Symbol.iterator]();!(r=(s=c.next()).done)&&(t.push(s.value),!n||t.length!==n);r=!0);}catch(e){i=!0,o=e}finally{try{!r&&c.return&&c.return()}finally{if(i)throw o}}return t}(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),t=function(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)},r=Object.keys,i=Array.isArray,o={}.toString,s=Object.getPrototypeOf,c={}.hasOwnProperty,a=c.toString;return TypesonPromise.prototype.then=function(e,n){var t=this;return new TypesonPromise(function(r,i){t.p.then(function(n){r(e?e(n):n)},function(e){t.p.catch(function(e){return n?n(e):Promise.reject(e)}).then(r,i)})})},TypesonPromise.prototype.catch=function(e){return this.then(null,e)},TypesonPromise.resolve=function(e){return new TypesonPromise(function(n){n(e)})},TypesonPromise.reject=function(e){return new TypesonPromise(function(n,t){t(e)})},["all","race"].map(function(e){TypesonPromise[e]=function(n){return new TypesonPromise(function(t,r){Promise[e](n.map(function(e){return e.p})).then(t,r)})}}),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=function(n){return null===n?"null":i(n)?"array":void 0===n?"undefined":e(n)},Typeson.JSON_TYPES=["null","boolean","number","string","array","object"],Typeson});
{
"name": "typeson",
"version": "5.7.1",
"version": "5.8.0",
"description": "Preserves types over JSON, BSON or socket.io",

@@ -40,20 +40,20 @@ "main": "./dist/typeson-commonjs2.js",

"base64-arraybuffer": "0.1.5",
"eslint": "4.13.0",
"eslint-config-standard": "10.2.1",
"eslint-plugin-compat": "2.1.0",
"eslint": "4.18.0",
"eslint-config-standard": "11.0.0-beta.0",
"eslint-plugin-compat": "2.2.0",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-node": "5.2.1",
"eslint-plugin-node": "6.0.0",
"eslint-plugin-promise": "3.6.0",
"eslint-plugin-standard": "3.0.1",
"node-static": "0.7.10",
"opn": "5.1.0",
"rollup": "0.52.1",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-uglify": "^2.0.1",
"uglify-es": "^3.2.1",
"uglify-js": "3.2.1"
"opn": "5.2.0",
"rollup": "0.56.1",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-commonjs": "^8.3.0",
"rollup-plugin-node-resolve": "^3.0.3",
"rollup-plugin-uglify": "^3.0.0",
"uglify-es": "^3.3.9",
"uglify-js": "3.3.11"
},
"tonicExample": "var Typeson = require('typeson');\nvar TSON = new Typeson().register(require('typeson-registry/presets/builtin'));\n\nTSON.stringify({foo: new Date()}, null, 2);"
}

@@ -222,2 +222,6 @@ const keys = Object.keys,

function _removeStateObjectProperties (stateObj) {
delete stateObj.type;
delete stateObj.replaced;
}
function _encapsulate (keypath, value, cyclic, stateObj, promisesData, resolvingTypesonPromise, detectedType) {

@@ -316,3 +320,4 @@ let ret;

for (const key in value) {
const ownKeysObj = {ownKeys: value.hasOwnProperty(key)};
const ownKeysObj = Object.assign(stateObj, {ownKeys: value.hasOwnProperty(key)});
_removeStateObjectProperties(ownKeysObj);
const kp = keypath + (keypath ? '.' : '') + escapeKeyPathComponent(key);

@@ -328,3 +333,4 @@ const val = _encapsulate(kp, value[key], !!cyclic, ownKeysObj, promisesData, resolvingTypesonPromise);

const kp = keypath + (keypath ? '.' : '') + escapeKeyPathComponent(key);
const ownKeysObj = {ownKeys: true};
const ownKeysObj = Object.assign(stateObj, {ownKeys: true});
_removeStateObjectProperties(ownKeysObj);
const val = _encapsulate(kp, value[key], !!cyclic, ownKeysObj, promisesData, resolvingTypesonPromise);

@@ -343,3 +349,4 @@ if (hasConstructorOf(val, TypesonPromise)) {

const kp = keypath + (keypath ? '.' : '') + i; // No need to escape numeric
const ownKeysObj = {ownKeys: false};
const ownKeysObj = Object.assign(stateObj, {ownKeys: false});
_removeStateObjectProperties(ownKeysObj);
const val = _encapsulate(kp, undefined, !!cyclic, ownKeysObj, promisesData, resolvingTypesonPromise);

@@ -416,2 +423,3 @@ if (hasConstructorOf(val, TypesonPromise)) {

const keyPathResolutions = [];
const stateObj = {};
let ret = _revive('', obj, null, opts);

@@ -478,3 +486,3 @@ ret = hasConstructorOf(ret, Undefined) ? undefined : ret;

: 'revive'
](val);
](val, stateObj);
}, value);

@@ -481,0 +489,0 @@ }

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