@es-joy/jsoe 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/README.md +3 -0
- package/package.json +4 -2
- package/src/formats/structuredCloning.js +1 -1
- package/src/formats.js +1 -1
- package/src/fundamentalTypes/arrayType.js +1 -1
- package/src/fundamentalTypes/dateType.js +1 -1
- package/src/fundamentalTypes/regexpType.js +1 -1
- package/src/subTypes/blobHTMLType.js +1 -1
- package/src/typeChoices.js +1 -1
- package/src/types.js +2 -2
- package/src/utils/dialogs.js +1 -1
- package/vendor/jamilih/dist/jml-es.js +1692 -0
- package/vendor/typeson-registry/dist/index.js +1262 -0
|
@@ -0,0 +1,1262 @@
|
|
|
1
|
+
function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n);}return r}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t]);})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t));}));}return e}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},_typeof(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 r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,_toPropertyKey(n.key),n);}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty(e,t,r){return (t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _slicedToArray(e,t){return function _arrayWithHoles(e){if(Array.isArray(e))return e}(e)||function _iterableToArrayLimit(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,a,i,c=[],s=!0,u=!1;try{if(a=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1;}else for(;!(s=(n=a.call(r)).done)&&(c.push(n.value),c.length!==t);s=!0);}catch(e){u=!0,o=e;}finally{try{if(!s&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(u)throw o}}return c}}(e,t)||_unsupportedIterableToArray(e,t)||function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _toConsumableArray(e){return function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}(e)||function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||_unsupportedIterableToArray(e)||function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return "Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _toPropertyKey(e){var t=function _toPrimitive(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===t?String:Number)(e)}(e,"string");return "symbol"==typeof t?t:String(t)}var e=_createClass((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,r){var n=this;return new e((function(e,o){n.p.then((function(r){e(t?t(r):r);})).catch((function(e){return r?r(e):Promise.reject(e)})).then(e,o);}))},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,r){r(t);}))},["all","race","allSettled"].forEach((function(t){e[t]=function(r){return new e((function(e,n){Promise[t](r.map((function(e){return e&&e.constructor&&"TypesonPromise"===e.constructor.__typeson__type__?e.p:e}))).then(e,n);}))};}));var t={}.toString,r={}.hasOwnProperty,n=Object.getPrototypeOf,o=r.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=n(e);if(!a)return null===t;var i=r.call(a,"constructor")&&a.constructor;return "function"!=typeof i?null===t:t===i||(null!==t&&o.call(i)===o.call(t)||"function"==typeof t&&"string"==typeof i.__typeson__type__&&i.__typeson__type__===t.__typeson__type__)}function isPlainObject(e){return !(!e||"Object"!==toStringTag(e))&&(!n(e)||hasConstructorOf(e,Object))}function isUserObject(e){if(!e||"Object"!==toStringTag(e))return !1;var t=n(e);return !t||(hasConstructorOf(e,Object)||isUserObject(t))}function isObject(e){return e&&"object"===_typeof(e)}function escapeKeyPathComponent(e){return e.replace(/''/g,"''''").replace(/^$/,"''").replace(/~/g,"~0").replace(/\./g,"~1")}function unescapeKeyPathComponent(e){return e.replace(/~1/g,".").replace(/~0/g,"~").replace(/^''$/,"").replace(/''''/g,"''")}function getByKeyPath(e,t){if(""===t)return e;var r=t.indexOf(".");if(r>-1){var n=e[unescapeKeyPathComponent(t.slice(0,r))];return void 0===n?void 0:getByKeyPath(n,t.slice(r+1))}return e[unescapeKeyPathComponent(t)]}function setAtKeyPath(e,t,r){if(""===t)return r;var n=t.indexOf(".");return n>-1?setAtKeyPath(e[unescapeKeyPathComponent(t.slice(0,n))],t.slice(n+1),r):(e[unescapeKeyPathComponent(t)]=r,e)}function getJSONType(e){return null===e?"null":Array.isArray(e)?"array":_typeof(e)}function _await(e,t,r){return r?t?t(e):e:(e&&e.then||(e=Promise.resolve(e)),t?e.then(t):e)}var a=Object.keys,i$1=Array.isArray,c={}.hasOwnProperty,s=["type","replaced","iterateIn","iterateUnsetNumeric"];function _async(e){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];try{return Promise.resolve(e.apply(this,t))}catch(e){return Promise.reject(e)}}}function nestedPathsFirst(e,t){if(""===e.keypath)return -1;var r=e.keypath.match(/\./g)||0,n=t.keypath.match(/\./g)||0;return r&&(r=r.length),n&&(n=n.length),r>n?-1:r<n?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 _createClass(Typeson,[{key:"stringify",value:function stringify(e,t,r,n){n=_objectSpread2(_objectSpread2(_objectSpread2({},this.options),n),{},{stringification:!0});var o=this.encapsulate(e,null,n);return i$1(o)?JSON.stringify(o[0],t,r):o.then((function(e){return JSON.stringify(e,t,r)}))}},{key:"stringifySync",value:function stringifySync(e,t,r,n){return this.stringify(e,t,r,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},n),{},{sync:!0}))}},{key:"stringifyAsync",value:function stringifyAsync(e,t,r,n){return this.stringify(e,t,r,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},n),{},{sync:!1}))}},{key:"parse",value:function parse(e,t,r){return r=_objectSpread2(_objectSpread2(_objectSpread2({},this.options),r),{},{parse:!0}),this.revive(JSON.parse(e,t),r)}},{key:"parseSync",value:function parseSync(e,t,r){return this.parse(e,t,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},r),{},{sync:!0}))}},{key:"parseAsync",value:function parseAsync(e,t,r){return this.parse(e,t,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},r),{},{sync:!1}))}},{key:"specialTypeNames",value:function specialTypeNames(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return r.returnTypeNames=!0,this.encapsulate(e,t,r)}},{key:"rootTypeName",value:function rootTypeName(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return r.iterateNone=!0,this.encapsulate(e,t,r)}},{key:"encapsulate",value:function encapsulate(t,r,n){var o=_async((function(t,r){return _await(Promise.all(r.map((function(e){return e[1].p}))),(function(n){return _await(Promise.all(n.map(_async((function(n){var a=!1,i=[],c=_slicedToArray(r.splice(0,1),1),s=_slicedToArray(c[0],7),u=s[0],p=s[2],l=s[3],y=s[4],f=s[5],h=s[6],v=_encapsulate(u,n,p,l,i,!0,h),b=hasConstructorOf(v,e);return function _invoke(e,t){var r=e();return r&&r.then?r.then(t):t(r)}((function(){if(u&&b)return _await(v.p,(function(e){y[f]=e;var r=o(t,i);return a=!0,r}))}),(function(e){return a?e:(u?y[f]=v:t=b?v.p:v,o(t,i))}))})))),(function(){return t}))}))})),u=(n=_objectSpread2(_objectSpread2({sync:!0},this.options),n)).sync,p=this,l={},y=[],f=[],h=[],v=!("cyclic"in n)||n.cyclic,b=n.encapsulateObserver,d=_encapsulate("",t,v,r||{},h);function finish(e){var t=Object.values(l);if(n.iterateNone)return t.length?t[0]:getJSONType(e);if(t.length){if(n.returnTypeNames)return _toConsumableArray(new Set(t));e&&isPlainObject(e)&&!c.call(e,"$types")?e.$types=l:e={$:e,$types:{$:l}};}else isObject(e)&&c.call(e,"$types")&&(e={$:e,$types:!0});return !n.returnTypeNames&&e}function _adaptBuiltinStateObjectProperties(e,t,r){Object.assign(e,t);var n=s.map((function(t){var r=e[t];return delete e[t],r}));r(),s.forEach((function(t,r){e[t]=n[r];}));}function _encapsulate(t,r,o,s,u,h,v){var d,_={},O=_typeof(r),j=b?function(n){var a=v||s.type||getJSONType(r);b(Object.assign(n||_,{keypath:t,value:r,cyclic:o,stateObj:s,promisesData:u,resolvingTypesonPromise:h,awaitingTypesonPromise:hasConstructorOf(r,e)},{type:a}));}:null;if(["string","boolean","number","undefined"].includes(O))return void 0===r||Number.isNaN(r)||r===Number.NEGATIVE_INFINITY||r===Number.POSITIVE_INFINITY?(d=s.replaced?r:replace(t,r,s,u,!1,h,j))!==r&&(_={replaced:d}):d=r,j&&j(),d;if(null===r)return j&&j(),r;if(o&&!s.iterateIn&&!s.iterateUnsetNumeric&&r&&"object"===_typeof(r)){var m=y.indexOf(r);if(!(m<0))return l[t]="#",j&&j({cyclicKeypath:f[m]}),"#"+f[m];!0===o&&(y.push(r),f.push(t));}var g,S=isPlainObject(r),P=i$1(r),T=(S||P)&&(!p.plainObjectReplacers.length||s.replaced)||s.iterateIn?r:replace(t,r,s,u,S||P,null,j);if(T!==r?(d=T,_={replaced:T}):""===t&&hasConstructorOf(r,e)?(u.push([t,r,o,s,void 0,void 0,s.type]),d=r):P&&"object"!==s.iterateIn||"array"===s.iterateIn?(g=new Array(r.length),_={clone:g}):(["function","symbol"].includes(_typeof(r))||"toJSON"in r||hasConstructorOf(r,e)||hasConstructorOf(r,Promise)||hasConstructorOf(r,ArrayBuffer))&&!S&&"object"!==s.iterateIn?d=r:(g={},s.addLength&&(g.length=r.length),_={clone:g}),j&&j(),n.iterateNone)return g||d;if(!g)return d;if(s.iterateIn){var w=function _loop(n){var a={ownKeys:c.call(r,n)};_adaptBuiltinStateObjectProperties(s,a,(function(){var a=t+(t?".":"")+escapeKeyPathComponent(n),i=_encapsulate(a,r[n],Boolean(o),s,u,h);hasConstructorOf(i,e)?u.push([a,i,Boolean(o),s,g,n,s.type]):void 0!==i&&(g[n]=i);}));};for(var A in r)w(A);j&&j({endIterateIn:!0,end:!0});}else a(r).forEach((function(n){var a=t+(t?".":"")+escapeKeyPathComponent(n);_adaptBuiltinStateObjectProperties(s,{ownKeys:!0},(function(){var t=_encapsulate(a,r[n],Boolean(o),s,u,h);hasConstructorOf(t,e)?u.push([a,t,Boolean(o),s,g,n,s.type]):void 0!==t&&(g[n]=t);}));})),j&&j({endIterateOwn:!0,end:!0});if(s.iterateUnsetNumeric){for(var C=r.length,k=function _loop2(n){if(!(n in r)){var a=t+(t?".":"")+n;_adaptBuiltinStateObjectProperties(s,{ownKeys:!1},(function(){var t=_encapsulate(a,void 0,Boolean(o),s,u,h);hasConstructorOf(t,e)?u.push([a,t,Boolean(o),s,g,n,s.type]):void 0!==t&&(g[n]=t);}));}},N=0;N<C;N++)k(N);j&&j({endIterateUnsetNumeric:!0,end:!0});}return g}function replace(e,t,r,n,o,a,i){for(var c=o?p.plainObjectReplacers:p.nonplainObjectReplacers,s=c.length;s--;){var y=c[s];if(y.test(t,r)){var f=y.type;if(p.revivers[f]){var h=l[e];l[e]=h?[f].concat(h):f;}return Object.assign(r,{type:f,replaced:!0}),!u&&y.replaceAsync||y.replace?(i&&i({replacing:!0}),_encapsulate(e,y[u||!y.replaceAsync?"replace":"replaceAsync"](t,r),v&&"readonly",r,n,a,f)):(i&&i({typeDetected:!0}),_encapsulate(e,t,v&&"readonly",r,n,a,f))}}return t}return h.length?u&&n.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():Promise.resolve(o(d,h)).then(finish):!u&&n.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():n.stringification&&u?[finish(d)]:u?finish(d):Promise.resolve(finish(d))}},{key:"encapsulateSync",value:function encapsulateSync(e,t,r){return this.encapsulate(e,t,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},r),{},{sync:!0}))}},{key:"encapsulateAsync",value:function encapsulateAsync(e,t,r){return this.encapsulate(e,t,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},r),{},{sync:!1}))}},{key:"revive",value:function revive(t,r){var n=t&&t.$types;if(!n)return t;if(!0===n)return t.$;var o=(r=_objectSpread2(_objectSpread2({sync:!0},this.options),r)).sync,c=[],s={},u=!0;n.$&&isPlainObject(n.$)&&(t=t.$,n=n.$,u=!1);var l=this;function executeReviver(e,t){var r=_slicedToArray(l.revivers[e]||[],1)[0];if(!r)throw new Error("Unregistered type: "+e);return o&&!("revive"in r)?t:r[o&&r.revive?"revive":!o&&r.reviveAsync?"reviveAsync":"revive"](t,s)}var y=[];function checkUndefined(e){return hasConstructorOf(e,p)?void 0:e}var f,h=function revivePlainObjects(){var r=[];if(Object.entries(n).forEach((function(e){var t=_slicedToArray(e,2),o=t[0],a=t[1];"#"!==a&&[].concat(a).forEach((function(e){_slicedToArray(l.revivers[e]||[null,{}],2)[1].plain&&(r.push({keypath:o,type:e}),delete n[o]);}));})),r.length)return r.sort(nestedPathsFirst).reduce((function reducer(r,n){var o=n.keypath,a=n.type;if(isThenable(r))return r.then((function(e){return reducer(e,{keypath:o,type:a})}));var i=getByKeyPath(t,o);if(hasConstructorOf(i=executeReviver(a,i),e))return i.then((function(e){var r=setAtKeyPath(t,o,e);r===e&&(t=r);}));var c=setAtKeyPath(t,o,i);c===i&&(t=c);}),void 0)}();return hasConstructorOf(h,e)?f=h.then((function(){return t})):(f=function _revive(t,r,o,s,l){if(!u||"$types"!==t){var f=n[t],h=i$1(r);if(h||isPlainObject(r)){var v=h?new Array(r.length):{};for(a(r).forEach((function(n){var a=_revive(t+(t?".":"")+escapeKeyPathComponent(n),r[n],o||v,v,n),i=function set(e){return hasConstructorOf(e,p)?v[n]=void 0:void 0!==e&&(v[n]=e),e};hasConstructorOf(a,e)?y.push(a.then((function(e){return i(e)}))):i(a);})),r=v;c.length;){var b=_slicedToArray(c[0],4),d=b[0],_=b[1],O=b[2],j=b[3],m=getByKeyPath(d,_);if(void 0===m)break;O[j]=m,c.splice(0,1);}}if(!f)return r;if("#"===f){var g=getByKeyPath(o,r.slice(1));return void 0===g&&c.push([o,r.slice(1),s,l]),g}return [].concat(f).reduce((function reducer(t,r){return hasConstructorOf(t,e)?t.then((function(e){return reducer(e,r)})):executeReviver(r,t)}),r)}}("",t,null),y.length&&(f=e.resolve(f).then((function(t){return e.all([t].concat(y))})).then((function(e){return _slicedToArray(e,1)[0]})))),isThenable(f)?o&&r.throwOnBadSyncType?function(){throw new TypeError("Sync method requested but async result obtained")}():hasConstructorOf(f,e)?f.p.then(checkUndefined):f:!o&&r.throwOnBadSyncType?function(){throw new TypeError("Async method requested but sync result obtained")}():o?checkUndefined(f):Promise.resolve(checkUndefined(f))}},{key:"reviveSync",value:function reviveSync(e,t){return this.revive(e,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},t),{},{sync:!0}))}},{key:"reviveAsync",value:function reviveAsync(e,t){return this.revive(e,_objectSpread2(_objectSpread2({throwOnBadSyncType:!0},t),{},{sync:!1}))}},{key:"register",value:function register(e,t){var r=this;t=t||{};var n=function R(e){i$1(e)?e.forEach((function(e){return R(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(l.includes(n))throw new TypeError("Plain JSON object types are reserved as type names");var o=e[n],a=o&&o.testPlainObjects?r.plainObjectReplacers:r.nonplainObjectReplacers,c=a.filter((function(e){return e.type===n}));if(c.length&&(a.splice(a.indexOf(c[0]),1),delete r.revivers[n],delete r.types[n]),"function"==typeof o){var s=o;o={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(i$1(o)){var u=_slicedToArray(o,3);o={test:u[0],replace:u[1],revive:u[2]};}if(o&&o.test){var p={type:n,test:o.test.bind(o)};o.replace&&(p.replace=o.replace.bind(o)),o.replaceAsync&&(p.replaceAsync=o.replaceAsync.bind(o));var y="number"==typeof t.fallback?t.fallback:t.fallback?0:Number.POSITIVE_INFINITY;if(o.testPlainObjects?r.plainObjectReplacers.splice(y,0,p):r.nonplainObjectReplacers.splice(y,0,p),o.revive||o.reviveAsync){var f={};o.revive&&(f.revive=o.revive.bind(o)),o.reviveAsync&&(f.reviveAsync=o.reviveAsync.bind(o)),r.revivers[n]=[f,{plain:o.testPlainObjects}];}r.types[n]=o;}}));};return [].concat(e).forEach((function(e){return n(e)})),this}}]),Typeson}(),p=_createClass((function Undefined(){_classCallCheck(this,Undefined);}));p.__typeson__type__="TypesonUndefined";var l=["null","boolean","number","string","array","object"];
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* base64-arraybuffer
|
|
5
|
+
* https://github.com/niklasvh/base64-arraybuffer
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2017 Brett Zamir, 2012 Niklas von Hertzen
|
|
8
|
+
* Licensed under the MIT license.
|
|
9
|
+
*/
|
|
10
|
+
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; // Use a lookup table to find the index.
|
|
11
|
+
|
|
12
|
+
var lookup = new Uint8Array(256);
|
|
13
|
+
|
|
14
|
+
for (var i = 0; i < chars.length; i++) {
|
|
15
|
+
lookup[chars.codePointAt(i)] = i;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @param {ArrayBuffer} arraybuffer
|
|
19
|
+
* @param {Integer} byteOffset
|
|
20
|
+
* @param {Integer} lngth
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
var encode = function encode(arraybuffer, byteOffset, lngth) {
|
|
26
|
+
if (lngth === null || lngth === undefined) {
|
|
27
|
+
lngth = arraybuffer.byteLength; // Needed for Safari
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var bytes = new Uint8Array(arraybuffer, byteOffset || 0, // Default needed for Safari
|
|
31
|
+
lngth);
|
|
32
|
+
var len = bytes.length;
|
|
33
|
+
var base64 = '';
|
|
34
|
+
|
|
35
|
+
for (var _i = 0; _i < len; _i += 3) {
|
|
36
|
+
base64 += chars[bytes[_i] >> 2];
|
|
37
|
+
base64 += chars[(bytes[_i] & 3) << 4 | bytes[_i + 1] >> 4];
|
|
38
|
+
base64 += chars[(bytes[_i + 1] & 15) << 2 | bytes[_i + 2] >> 6];
|
|
39
|
+
base64 += chars[bytes[_i + 2] & 63];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (len % 3 === 2) {
|
|
43
|
+
base64 = base64.slice(0, -1) + '=';
|
|
44
|
+
} else if (len % 3 === 1) {
|
|
45
|
+
base64 = base64.slice(0, -2) + '==';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return base64;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* @param {string} base64
|
|
52
|
+
* @returns {ArrayBuffer}
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
var decode = function decode(base64) {
|
|
56
|
+
var len = base64.length;
|
|
57
|
+
var bufferLength = base64.length * 0.75;
|
|
58
|
+
var p = 0;
|
|
59
|
+
var encoded1, encoded2, encoded3, encoded4;
|
|
60
|
+
|
|
61
|
+
if (base64[base64.length - 1] === '=') {
|
|
62
|
+
bufferLength--;
|
|
63
|
+
|
|
64
|
+
if (base64[base64.length - 2] === '=') {
|
|
65
|
+
bufferLength--;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var arraybuffer = new ArrayBuffer(bufferLength),
|
|
70
|
+
bytes = new Uint8Array(arraybuffer);
|
|
71
|
+
|
|
72
|
+
for (var _i2 = 0; _i2 < len; _i2 += 4) {
|
|
73
|
+
encoded1 = lookup[base64.codePointAt(_i2)];
|
|
74
|
+
encoded2 = lookup[base64.codePointAt(_i2 + 1)];
|
|
75
|
+
encoded3 = lookup[base64.codePointAt(_i2 + 2)];
|
|
76
|
+
encoded4 = lookup[base64.codePointAt(_i2 + 3)];
|
|
77
|
+
bytes[p++] = encoded1 << 2 | encoded2 >> 4;
|
|
78
|
+
bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
|
|
79
|
+
bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return arraybuffer;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const arraybuffer = {
|
|
86
|
+
arraybuffer: {
|
|
87
|
+
test (x) { return toStringTag(x) === 'ArrayBuffer'; },
|
|
88
|
+
replace (b, stateObj) {
|
|
89
|
+
if (!stateObj.buffers) {
|
|
90
|
+
stateObj.buffers = [];
|
|
91
|
+
}
|
|
92
|
+
const index = stateObj.buffers.indexOf(b);
|
|
93
|
+
if (index > -1) {
|
|
94
|
+
return {index};
|
|
95
|
+
}
|
|
96
|
+
stateObj.buffers.push(b);
|
|
97
|
+
return encode(b);
|
|
98
|
+
},
|
|
99
|
+
revive (b64, stateObj) {
|
|
100
|
+
if (!stateObj.buffers) {
|
|
101
|
+
stateObj.buffers = [];
|
|
102
|
+
}
|
|
103
|
+
if (typeof b64 === 'object') {
|
|
104
|
+
return stateObj.buffers[b64.index];
|
|
105
|
+
}
|
|
106
|
+
const buffer = decode(b64);
|
|
107
|
+
stateObj.buffers.push(buffer);
|
|
108
|
+
return buffer;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// See also typed-arrays!
|
|
114
|
+
|
|
115
|
+
/* globals BigInt */
|
|
116
|
+
|
|
117
|
+
const bigintObject = {
|
|
118
|
+
bigintObject: {
|
|
119
|
+
test (x) {
|
|
120
|
+
return typeof x === 'object' && hasConstructorOf(x, BigInt);
|
|
121
|
+
},
|
|
122
|
+
replace: String,
|
|
123
|
+
revive (s) {
|
|
124
|
+
// Filed this to avoid error: https://github.com/eslint/eslint/issues/11810
|
|
125
|
+
// eslint-disable-next-line no-new-object
|
|
126
|
+
return new Object(BigInt(s));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/* globals BigInt */
|
|
132
|
+
|
|
133
|
+
const bigint = {
|
|
134
|
+
bigint: {
|
|
135
|
+
test (x) {
|
|
136
|
+
return typeof x === 'bigint';
|
|
137
|
+
},
|
|
138
|
+
replace: String,
|
|
139
|
+
revive: BigInt
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Not currently in use internally, but provided for parity.
|
|
145
|
+
* @param {ArrayBuffer} buf
|
|
146
|
+
* @returns {Uint8Array}
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
*
|
|
151
|
+
* @param {string} str
|
|
152
|
+
* @returns {ArrayBuffer}
|
|
153
|
+
*/
|
|
154
|
+
function string2arraybuffer (str) {
|
|
155
|
+
/*
|
|
156
|
+
// UTF-8 approaches
|
|
157
|
+
const utf8 = unescape(encodeURIComponent(str));
|
|
158
|
+
const arr = new Uint8Array(utf8.length);
|
|
159
|
+
for (let i = 0; i < utf8.length; i++) {
|
|
160
|
+
arr[i] = utf8.charCodeAt(i);
|
|
161
|
+
}
|
|
162
|
+
return arr.buffer;
|
|
163
|
+
|
|
164
|
+
const utf8 = [];
|
|
165
|
+
for (let i = 0; i < str.length; i++) {
|
|
166
|
+
let charcode = str.charCodeAt(i);
|
|
167
|
+
if (charcode < 0x80) utf8.push(charcode);
|
|
168
|
+
else if (charcode < 0x800) {
|
|
169
|
+
utf8.push(0xc0 | (charcode >> 6),
|
|
170
|
+
0x80 | (charcode & 0x3f));
|
|
171
|
+
} else if (charcode < 0xd800 || charcode >= 0xe000) {
|
|
172
|
+
utf8.push(0xe0 | (charcode >> 12),
|
|
173
|
+
0x80 | ((charcode >> 6) & 0x3f),
|
|
174
|
+
0x80 | (charcode & 0x3f));
|
|
175
|
+
// surrogate pair
|
|
176
|
+
} else {
|
|
177
|
+
i++;
|
|
178
|
+
// UTF-16 encodes 0x10000-0x10FFFF by
|
|
179
|
+
// subtracting 0x10000 and splitting the
|
|
180
|
+
// 20 bits of 0x0-0xFFFFF into two halves
|
|
181
|
+
charcode = 0x10000 + (((charcode & 0x3ff) << 10) |
|
|
182
|
+
(str.charCodeAt(i) & 0x3ff));
|
|
183
|
+
utf8.push(0xf0 | (charcode >> 18),
|
|
184
|
+
0x80 | ((charcode >> 12) & 0x3f),
|
|
185
|
+
0x80 | ((charcode >> 6) & 0x3f),
|
|
186
|
+
0x80 | (charcode & 0x3f));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return utf8;
|
|
190
|
+
*/
|
|
191
|
+
/*
|
|
192
|
+
// Working UTF-16 options (equivalents)
|
|
193
|
+
const buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char
|
|
194
|
+
const bufView = new Uint16Array(buf);
|
|
195
|
+
for (let i = 0, strLen = str.length; i < strLen; i++) {
|
|
196
|
+
bufView[i] = str.charCodeAt(i);
|
|
197
|
+
}
|
|
198
|
+
return buf;
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
const array = new Uint8Array(str.length);
|
|
202
|
+
for (let i = 0; i < str.length; i++) {
|
|
203
|
+
// eslint-disable-next-line max-len -- Long
|
|
204
|
+
// eslint-disable-next-line unicorn/prefer-code-point -- Iterating char. codes
|
|
205
|
+
array[i] = str.charCodeAt(i); // & 0xff;
|
|
206
|
+
}
|
|
207
|
+
return array.buffer;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/* globals XMLHttpRequest, Blob, FileReader */
|
|
211
|
+
|
|
212
|
+
const blob = {
|
|
213
|
+
blob: {
|
|
214
|
+
test (x) { return toStringTag(x) === 'Blob'; },
|
|
215
|
+
replace (b) { // Sync
|
|
216
|
+
const req = new XMLHttpRequest();
|
|
217
|
+
req.overrideMimeType('text/plain; charset=x-user-defined');
|
|
218
|
+
req.open('GET', URL.createObjectURL(b), false); // Sync
|
|
219
|
+
req.send();
|
|
220
|
+
|
|
221
|
+
// Seems not feasible to accurately simulate
|
|
222
|
+
/* c8 ignore next 3 */
|
|
223
|
+
if (req.status !== 200 && req.status !== 0) {
|
|
224
|
+
throw new Error('Bad Blob access: ' + req.status);
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
type: b.type,
|
|
228
|
+
stringContents: req.responseText
|
|
229
|
+
};
|
|
230
|
+
},
|
|
231
|
+
revive ({type, stringContents}) {
|
|
232
|
+
return new Blob([string2arraybuffer(stringContents)], {type});
|
|
233
|
+
},
|
|
234
|
+
replaceAsync (b) {
|
|
235
|
+
return new e((resolve, reject) => {
|
|
236
|
+
/*
|
|
237
|
+
if (b.isClosed) { // On MDN, but not in https://w3c.github.io/FileAPI/#dfn-Blob
|
|
238
|
+
reject(new Error('The Blob is closed'));
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
*/
|
|
242
|
+
const reader = new FileReader();
|
|
243
|
+
reader.addEventListener('load', () => {
|
|
244
|
+
resolve({
|
|
245
|
+
type: b.type,
|
|
246
|
+
stringContents: reader.result
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
// Seems not feasible to accurately simulate
|
|
250
|
+
/* c8 ignore next 3 */
|
|
251
|
+
reader.addEventListener('error', () => {
|
|
252
|
+
reject(reader.error);
|
|
253
|
+
});
|
|
254
|
+
reader.readAsBinaryString(b);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/* globals performance */
|
|
261
|
+
|
|
262
|
+
// The `performance` global is optional
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @todo We could use `import generateUUID from 'uuid/v4';` (but it needs
|
|
266
|
+
* crypto library, etc.; `rollup-plugin-node-builtins` doesn't recommend
|
|
267
|
+
* using its own version and though there is <https://www.npmjs.com/package/crypto-browserify>,
|
|
268
|
+
* it may be troublesome to bundle and not strongly needed)
|
|
269
|
+
* @returns {string}
|
|
270
|
+
*/
|
|
271
|
+
function generateUUID () { // Adapted from original: public domain/MIT: http://stackoverflow.com/a/8809472/271577
|
|
272
|
+
/* c8 ignore next */
|
|
273
|
+
let d = Date.now() +
|
|
274
|
+
// use high-precision timer if available
|
|
275
|
+
/* c8 ignore next 4 */
|
|
276
|
+
(typeof performance !== 'undefined' &&
|
|
277
|
+
typeof performance.now === 'function'
|
|
278
|
+
? performance.now()
|
|
279
|
+
: 0);
|
|
280
|
+
|
|
281
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/gu, function (c) {
|
|
282
|
+
/* eslint-disable no-bitwise */
|
|
283
|
+
const r = Math.trunc((d + Math.random() * 16) % 16);
|
|
284
|
+
d = Math.floor(d / 16);
|
|
285
|
+
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
|
|
286
|
+
/* eslint-enable no-bitwise */
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const cloneableObjectsByUUID = {};
|
|
291
|
+
|
|
292
|
+
const cloneable = {
|
|
293
|
+
cloneable: {
|
|
294
|
+
test (x) {
|
|
295
|
+
return x && typeof x === 'object' &&
|
|
296
|
+
typeof x[Symbol.for('cloneEncapsulate')] === 'function';
|
|
297
|
+
},
|
|
298
|
+
replace (clonable) {
|
|
299
|
+
const encapsulated = clonable[Symbol.for('cloneEncapsulate')]();
|
|
300
|
+
const uuid = generateUUID();
|
|
301
|
+
cloneableObjectsByUUID[uuid] = clonable;
|
|
302
|
+
return {uuid, encapsulated};
|
|
303
|
+
},
|
|
304
|
+
revive ({uuid, encapsulated}) {
|
|
305
|
+
return cloneableObjectsByUUID[uuid][Symbol.for('cloneRevive')](
|
|
306
|
+
encapsulated
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/* globals crypto */
|
|
313
|
+
|
|
314
|
+
const cryptokey = {
|
|
315
|
+
cryptokey: {
|
|
316
|
+
test (x) {
|
|
317
|
+
return toStringTag(x) === 'CryptoKey' && x.extractable;
|
|
318
|
+
},
|
|
319
|
+
replaceAsync (key) {
|
|
320
|
+
return new e(async (resolve, reject) => {
|
|
321
|
+
let jwk;
|
|
322
|
+
try {
|
|
323
|
+
jwk = await crypto.subtle.exportKey('jwk', key);
|
|
324
|
+
// Our format should be valid and our key extractable
|
|
325
|
+
/* c8 ignore next 4 */
|
|
326
|
+
} catch (err) {
|
|
327
|
+
reject(err);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
resolve({
|
|
331
|
+
jwk,
|
|
332
|
+
algorithm: key.algorithm,
|
|
333
|
+
usages: key.usages
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
},
|
|
337
|
+
revive ({jwk, algorithm, usages}) {
|
|
338
|
+
return crypto.subtle.importKey('jwk', jwk, algorithm, true, usages);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const dataview = {
|
|
344
|
+
dataview: {
|
|
345
|
+
test (x) { return toStringTag(x) === 'DataView'; },
|
|
346
|
+
replace ({buffer, byteOffset, byteLength}, stateObj) {
|
|
347
|
+
if (!stateObj.buffers) {
|
|
348
|
+
stateObj.buffers = [];
|
|
349
|
+
}
|
|
350
|
+
const index = stateObj.buffers.indexOf(buffer);
|
|
351
|
+
if (index > -1) {
|
|
352
|
+
return {index, byteOffset, byteLength};
|
|
353
|
+
}
|
|
354
|
+
stateObj.buffers.push(buffer);
|
|
355
|
+
return {
|
|
356
|
+
encoded: encode(buffer),
|
|
357
|
+
byteOffset,
|
|
358
|
+
byteLength
|
|
359
|
+
};
|
|
360
|
+
},
|
|
361
|
+
revive (b64Obj, stateObj) {
|
|
362
|
+
if (!stateObj.buffers) {
|
|
363
|
+
stateObj.buffers = [];
|
|
364
|
+
}
|
|
365
|
+
const {byteOffset, byteLength, encoded, index} = b64Obj;
|
|
366
|
+
let buffer;
|
|
367
|
+
if ('index' in b64Obj) {
|
|
368
|
+
buffer = stateObj.buffers[index];
|
|
369
|
+
} else {
|
|
370
|
+
buffer = decode(encoded);
|
|
371
|
+
stateObj.buffers.push(buffer);
|
|
372
|
+
}
|
|
373
|
+
return new DataView(buffer, byteOffset, byteLength);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
const date = {
|
|
379
|
+
date: {
|
|
380
|
+
test (x) { return toStringTag(x) === 'Date'; },
|
|
381
|
+
replace (dt) {
|
|
382
|
+
const time = dt.getTime();
|
|
383
|
+
if (Number.isNaN(time)) {
|
|
384
|
+
return 'NaN';
|
|
385
|
+
}
|
|
386
|
+
return time;
|
|
387
|
+
},
|
|
388
|
+
revive (time) {
|
|
389
|
+
if (time === 'NaN') {
|
|
390
|
+
return new Date(Number.NaN);
|
|
391
|
+
}
|
|
392
|
+
return new Date(time);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
const error = {
|
|
398
|
+
error: {
|
|
399
|
+
test (x) { return toStringTag(x) === 'Error'; },
|
|
400
|
+
replace ({
|
|
401
|
+
name, message, cause, stack, fileName, lineNumber, columnNumber
|
|
402
|
+
}) {
|
|
403
|
+
return {
|
|
404
|
+
name, message, cause, stack, fileName, lineNumber, columnNumber
|
|
405
|
+
};
|
|
406
|
+
},
|
|
407
|
+
revive (obj) {
|
|
408
|
+
const e = new Error(obj.message);
|
|
409
|
+
[
|
|
410
|
+
'name', 'cause', 'stack', 'fileName', 'lineNumber',
|
|
411
|
+
'columnNumber'
|
|
412
|
+
].forEach((prop) => {
|
|
413
|
+
e[prop] = obj[prop];
|
|
414
|
+
});
|
|
415
|
+
return e;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
/* globals InternalError */
|
|
421
|
+
|
|
422
|
+
const errors = {};
|
|
423
|
+
|
|
424
|
+
// JS standard
|
|
425
|
+
[
|
|
426
|
+
TypeError, RangeError, SyntaxError, ReferenceError, EvalError, URIError
|
|
427
|
+
].forEach((error) => create$2(error));
|
|
428
|
+
|
|
429
|
+
/* c8 ignore next 3 */
|
|
430
|
+
if (typeof AggregateError !== 'undefined') {
|
|
431
|
+
create$2(AggregateError);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/* c8 ignore next 2 */
|
|
435
|
+
// @ts-ignore Non-standard
|
|
436
|
+
typeof InternalError === 'function' && create$2(InternalError);
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Comprises all built-in errors.
|
|
440
|
+
* @param {
|
|
441
|
+
* TypeError|RangeError|SyntaxError|ReferenceError|EvalError|URIError|
|
|
442
|
+
* AggregateError|InternalError
|
|
443
|
+
* } Ctor
|
|
444
|
+
* @returns {void}
|
|
445
|
+
*/
|
|
446
|
+
function create$2 (Ctor) {
|
|
447
|
+
errors[Ctor.name.toLowerCase()] = {
|
|
448
|
+
test (x) { return hasConstructorOf(x, Ctor); },
|
|
449
|
+
replace ({
|
|
450
|
+
name, message, cause, stack, fileName,
|
|
451
|
+
lineNumber, columnNumber, errors: errs
|
|
452
|
+
}) {
|
|
453
|
+
return {
|
|
454
|
+
name, message, cause, stack, fileName,
|
|
455
|
+
lineNumber, columnNumber, errors: errs
|
|
456
|
+
};
|
|
457
|
+
},
|
|
458
|
+
revive (obj) {
|
|
459
|
+
const isAggregateError = typeof AggregateError !== 'undefined' &&
|
|
460
|
+
Ctor === AggregateError;
|
|
461
|
+
const e = isAggregateError
|
|
462
|
+
? new Ctor(obj.errors, obj.message)
|
|
463
|
+
: new Ctor(obj.message);
|
|
464
|
+
[
|
|
465
|
+
'name', 'cause', 'stack', 'fileName', 'lineNumber',
|
|
466
|
+
'columnNumber'
|
|
467
|
+
].forEach((prop) => {
|
|
468
|
+
e[prop] = obj[prop];
|
|
469
|
+
});
|
|
470
|
+
/* c8 ignore next 6 */
|
|
471
|
+
if (isAggregateError) {
|
|
472
|
+
e.errors = obj.errors;
|
|
473
|
+
}
|
|
474
|
+
return e;
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/* globals XMLHttpRequest, File, FileReader */
|
|
480
|
+
|
|
481
|
+
const file = {
|
|
482
|
+
file: {
|
|
483
|
+
test (x) { return toStringTag(x) === 'File'; },
|
|
484
|
+
replace (f) { // Sync
|
|
485
|
+
const req = new XMLHttpRequest();
|
|
486
|
+
req.overrideMimeType('text/plain; charset=x-user-defined');
|
|
487
|
+
req.open('GET', URL.createObjectURL(f), false); // Sync
|
|
488
|
+
req.send();
|
|
489
|
+
|
|
490
|
+
// Seems not feasible to accurately simulate
|
|
491
|
+
/* c8 ignore next 3 */
|
|
492
|
+
if (req.status !== 200 && req.status !== 0) {
|
|
493
|
+
throw new Error('Bad File access: ' + req.status);
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
type: f.type,
|
|
497
|
+
stringContents: req.responseText,
|
|
498
|
+
name: f.name,
|
|
499
|
+
lastModified: f.lastModified
|
|
500
|
+
};
|
|
501
|
+
},
|
|
502
|
+
revive ({name, type, stringContents, lastModified}) {
|
|
503
|
+
return new File([string2arraybuffer(stringContents)], name, {
|
|
504
|
+
type,
|
|
505
|
+
lastModified
|
|
506
|
+
});
|
|
507
|
+
},
|
|
508
|
+
replaceAsync (f) {
|
|
509
|
+
return new e(function (resolve, reject) {
|
|
510
|
+
/*
|
|
511
|
+
if (f.isClosed) { // On MDN, but not in https://w3c.github.io/FileAPI/#dfn-Blob
|
|
512
|
+
reject(new Error('The File is closed'));
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
*/
|
|
516
|
+
const reader = new FileReader();
|
|
517
|
+
reader.addEventListener('load', function () {
|
|
518
|
+
resolve({
|
|
519
|
+
type: f.type,
|
|
520
|
+
stringContents: reader.result,
|
|
521
|
+
name: f.name,
|
|
522
|
+
lastModified: f.lastModified
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
// Seems not feasible to accurately simulate
|
|
526
|
+
/* c8 ignore next 3 */
|
|
527
|
+
reader.addEventListener('error', function () {
|
|
528
|
+
reject(reader.error);
|
|
529
|
+
});
|
|
530
|
+
reader.readAsBinaryString(f);
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
const filelist = {
|
|
537
|
+
file: file.file,
|
|
538
|
+
filelist: {
|
|
539
|
+
test (x) { return toStringTag(x) === 'FileList'; },
|
|
540
|
+
replace (fl) {
|
|
541
|
+
const arr = [];
|
|
542
|
+
for (let i = 0; i < fl.length; i++) {
|
|
543
|
+
arr[i] = fl.item(i);
|
|
544
|
+
}
|
|
545
|
+
return arr;
|
|
546
|
+
},
|
|
547
|
+
revive (o) {
|
|
548
|
+
/**
|
|
549
|
+
* `FileList` polyfill.
|
|
550
|
+
*/
|
|
551
|
+
class FileList {
|
|
552
|
+
/**
|
|
553
|
+
* Set private properties and length.
|
|
554
|
+
*/
|
|
555
|
+
constructor () {
|
|
556
|
+
// eslint-disable-next-line prefer-rest-params
|
|
557
|
+
this._files = arguments[0];
|
|
558
|
+
this.length = this._files.length;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* @param {Integer} index
|
|
562
|
+
* @returns {File}
|
|
563
|
+
*/
|
|
564
|
+
item (index) {
|
|
565
|
+
return this._files[index];
|
|
566
|
+
}
|
|
567
|
+
/* eslint-disable class-methods-use-this */
|
|
568
|
+
/**
|
|
569
|
+
* @returns {"FileList"}
|
|
570
|
+
*/
|
|
571
|
+
get [Symbol.toStringTag] () {
|
|
572
|
+
/* eslint-enable class-methods-use-this */
|
|
573
|
+
return 'FileList';
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
return new FileList(o);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
/* globals createImageBitmap */
|
|
582
|
+
|
|
583
|
+
const imagebitmap = {
|
|
584
|
+
imagebitmap: {
|
|
585
|
+
test (x) {
|
|
586
|
+
return toStringTag(x) === 'ImageBitmap' ||
|
|
587
|
+
// In Node, our polyfill sets the dataset on a canvas
|
|
588
|
+
// element as JSDom no longer allows overriding toStringTag
|
|
589
|
+
(x && x.dataset && x.dataset.toStringTag === 'ImageBitmap');
|
|
590
|
+
},
|
|
591
|
+
replace (bm) {
|
|
592
|
+
const canvas = document.createElement('canvas');
|
|
593
|
+
const ctx = canvas.getContext('2d');
|
|
594
|
+
ctx.drawImage(bm, 0, 0);
|
|
595
|
+
// Although `width` and `height` are part of `ImageBitMap`,
|
|
596
|
+
// these will be auto-created for us when reviving with the
|
|
597
|
+
// data URL (and they are not settable even if they weren't)
|
|
598
|
+
// return {
|
|
599
|
+
// width: bm.width, height: bm.height, dataURL: canvas.toDataURL()
|
|
600
|
+
// };
|
|
601
|
+
return canvas.toDataURL();
|
|
602
|
+
},
|
|
603
|
+
revive (o) {
|
|
604
|
+
/*
|
|
605
|
+
var req = new XMLHttpRequest();
|
|
606
|
+
req.open('GET', o, false); // Sync
|
|
607
|
+
if (req.status !== 200 && req.status !== 0) {
|
|
608
|
+
throw new Error('Bad ImageBitmap access: ' + req.status);
|
|
609
|
+
}
|
|
610
|
+
req.send();
|
|
611
|
+
return req.responseText;
|
|
612
|
+
*/
|
|
613
|
+
const canvas = document.createElement('canvas');
|
|
614
|
+
const ctx = canvas.getContext('2d');
|
|
615
|
+
const img = document.createElement('img');
|
|
616
|
+
// The onload is needed by some browsers per http://stackoverflow.com/a/4776378/271577
|
|
617
|
+
img.addEventListener('load', function () {
|
|
618
|
+
ctx.drawImage(img, 0, 0);
|
|
619
|
+
});
|
|
620
|
+
img.src = o;
|
|
621
|
+
// Works in contexts allowing an `ImageBitmap` (We might use
|
|
622
|
+
// `OffscreenCanvas.transferToBitmap` when supported)
|
|
623
|
+
return canvas;
|
|
624
|
+
},
|
|
625
|
+
reviveAsync (o) {
|
|
626
|
+
const canvas = document.createElement('canvas');
|
|
627
|
+
const ctx = canvas.getContext('2d');
|
|
628
|
+
const img = document.createElement('img');
|
|
629
|
+
// The onload is needed by some browsers per http://stackoverflow.com/a/4776378/271577
|
|
630
|
+
img.addEventListener('load', function () {
|
|
631
|
+
ctx.drawImage(img, 0, 0);
|
|
632
|
+
});
|
|
633
|
+
img.src = o; // o.dataURL;
|
|
634
|
+
return createImageBitmap(canvas); // Returns a promise
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
/* globals ImageData */
|
|
640
|
+
|
|
641
|
+
const imagedata = {
|
|
642
|
+
imagedata: {
|
|
643
|
+
test (x) { return toStringTag(x) === 'ImageData'; },
|
|
644
|
+
replace (d) {
|
|
645
|
+
return {
|
|
646
|
+
// Ensure `length` gets preserved for revival
|
|
647
|
+
array: [...d.data],
|
|
648
|
+
width: d.width,
|
|
649
|
+
height: d.height
|
|
650
|
+
};
|
|
651
|
+
},
|
|
652
|
+
revive (o) {
|
|
653
|
+
return new ImageData(
|
|
654
|
+
new Uint8ClampedArray(o.array), o.width, o.height
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
const infinity = {
|
|
661
|
+
infinity: {
|
|
662
|
+
test (x) { return x === Number.POSITIVE_INFINITY; },
|
|
663
|
+
replace (n) { return 'Infinity'; },
|
|
664
|
+
revive (s) { return Number.POSITIVE_INFINITY; }
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
const IntlCollator = {
|
|
669
|
+
test (x) { return hasConstructorOf(x, Intl.Collator); },
|
|
670
|
+
replace (c) { return c.resolvedOptions(); },
|
|
671
|
+
revive (options) { return new Intl.Collator(options.locale, options); }
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
const IntlDateTimeFormat = {
|
|
675
|
+
test (x) { return hasConstructorOf(x, Intl.DateTimeFormat); },
|
|
676
|
+
replace (dtf) { return dtf.resolvedOptions(); },
|
|
677
|
+
revive (options) {
|
|
678
|
+
return new Intl.DateTimeFormat(options.locale, options);
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
const IntlNumberFormat = {
|
|
683
|
+
test (x) { return hasConstructorOf(x, Intl.NumberFormat); },
|
|
684
|
+
replace (nf) { return nf.resolvedOptions(); },
|
|
685
|
+
revive (options) { return new Intl.NumberFormat(options.locale, options); }
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
const intlTypes = {
|
|
689
|
+
IntlCollator,
|
|
690
|
+
IntlDateTimeFormat,
|
|
691
|
+
IntlNumberFormat
|
|
692
|
+
};
|
|
693
|
+
|
|
694
|
+
const map = {
|
|
695
|
+
map: {
|
|
696
|
+
test (x) { return toStringTag(x) === 'Map'; },
|
|
697
|
+
replace (mp) { return [...mp.entries()]; },
|
|
698
|
+
revive (entries) { return new Map(entries); }
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
const nan = {
|
|
703
|
+
nan: {
|
|
704
|
+
test (x) { return Number.isNaN(x); },
|
|
705
|
+
replace (n) { return 'NaN'; },
|
|
706
|
+
revive (s) { return Number.NaN; }
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
const negativeInfinity = {
|
|
711
|
+
negativeInfinity: {
|
|
712
|
+
test (x) { return x === Number.NEGATIVE_INFINITY; },
|
|
713
|
+
replace (n) { return '-Infinity'; },
|
|
714
|
+
revive (s) { return Number.NEGATIVE_INFINITY; }
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
const nonbuiltinIgnore = {
|
|
719
|
+
nonbuiltinIgnore: {
|
|
720
|
+
test (x) {
|
|
721
|
+
return x && typeof x === 'object' && !Array.isArray(x) && ![
|
|
722
|
+
'Object',
|
|
723
|
+
// `Proxy` and `Reflect`, two other built-in objects, will also
|
|
724
|
+
// have a `toStringTag` of `Object`; we don't want built-in
|
|
725
|
+
// function objects, however
|
|
726
|
+
'Boolean', 'Number', 'String',
|
|
727
|
+
'Error', 'RegExp', 'Math', 'Date',
|
|
728
|
+
'Map', 'Set',
|
|
729
|
+
'JSON',
|
|
730
|
+
'ArrayBuffer', 'SharedArrayBuffer', 'DataView',
|
|
731
|
+
'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array',
|
|
732
|
+
'Uint16Array', 'Int32Array', 'Uint32Array',
|
|
733
|
+
'Float32Array', 'Float64Array',
|
|
734
|
+
'Promise',
|
|
735
|
+
'String Iterator', 'Array Iterator',
|
|
736
|
+
'Map Iterator', 'Set Iterator',
|
|
737
|
+
'WeakMap', 'WeakSet',
|
|
738
|
+
'Atomics', 'Module'
|
|
739
|
+
].includes(toStringTag(x));
|
|
740
|
+
},
|
|
741
|
+
replace (rexp) {
|
|
742
|
+
// Not in use
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
// This module is for objectified primitives (such as `new Number(3)` or
|
|
748
|
+
|
|
749
|
+
const primitiveObjects = {
|
|
750
|
+
// String Object (not primitive string which need no type spec)
|
|
751
|
+
StringObject: {
|
|
752
|
+
test (x) {
|
|
753
|
+
return toStringTag(x) === 'String' && typeof x === 'object';
|
|
754
|
+
},
|
|
755
|
+
replace: String, // convert to primitive string
|
|
756
|
+
revive (s) { return new String(s); } // Revive to an objectified string
|
|
757
|
+
},
|
|
758
|
+
// Boolean Object (not primitive boolean which need no type spec)
|
|
759
|
+
BooleanObject: {
|
|
760
|
+
test (x) {
|
|
761
|
+
return toStringTag(x) === 'Boolean' &&
|
|
762
|
+
typeof x === 'object';
|
|
763
|
+
},
|
|
764
|
+
replace: Boolean, // convert to primitive boolean
|
|
765
|
+
revive (b) {
|
|
766
|
+
// Revive to an objectified Boolean
|
|
767
|
+
return new Boolean(b);
|
|
768
|
+
}
|
|
769
|
+
},
|
|
770
|
+
// Number Object (not primitive number which need no type spec)
|
|
771
|
+
NumberObject: {
|
|
772
|
+
test (x) {
|
|
773
|
+
return toStringTag(x) === 'Number' && typeof x === 'object';
|
|
774
|
+
},
|
|
775
|
+
replace: Number, // convert to primitive number
|
|
776
|
+
revive (n) { return new Number(n); } // Revive to an objectified number
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
const regexp = {
|
|
781
|
+
regexp: {
|
|
782
|
+
test (x) { return toStringTag(x) === 'RegExp'; },
|
|
783
|
+
replace (rexp) {
|
|
784
|
+
return {
|
|
785
|
+
source: rexp.source,
|
|
786
|
+
flags: (rexp.global ? 'g' : '') +
|
|
787
|
+
(rexp.ignoreCase ? 'i' : '') +
|
|
788
|
+
(rexp.multiline ? 'm' : '') +
|
|
789
|
+
(rexp.sticky ? 'y' : '') +
|
|
790
|
+
(rexp.unicode ? 'u' : '')
|
|
791
|
+
};
|
|
792
|
+
},
|
|
793
|
+
revive ({source, flags}) { return new RegExp(source, flags); }
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
|
|
797
|
+
// Here we allow the exact same non-plain object, function, and symbol
|
|
798
|
+
|
|
799
|
+
const resurrectableObjectsByUUID = {};
|
|
800
|
+
|
|
801
|
+
const resurrectable = {
|
|
802
|
+
resurrectable: {
|
|
803
|
+
test (x) {
|
|
804
|
+
return x &&
|
|
805
|
+
!Array.isArray(x) &&
|
|
806
|
+
['object', 'function', 'symbol'].includes(typeof x);
|
|
807
|
+
},
|
|
808
|
+
replace (rsrrctble) {
|
|
809
|
+
const uuid = generateUUID();
|
|
810
|
+
resurrectableObjectsByUUID[uuid] = rsrrctble;
|
|
811
|
+
return uuid;
|
|
812
|
+
},
|
|
813
|
+
revive (serializedResurrectable) {
|
|
814
|
+
return resurrectableObjectsByUUID[serializedResurrectable];
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
const set = {
|
|
820
|
+
set: {
|
|
821
|
+
test (x) { return toStringTag(x) === 'Set'; },
|
|
822
|
+
replace (st) {
|
|
823
|
+
return [...st.values()];
|
|
824
|
+
},
|
|
825
|
+
revive (values) { return new Set(values); }
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
/* eslint-env browser, node */
|
|
830
|
+
|
|
831
|
+
// Support all kinds of typed arrays (views of ArrayBuffers)
|
|
832
|
+
const typedArraysSocketIO = {};
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* @param {
|
|
836
|
+
* Int8Array|Uint8Array|Uint8ClampedArray|Int16Array|Uint16Array|Int32Array|
|
|
837
|
+
* Uint32Array|Float32Array|Float64Array
|
|
838
|
+
* } TypedArray
|
|
839
|
+
* @returns {void}
|
|
840
|
+
*/
|
|
841
|
+
function create$1 (TypedArray) {
|
|
842
|
+
const typeName = TypedArray.name;
|
|
843
|
+
typedArraysSocketIO[typeName.toLowerCase()] = {
|
|
844
|
+
test (x) { return toStringTag(x) === typeName; },
|
|
845
|
+
replace (a) {
|
|
846
|
+
return (a.byteOffset === 0 &&
|
|
847
|
+
a.byteLength === a.buffer.byteLength
|
|
848
|
+
? a
|
|
849
|
+
// socket.io supports streaming ArrayBuffers.
|
|
850
|
+
// If we have a typed array representing a portion
|
|
851
|
+
// of the buffer, we need to clone
|
|
852
|
+
// the buffer before leaving it to socket.io.
|
|
853
|
+
: a.slice(0)).buffer;
|
|
854
|
+
},
|
|
855
|
+
revive (buf) {
|
|
856
|
+
// One may configure socket.io to revive binary data as
|
|
857
|
+
// Buffer or Blob.
|
|
858
|
+
// We should therefore not rely on that the instance we
|
|
859
|
+
// get here is an ArrayBuffer
|
|
860
|
+
// If not, let's assume user wants to receive it as
|
|
861
|
+
// configured with socket.io.
|
|
862
|
+
return toStringTag(buf) === 'ArrayBuffer'
|
|
863
|
+
? new TypedArray(buf)
|
|
864
|
+
: buf;
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
if (typeof Int8Array === 'function') {
|
|
870
|
+
// Those constructors are added in ES6 as a group.
|
|
871
|
+
// If we have Int8Array, we can assume the rest also exists.
|
|
872
|
+
|
|
873
|
+
[
|
|
874
|
+
Int8Array,
|
|
875
|
+
Uint8Array,
|
|
876
|
+
Uint8ClampedArray,
|
|
877
|
+
Int16Array,
|
|
878
|
+
Uint16Array,
|
|
879
|
+
Int32Array,
|
|
880
|
+
Uint32Array,
|
|
881
|
+
Float32Array,
|
|
882
|
+
Float64Array
|
|
883
|
+
].forEach((TypedArray) => create$1(TypedArray));
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/* eslint-env browser, node */
|
|
887
|
+
|
|
888
|
+
const typedArrays = {};
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* @param {
|
|
892
|
+
* Int8Array|Uint8Array|Uint8ClampedArray|Int16Array|Uint16Array|Int32Array|
|
|
893
|
+
* Uint32Array|Float32Array|Float64Array
|
|
894
|
+
* } TypedArray
|
|
895
|
+
* @returns {void}
|
|
896
|
+
*/
|
|
897
|
+
function create (TypedArray) {
|
|
898
|
+
const typeName = TypedArray.name;
|
|
899
|
+
typedArrays[typeName.toLowerCase()] = {
|
|
900
|
+
test (x) { return toStringTag(x) === typeName; },
|
|
901
|
+
replace ({buffer, byteOffset, length: l}, stateObj) {
|
|
902
|
+
if (!stateObj.buffers) {
|
|
903
|
+
stateObj.buffers = [];
|
|
904
|
+
}
|
|
905
|
+
const index = stateObj.buffers.indexOf(buffer);
|
|
906
|
+
if (index > -1) {
|
|
907
|
+
return {index, byteOffset, length: l};
|
|
908
|
+
}
|
|
909
|
+
stateObj.buffers.push(buffer);
|
|
910
|
+
return {
|
|
911
|
+
encoded: encode(buffer),
|
|
912
|
+
byteOffset,
|
|
913
|
+
length: l
|
|
914
|
+
};
|
|
915
|
+
},
|
|
916
|
+
revive (b64Obj, stateObj) {
|
|
917
|
+
if (!stateObj.buffers) {
|
|
918
|
+
stateObj.buffers = [];
|
|
919
|
+
}
|
|
920
|
+
const {byteOffset, length: len, encoded, index} = b64Obj;
|
|
921
|
+
let buffer;
|
|
922
|
+
if ('index' in b64Obj) {
|
|
923
|
+
buffer = stateObj.buffers[index];
|
|
924
|
+
} else {
|
|
925
|
+
buffer = decode(encoded);
|
|
926
|
+
stateObj.buffers.push(buffer);
|
|
927
|
+
}
|
|
928
|
+
return new TypedArray(buffer, byteOffset, len);
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
if (typeof Int8Array === 'function') {
|
|
934
|
+
// Those constructors are added in ES6 as a group.
|
|
935
|
+
// If we have Int8Array, we can assume the rest also exists.
|
|
936
|
+
[
|
|
937
|
+
Int8Array,
|
|
938
|
+
Uint8Array,
|
|
939
|
+
Uint8ClampedArray,
|
|
940
|
+
Int16Array,
|
|
941
|
+
Uint16Array,
|
|
942
|
+
Int32Array,
|
|
943
|
+
Uint32Array,
|
|
944
|
+
Float32Array,
|
|
945
|
+
Float64Array
|
|
946
|
+
].forEach((TypedArray) => create(TypedArray));
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
// This does not preserve `undefined` in sparse arrays; see the `undef`
|
|
950
|
+
|
|
951
|
+
const undef$1 = {
|
|
952
|
+
undef: {
|
|
953
|
+
test (x, stateObj) {
|
|
954
|
+
return typeof x === 'undefined' &&
|
|
955
|
+
(stateObj.ownKeys || !('ownKeys' in stateObj));
|
|
956
|
+
},
|
|
957
|
+
replace (n) { return 0; },
|
|
958
|
+
revive (s) {
|
|
959
|
+
// Will add `undefined` (returning `undefined` would instead
|
|
960
|
+
// avoid explicitly setting)
|
|
961
|
+
return new p();
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
const userObject = {
|
|
967
|
+
userObject: {
|
|
968
|
+
test (x, stateObj) { return isUserObject(x); },
|
|
969
|
+
replace (n) { return {...n}; },
|
|
970
|
+
revive (s) { return s; }
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
const arrayNonindexKeys = [
|
|
975
|
+
{
|
|
976
|
+
arrayNonindexKeys: {
|
|
977
|
+
testPlainObjects: true,
|
|
978
|
+
test (x, stateObj) {
|
|
979
|
+
if (Array.isArray(x)) {
|
|
980
|
+
if (
|
|
981
|
+
// By avoiding serializing arrays into objects which
|
|
982
|
+
// have only positive-integer keys, we reduce
|
|
983
|
+
// size and improve revival performance; arrays with
|
|
984
|
+
// non-index keys will be larger however
|
|
985
|
+
Object.keys(x).some((k) => {
|
|
986
|
+
// No need to check for `isNaN` or
|
|
987
|
+
// `isNaN(Number.parseInt())` as `NaN` will be
|
|
988
|
+
// treated as a string.
|
|
989
|
+
// No need to do check as
|
|
990
|
+
// `Number.parseInt(Number())` since scientific
|
|
991
|
+
// notation will be pre-resolved if a number
|
|
992
|
+
// was given, and it will otherwise be a string
|
|
993
|
+
return String(Number.parseInt(k)) !== k;
|
|
994
|
+
})
|
|
995
|
+
) {
|
|
996
|
+
stateObj.iterateIn = 'object';
|
|
997
|
+
stateObj.addLength = true;
|
|
998
|
+
}
|
|
999
|
+
return true;
|
|
1000
|
+
}
|
|
1001
|
+
return false;
|
|
1002
|
+
},
|
|
1003
|
+
replace (a, stateObj) {
|
|
1004
|
+
// Catch sparse undefined
|
|
1005
|
+
stateObj.iterateUnsetNumeric = true;
|
|
1006
|
+
return a;
|
|
1007
|
+
},
|
|
1008
|
+
revive (o) {
|
|
1009
|
+
if (Array.isArray(o)) {
|
|
1010
|
+
return o;
|
|
1011
|
+
}
|
|
1012
|
+
const arr = [];
|
|
1013
|
+
// No map here as may be a sparse array (including
|
|
1014
|
+
// with `length` set)
|
|
1015
|
+
// Todo: Reenable when Node `engines` >= 7
|
|
1016
|
+
// Object.entries(o).forEach(([key, val]) => {
|
|
1017
|
+
Object.keys(o).forEach((key) => {
|
|
1018
|
+
const val = o[key];
|
|
1019
|
+
arr[key] = val;
|
|
1020
|
+
});
|
|
1021
|
+
return arr;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
},
|
|
1025
|
+
{
|
|
1026
|
+
sparseUndefined: {
|
|
1027
|
+
test (x, stateObj) {
|
|
1028
|
+
return typeof x === 'undefined' && stateObj.ownKeys === false;
|
|
1029
|
+
},
|
|
1030
|
+
replace (n) { return 0; },
|
|
1031
|
+
revive (s) { return undefined; } // Will avoid adding anything
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
];
|
|
1035
|
+
|
|
1036
|
+
const specialNumbers = [
|
|
1037
|
+
nan,
|
|
1038
|
+
infinity,
|
|
1039
|
+
negativeInfinity
|
|
1040
|
+
];
|
|
1041
|
+
|
|
1042
|
+
/* This preset includes types that are built-in into the JavaScript
|
|
1043
|
+
language itself, this should work universally.
|
|
1044
|
+
|
|
1045
|
+
Types that were added in ES6 or beyond will be checked before inclusion
|
|
1046
|
+
so that this module can be consumed by both ES5 and ES6 environments.
|
|
1047
|
+
|
|
1048
|
+
Some types cannot be encapsulated because their inner state is private:
|
|
1049
|
+
`WeakMap`, `WeakSet`.
|
|
1050
|
+
|
|
1051
|
+
The Function type is not included because their closures would not be
|
|
1052
|
+
serialized, so a revived Function that uses closures would not behave
|
|
1053
|
+
as expected.
|
|
1054
|
+
|
|
1055
|
+
Symbols are similarly not included.
|
|
1056
|
+
*/
|
|
1057
|
+
|
|
1058
|
+
const expObj$1 = [
|
|
1059
|
+
undef$1,
|
|
1060
|
+
// ES5
|
|
1061
|
+
arrayNonindexKeys, primitiveObjects, specialNumbers,
|
|
1062
|
+
date, error, errors, regexp
|
|
1063
|
+
].concat(
|
|
1064
|
+
// ES2015 (ES6)
|
|
1065
|
+
/* c8 ignore next */
|
|
1066
|
+
typeof Map === 'function' ? map : [],
|
|
1067
|
+
/* c8 ignore next */
|
|
1068
|
+
typeof Set === 'function' ? set : [],
|
|
1069
|
+
/* c8 ignore next */
|
|
1070
|
+
typeof ArrayBuffer === 'function' ? arraybuffer : [],
|
|
1071
|
+
/* c8 ignore next */
|
|
1072
|
+
typeof Uint8Array === 'function' ? typedArrays : [],
|
|
1073
|
+
/* c8 ignore next */
|
|
1074
|
+
typeof DataView === 'function' ? dataview : [],
|
|
1075
|
+
/* c8 ignore next */
|
|
1076
|
+
typeof Intl !== 'undefined' ? intlTypes : [],
|
|
1077
|
+
|
|
1078
|
+
/* c8 ignore next */
|
|
1079
|
+
typeof BigInt !== 'undefined' ? [bigint, bigintObject] : []
|
|
1080
|
+
);
|
|
1081
|
+
|
|
1082
|
+
/*
|
|
1083
|
+
When communicating via `postMessage()` (`Worker.postMessage()` or
|
|
1084
|
+
`window.postMessage()`), the browser will use a similar algorithm as Typeson
|
|
1085
|
+
does to encapsulate and revive all items in the structure (aka the structured
|
|
1086
|
+
clone algorithm). This algorithm supports all built-in types as well as many
|
|
1087
|
+
DOM types. Therefore, only types that are not included in the structured clone
|
|
1088
|
+
algorithm need to be registered, which is:
|
|
1089
|
+
|
|
1090
|
+
* Error
|
|
1091
|
+
* Specific Errors like SyntaxError, TypeError, etc.
|
|
1092
|
+
* Any custom type you want to send across window- or worker boundraries
|
|
1093
|
+
|
|
1094
|
+
This preset will only include the Error types and you can register your
|
|
1095
|
+
custom types after having registered these.
|
|
1096
|
+
*/
|
|
1097
|
+
|
|
1098
|
+
const postmessage = [
|
|
1099
|
+
error,
|
|
1100
|
+
errors
|
|
1101
|
+
];
|
|
1102
|
+
|
|
1103
|
+
const socketio = [
|
|
1104
|
+
expObj$1,
|
|
1105
|
+
// Leave ArrayBuffer as is, and let socket.io stream it instead.
|
|
1106
|
+
{arraybuffer: null},
|
|
1107
|
+
// Encapsulate TypedArrays in ArrayBuffers instead of base64 strings.
|
|
1108
|
+
typedArraysSocketIO
|
|
1109
|
+
];
|
|
1110
|
+
|
|
1111
|
+
const sparseUndefined = [
|
|
1112
|
+
{
|
|
1113
|
+
sparseArrays: {
|
|
1114
|
+
testPlainObjects: true,
|
|
1115
|
+
test (x) { return Array.isArray(x); },
|
|
1116
|
+
replace (a, stateObj) {
|
|
1117
|
+
stateObj.iterateUnsetNumeric = true;
|
|
1118
|
+
return a;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
},
|
|
1122
|
+
{
|
|
1123
|
+
sparseUndefined: {
|
|
1124
|
+
test (x, stateObj) {
|
|
1125
|
+
return typeof x === 'undefined' && stateObj.ownKeys === false;
|
|
1126
|
+
},
|
|
1127
|
+
replace (n) { return 0; },
|
|
1128
|
+
revive (s) { return undefined; } // Will avoid adding anything
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
];
|
|
1132
|
+
|
|
1133
|
+
/* This preset includes types for the Structured Cloning Algorithm. */
|
|
1134
|
+
|
|
1135
|
+
const expObj = [
|
|
1136
|
+
// Todo: Might also register synchronous `ImageBitmap` and
|
|
1137
|
+
// `Blob`/`File`/`FileList`?
|
|
1138
|
+
// ES5
|
|
1139
|
+
userObject, // Processed last (non-builtin)
|
|
1140
|
+
|
|
1141
|
+
undef$1,
|
|
1142
|
+
arrayNonindexKeys, primitiveObjects, specialNumbers,
|
|
1143
|
+
date, regexp,
|
|
1144
|
+
|
|
1145
|
+
// Non-built-ins
|
|
1146
|
+
imagedata,
|
|
1147
|
+
imagebitmap, // Async return
|
|
1148
|
+
file,
|
|
1149
|
+
filelist,
|
|
1150
|
+
blob,
|
|
1151
|
+
error,
|
|
1152
|
+
errors
|
|
1153
|
+
].concat(
|
|
1154
|
+
// ES2015 (ES6)
|
|
1155
|
+
/* c8 ignore next */
|
|
1156
|
+
typeof Map === 'function' ? map : [],
|
|
1157
|
+
/* c8 ignore next */
|
|
1158
|
+
typeof Set === 'function' ? set : [],
|
|
1159
|
+
/* c8 ignore next */
|
|
1160
|
+
typeof ArrayBuffer === 'function' ? arraybuffer : [],
|
|
1161
|
+
/* c8 ignore next */
|
|
1162
|
+
typeof Uint8Array === 'function' ? typedArrays : [],
|
|
1163
|
+
/* c8 ignore next */
|
|
1164
|
+
typeof DataView === 'function' ? dataview : [],
|
|
1165
|
+
/* c8 ignore next */
|
|
1166
|
+
typeof Intl !== 'undefined' ? intlTypes : [],
|
|
1167
|
+
/* c8 ignore next */
|
|
1168
|
+
typeof crypto !== 'undefined' ? cryptokey : [],
|
|
1169
|
+
/* c8 ignore next */
|
|
1170
|
+
typeof BigInt !== 'undefined' ? [bigint, bigintObject] : []
|
|
1171
|
+
);
|
|
1172
|
+
|
|
1173
|
+
/* globals DOMException */
|
|
1174
|
+
|
|
1175
|
+
var structuredCloningThrowing = expObj.concat({
|
|
1176
|
+
checkDataCloneException: {
|
|
1177
|
+
test (val) {
|
|
1178
|
+
// Should also throw with:
|
|
1179
|
+
// 1. `IsDetachedBuffer` (a process not called within the
|
|
1180
|
+
// ECMAScript spec)
|
|
1181
|
+
// 2. `IsCallable` (covered by `typeof === 'function'` or a
|
|
1182
|
+
// function's `toStringTag`)
|
|
1183
|
+
// 3. internal slots besides [[Prototype]] or [[Extensible]] (e.g.,
|
|
1184
|
+
// [[PromiseState]] or [[WeakMapData]])
|
|
1185
|
+
// 4. exotic object (e.g., `Proxy`) (unless an `%ObjectPrototype%`
|
|
1186
|
+
// intrinsic object) (which does not have default
|
|
1187
|
+
// behavior for one or more of the essential internal methods
|
|
1188
|
+
// that are limited to the following for non-function objects
|
|
1189
|
+
// (we auto-exclude functions):
|
|
1190
|
+
// [[GetPrototypeOf]],[[SetPrototypeOf]],[[IsExtensible]],
|
|
1191
|
+
// [[PreventExtensions]],[[GetOwnProperty]],
|
|
1192
|
+
// [[DefineOwnProperty]],[[HasProperty]],
|
|
1193
|
+
// [[Get]],[[Set]],[[Delete]],[[OwnPropertyKeys]]);
|
|
1194
|
+
// except for the standard, built-in exotic objects, we'd need
|
|
1195
|
+
// to know whether these methods had distinct behaviors
|
|
1196
|
+
// Note: There is no apparent way for us to detect a `Proxy` and
|
|
1197
|
+
// reject (Chrome at least is not rejecting anyways)
|
|
1198
|
+
const stringTag = ({}.toString.call(val).slice(8, -1));
|
|
1199
|
+
if (
|
|
1200
|
+
[
|
|
1201
|
+
// Symbol's `toStringTag` is only "Symbol" for its initial
|
|
1202
|
+
// value, so we check `typeof`
|
|
1203
|
+
'symbol',
|
|
1204
|
+
// All functions including bound function exotic objects
|
|
1205
|
+
'function'
|
|
1206
|
+
].includes(typeof val) ||
|
|
1207
|
+
[
|
|
1208
|
+
// A non-array exotic object
|
|
1209
|
+
'Arguments',
|
|
1210
|
+
// A non-array exotic object
|
|
1211
|
+
'Module',
|
|
1212
|
+
// `Error` and other errors have the [[ErrorData]] internal
|
|
1213
|
+
// slot and give "Error"
|
|
1214
|
+
'Error',
|
|
1215
|
+
// Promise instances have an extra slot ([[PromiseState]])
|
|
1216
|
+
// but not throwing in Chrome `postMessage`
|
|
1217
|
+
'Promise',
|
|
1218
|
+
// WeakMap instances have an extra slot ([[WeakMapData]])
|
|
1219
|
+
// but not throwing in Chrome `postMessage`
|
|
1220
|
+
'WeakMap',
|
|
1221
|
+
// WeakSet instances have an extra slot ([[WeakSetData]])
|
|
1222
|
+
// but not throwing in Chrome `postMessage`
|
|
1223
|
+
'WeakSet',
|
|
1224
|
+
|
|
1225
|
+
// HTML-SPECIFIC
|
|
1226
|
+
'Event',
|
|
1227
|
+
// Also in Node `worker_threads` (currently experimental)
|
|
1228
|
+
'MessageChannel'
|
|
1229
|
+
].includes(stringTag) ||
|
|
1230
|
+
/*
|
|
1231
|
+
// isClosed is no longer documented
|
|
1232
|
+
((stringTag === 'Blob' || stringTag === 'File') &&
|
|
1233
|
+
val.isClosed) ||
|
|
1234
|
+
*/
|
|
1235
|
+
(val && typeof val === 'object' &&
|
|
1236
|
+
// Duck-type DOM node objects (non-array exotic?
|
|
1237
|
+
// objects which cannot be cloned by the SCA)
|
|
1238
|
+
typeof val.nodeType === 'number' &&
|
|
1239
|
+
typeof val.insertBefore === 'function')
|
|
1240
|
+
) {
|
|
1241
|
+
throw new DOMException(
|
|
1242
|
+
'The object cannot be cloned.', 'DataCloneError'
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
return false;
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1249
|
+
|
|
1250
|
+
const undef = [
|
|
1251
|
+
sparseUndefined,
|
|
1252
|
+
undef$1
|
|
1253
|
+
];
|
|
1254
|
+
|
|
1255
|
+
const universal = [
|
|
1256
|
+
expObj$1
|
|
1257
|
+
// TODO: Add types that are de-facto universal even though not
|
|
1258
|
+
// built-in into ecmasript standard.
|
|
1259
|
+
];
|
|
1260
|
+
|
|
1261
|
+
export { l as JSON_TYPES, u as Typeson, e as TypesonPromise, p as Undefined, arrayNonindexKeys, arraybuffer, bigint, bigintObject, blob, expObj$1 as builtin, cloneable, cryptokey, dataview, date, error, errors, escapeKeyPathComponent, file, filelist, getByKeyPath, getJSONType, hasConstructorOf, imagebitmap, imagedata, infinity, intlTypes, isObject, isPlainObject, isThenable, isUserObject, map, nan, negativeInfinity, nonbuiltinIgnore, postmessage, primitiveObjects, regexp, resurrectable, set, setAtKeyPath, socketio, sparseUndefined, specialNumbers, expObj as structuredCloning, structuredCloningThrowing, toStringTag, typedArrays, typedArraysSocketIO as typedArraysSocketio, undef$1 as undef, undef as undefPreset, unescapeKeyPathComponent, universal, userObject };
|
|
1262
|
+
//# sourceMappingURL=index.js.map
|