polyfill-library 4.6.0 → 4.8.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +4 -4
- package/README.md +41 -0
- package/package.json +10 -21
- package/polyfills/__dist/Array.prototype.sort/meta.json +1 -1
- package/polyfills/__dist/Array.prototype.sort/min.js +1 -1
- package/polyfills/__dist/Array.prototype.sort/raw.js +20 -9
- package/polyfills/__dist/Array.prototype.toReversed/meta.json +1 -0
- package/polyfills/__dist/Array.prototype.toReversed/min.js +1 -0
- package/polyfills/__dist/Array.prototype.toReversed/raw.js +29 -0
- package/polyfills/__dist/Array.prototype.toSorted/meta.json +1 -0
- package/polyfills/__dist/Array.prototype.toSorted/min.js +1 -0
- package/polyfills/__dist/Array.prototype.toSorted/raw.js +37 -0
- package/polyfills/__dist/Array.prototype.toSpliced/meta.json +1 -0
- package/polyfills/__dist/Array.prototype.toSpliced/min.js +1 -0
- package/polyfills/__dist/Array.prototype.toSpliced/raw.js +96 -0
- package/polyfills/__dist/Array.prototype.with/meta.json +1 -0
- package/polyfills/__dist/Array.prototype.with/min.js +1 -0
- package/polyfills/__dist/Array.prototype.with/raw.js +60 -0
- package/polyfills/__dist/DocumentFragment.prototype.replaceChildren/meta.json +1 -0
- package/polyfills/__dist/DocumentFragment.prototype.replaceChildren/min.js +1 -0
- package/polyfills/__dist/DocumentFragment.prototype.replaceChildren/raw.js +15 -0
- package/polyfills/__dist/Element.prototype.replaceChildren/meta.json +1 -0
- package/polyfills/__dist/Element.prototype.replaceChildren/min.js +1 -0
- package/polyfills/__dist/Element.prototype.replaceChildren/raw.js +8 -0
- package/polyfills/__dist/HTMLFormElement.prototype.requestSubmit/meta.json +1 -0
- package/polyfills/__dist/HTMLFormElement.prototype.requestSubmit/min.js +1 -0
- package/polyfills/__dist/HTMLFormElement.prototype.requestSubmit/raw.js +116 -0
- package/polyfills/__dist/IntersectionObserver/meta.json +1 -1
- package/polyfills/__dist/IntersectionObserver/min.js +1 -1
- package/polyfills/__dist/IntersectionObserver/raw.js +2 -1
- package/polyfills/__dist/IntersectionObserverEntry/meta.json +1 -1
- package/polyfills/__dist/Intl.DateTimeFormat.~locale.en-US-POSIX/meta.json +1 -1
- package/polyfills/__dist/Intl.NumberFormat.~locale.he/meta.json +1 -1
- package/polyfills/__dist/Intl.NumberFormat.~locale.id/meta.json +1 -1
- package/polyfills/__dist/Intl.NumberFormat.~locale.jv/meta.json +1 -1
- package/polyfills/__dist/Intl.NumberFormat.~locale.sr-Latn/meta.json +1 -1
- package/polyfills/__dist/Intl.NumberFormat.~locale.sr-Latn-BA/meta.json +1 -1
- package/polyfills/__dist/Intl.NumberFormat.~locale.sr-Latn-ME/meta.json +1 -1
- package/polyfills/__dist/Intl.NumberFormat.~locale.sr-Latn-XK/meta.json +1 -1
- package/polyfills/__dist/Intl.RelativeTimeFormat.~locale.en-US-POSIX/meta.json +1 -1
- package/polyfills/__dist/Intl.RelativeTimeFormat.~locale.he/meta.json +1 -1
- package/polyfills/__dist/Intl.RelativeTimeFormat.~locale.id/meta.json +1 -1
- package/polyfills/__dist/Intl.RelativeTimeFormat.~locale.jv/meta.json +1 -1
- package/polyfills/__dist/Intl.RelativeTimeFormat.~locale.sr-Latn/meta.json +1 -1
- package/polyfills/__dist/Intl.RelativeTimeFormat.~locale.sr-Latn-BA/meta.json +1 -1
- package/polyfills/__dist/Intl.RelativeTimeFormat.~locale.sr-Latn-ME/meta.json +1 -1
- package/polyfills/__dist/Intl.RelativeTimeFormat.~locale.sr-Latn-XK/meta.json +1 -1
- package/polyfills/__dist/Map/meta.json +1 -1
- package/polyfills/__dist/Map/min.js +1 -1
- package/polyfills/__dist/Map/raw.js +5 -2
- package/polyfills/__dist/ResizeObserver/min.js +1 -1
- package/polyfills/__dist/ResizeObserver/raw.js +5 -5
- package/polyfills/__dist/TypedArray.prototype.@@toStringTag/raw.js +1 -1
- package/polyfills/__dist/TypedArray.prototype.at/raw.js +1 -1
- package/polyfills/__dist/TypedArray.prototype.entries/meta.json +1 -1
- package/polyfills/__dist/TypedArray.prototype.entries/min.js +1 -1
- package/polyfills/__dist/TypedArray.prototype.entries/raw.js +21 -25
- package/polyfills/__dist/TypedArray.prototype.findLast/meta.json +1 -1
- package/polyfills/__dist/TypedArray.prototype.findLast/min.js +1 -1
- package/polyfills/__dist/TypedArray.prototype.findLast/raw.js +12 -11
- package/polyfills/__dist/TypedArray.prototype.findLastIndex/meta.json +1 -1
- package/polyfills/__dist/TypedArray.prototype.findLastIndex/min.js +1 -1
- package/polyfills/__dist/TypedArray.prototype.findLastIndex/raw.js +12 -11
- package/polyfills/__dist/TypedArray.prototype.keys/meta.json +1 -1
- package/polyfills/__dist/TypedArray.prototype.keys/min.js +1 -1
- package/polyfills/__dist/TypedArray.prototype.keys/raw.js +21 -25
- package/polyfills/__dist/TypedArray.prototype.sort/meta.json +1 -0
- package/polyfills/__dist/TypedArray.prototype.sort/min.js +1 -0
- package/polyfills/__dist/TypedArray.prototype.sort/raw.js +71 -0
- package/polyfills/__dist/TypedArray.prototype.toReversed/meta.json +1 -0
- package/polyfills/__dist/TypedArray.prototype.toReversed/min.js +1 -0
- package/polyfills/__dist/TypedArray.prototype.toReversed/raw.js +50 -0
- package/polyfills/__dist/TypedArray.prototype.toSorted/meta.json +1 -0
- package/polyfills/__dist/TypedArray.prototype.toSorted/min.js +1 -0
- package/polyfills/__dist/TypedArray.prototype.toSorted/raw.js +59 -0
- package/polyfills/__dist/TypedArray.prototype.with/meta.json +1 -0
- package/polyfills/__dist/TypedArray.prototype.with/min.js +1 -0
- package/polyfills/__dist/TypedArray.prototype.with/raw.js +83 -0
- package/polyfills/__dist/_ESAbstract.IsValidIntegerIndex/meta.json +1 -0
- package/polyfills/__dist/_ESAbstract.IsValidIntegerIndex/min.js +1 -0
- package/polyfills/__dist/_ESAbstract.IsValidIntegerIndex/raw.js +16 -0
- package/polyfills/__dist/_ESAbstract.TypedArrayCreate/meta.json +1 -0
- package/polyfills/__dist/_ESAbstract.TypedArrayCreate/min.js +1 -0
- package/polyfills/__dist/_ESAbstract.TypedArrayCreate/raw.js +20 -0
- package/polyfills/__dist/_ESAbstract.TypedArrayCreateSameType/meta.json +1 -0
- package/polyfills/__dist/_ESAbstract.TypedArrayCreateSameType/min.js +1 -0
- package/polyfills/__dist/_ESAbstract.TypedArrayCreateSameType/raw.js +41 -0
- package/polyfills/__dist/aliases.json +1 -1
- package/polyfills/__dist/atob/meta.json +1 -1
- package/polyfills/__dist/atob/min.js +1 -1
- package/polyfills/__dist/atob/raw.js +22 -16
- package/polyfills/__dist/structuredClone/meta.json +1 -0
- package/polyfills/__dist/structuredClone/min.js +1 -0
- package/polyfills/__dist/structuredClone/raw.js +279 -0
@@ -1 +1 @@
|
|
1
|
-
{"aliases":["default-3.3","default-3.4","default-3.5","default-3.6","default","caniuse:datauri"],"license":"MIT","repo":"http://www.webtoolkit.info/javascript-base64.html","spec":"https://html.spec.whatwg.org/multipage/webappapis.html#dom-windowbase64-atob","docs":"https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/atob","browsers":{"ie":"<10"},"install":{"module":"Base64","paths":["base64.js"]},"detectSource":"\"atob\"in self\n","baseDir":"atob","hasTests":true,"isTestable":true,"isPublic":true,"size":
|
1
|
+
{"aliases":["default-3.3","default-3.4","default-3.5","default-3.6","default","caniuse:datauri"],"license":"MIT","repo":"http://www.webtoolkit.info/javascript-base64.html","spec":"https://html.spec.whatwg.org/multipage/webappapis.html#dom-windowbase64-atob","docs":"https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/atob","browsers":{"ie":"<10"},"install":{"module":"Base64","paths":["base64.js"]},"detectSource":"\"atob\"in self\n","baseDir":"atob","hasTests":true,"isTestable":true,"isPublic":true,"size":1270}
|
@@ -1 +1 @@
|
|
1
|
-
!function(e){"use strict";if("object"==typeof exports&&null!=exports&&"number"!=typeof exports.nodeType)module.exports=e();else if("function"==typeof define&&null!=define.amd)define([],e);else{var t=e(),o="undefined"!=typeof self?self:$.global;"function"!=typeof o.btoa&&(o.btoa=t.btoa),"function"!=typeof o.atob&&(o.atob=t.atob)}}(function(){"use strict";function e(e){this.message=e}function t(t){for(var o,n,a=String(t),
|
1
|
+
!function(e){"use strict";if("object"==typeof exports&&null!=exports&&"number"!=typeof exports.nodeType)module.exports=e();else if("function"==typeof define&&null!=define.amd)define([],e);else{var t=e(),o="undefined"!=typeof self?self:$.global;"function"!=typeof o.btoa&&(o.btoa=t.btoa),"function"!=typeof o.atob&&(o.atob=t.atob)}}(function(){"use strict";function e(e){this.message=e}function t(t){for(var o,n,a,c,i=String(t),f=0,s="";f<i.length;){if(o=i.charCodeAt(f++),n=i.charCodeAt(f++),a=i.charCodeAt(f++),o>128||n>128||a>128)throw new e("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");c=o<<16|n<<8|a,s+=r.charAt(c>>18&63)+r.charAt(c>>12&63)+r.charAt(c>>6&63)+r.charAt(63&c)}switch(i.length%3){case 0:return s;case 1:return s.slice(0,-2)+"==";case 2:return s.slice(0,-1)+"="}}function o(t){var o=String(t).replace(/[=]+$/,"");if(o.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,a,c=0,i=0,f="";a=o.charAt(i++);~a&&(n=c%4?64*n+a:a,c++%4)?f+=String.fromCharCode(255&n>>(-2*c&6)):0)a=r.indexOf(a);return f}var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";return e.prototype=new Error,e.prototype.name="InvalidCharacterError",{btoa:t,atob:o}});
|
@@ -30,26 +30,32 @@
|
|
30
30
|
InvalidCharacterError.prototype.name = 'InvalidCharacterError';
|
31
31
|
|
32
32
|
// encoder
|
33
|
-
// [https://gist.github.com/999166] by [https://github.com/nignag]
|
34
33
|
function btoa(input) {
|
35
|
-
var
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
output += map.charAt (63 & block >> 8 - idx % 1 * 8)
|
45
|
-
) {
|
46
|
-
charCode = str.charCodeAt (idx += 3 / 4);
|
47
|
-
if (charCode > 0xFF) {
|
34
|
+
var data = String (input), o1, o2, o3, bits, i = 0, acc = '';
|
35
|
+
|
36
|
+
while (i < data.length) {
|
37
|
+
// pack three octets into four hextets
|
38
|
+
o1 = data.charCodeAt (i++);
|
39
|
+
o2 = data.charCodeAt (i++);
|
40
|
+
o3 = data.charCodeAt (i++);
|
41
|
+
|
42
|
+
if (o1 > 128 || o2 > 128 || o3 > 128) {
|
48
43
|
throw new InvalidCharacterError ("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");
|
49
44
|
}
|
50
|
-
|
45
|
+
|
46
|
+
bits = (o1 << 16) | (o2 << 8) | o3;
|
47
|
+
// use hextets to index into b64, and append result to encoded string
|
48
|
+
acc += chars.charAt ((bits >> 18) & 0x3F) +
|
49
|
+
chars.charAt ((bits >> 12) & 0x3F) +
|
50
|
+
chars.charAt ((bits >> 6) & 0x3F) +
|
51
|
+
chars.charAt ((bits) & 0x3F);
|
52
|
+
}
|
53
|
+
|
54
|
+
switch (data.length % 3) {
|
55
|
+
case 0: return acc;
|
56
|
+
case 1: return acc.slice (0, -2) + '==';
|
57
|
+
case 2: return acc.slice (0, -1) + '=';
|
51
58
|
}
|
52
|
-
return output;
|
53
59
|
}
|
54
60
|
|
55
61
|
// decoder
|
@@ -0,0 +1 @@
|
|
1
|
+
{"dependencies":["Map","Set","Object.keys","String.prototype.includes","RegExp.prototype.flags"],"spec":"https://html.spec.whatwg.org/multipage/structured-data.html#dom-structuredclone","docs":"https://developer.mozilla.org/en-US/docs/Web/API/structuredClone","license":"MIT","repo":"https://github.com/ungap/structured-clone/","notes":["This polyfill currently does not support cloning: Blob, File, FileList, ImageBitmap, ImageData, and ArrayBuffer. TypedArrays are supported without major issues, but int and uint 8/16/32 are the only safely supported TypedArrays."],"browsers":{"android":"*","bb":"*","chrome":"<98","edge":"*","edge_mob":"*","firefox":"<94","firefox_mob":"<94","ie":"*","ie_mob":"*","opera":"<84","op_mob":"<68","op_mini":"*","safari":"<15.4","ios_saf":"<15.4","samsung_mob":"<18.0"},"detectSource":"\"structuredClone\"in self&&\"function\"==typeof self.structuredClone\n","baseDir":"structuredClone","hasTests":true,"isTestable":true,"isPublic":true,"size":2490}
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";!function(e){function r(r,n){function t(e,n){return r.set(n,e),e}function a(u){var s,b;if(r.has(u))return r.get(u);var m=n[u][0],y=n[u][1];switch(m){case i:case c:return t(y,u);case o:var O=t([],u);for(s=0,b=y.length;s<b;++s)O.push(a(y[s]));return O;case f:var S=t({},u),d=Object.keys(y);for(s=0,b=d.length;s<b;++s){var E=y[d[s]];S[a(E[0])]=a(E[1])}return S;case g:return t(new Date(y),u);case l:return t(new RegExp(y.source,y.flags),u);case h:var j=t(new Map,u);for(s=0,b=y.length;s<b;++s){var B=y[s];j.set(a(B[0]),a(B[1]))}return j;case v:var I=t(new Set,u);for(s=0,b=y.length;s<b;++s)I.add(a(y[s]));return I;case p:return t(new e[y.name](y.message),u);case w:return t(BigInt(y),u);case"BigInt":return t(Object(BigInt(y)),u)}return t(new e[m](y),u)}return a}function n(e){return r(new Map,e)(0)}function t(e){if(e instanceof Map)return[h,b];if(e instanceof Set)return[v,b];var r=typeof e;if("object"!==r||!e)return[i,r];var n=m.toString.call(e).slice(8,-1);switch(n){case"Array":return[o,b];case"Object":return[f,b];case"Date":return[g,b];case"RegExp":return[l,b]}return-1!==n.indexOf("Array")?[o,n]:-1!==n.indexOf("Error")?[p,n]:[f,n]}function a(e){return e[0]===i&&("function"===e[1]||"symbol"===e[1])}function u(e,r){function n(n,t){var a=r.push(n)-1;return e.set(t,a),a}function u(r){if(e.has(r))return e.get(r);var s,p,b,m=t(r),y=m[0],O=m[1];switch(y){case i:var S=r;switch(O){case"bigint":y=w,S=r.toString();break;case"function":case"symbol":throw new TypeError("unable to serialize "+O);case"undefined":return n([c],r)}return n([y,S],r);case o:var d=[],E=n([O||y,d],r);if(O)for(s=0,p=r.length;s<p;++s)d.push(r[s]);else for(s=0,p=r.length;s<p;++s)d.push(u(r[s]));return E;case f:if(O)switch(O){case"BigInt":return n([O,r.toString()],r);case"Boolean":case"Number":case"String":return n([O,r.valueOf()],r)}var j=[],B=n([y,j],r);for(b=Object.keys(r),s=0,p=b.length;s<p;++s){var I=b[s];a(t(r[I]))||j.push([u(I),u(r[I])])}return B;case g:return n([y,r.toISOString()],r);case l:return n([y,{source:r.source,flags:(r.global?"g":"")+(r.ignoreCase?"i":"")+(r.multiline?"m":"")}],r);case h:var x=[],M=n([y,x],r);return r.forEach(function(e,r){a(t(r))||a(t(e))||x.push([u(r),u(e)])}),M;case v:var k=[],A=n([y,k],r);return r.forEach(function(e){a(t(e))||k.push(u(e))}),A}return n([y,{name:O,message:r.message}],r)}return u}function s(e){var r=[];return u(new Map,r)(e),r}var c=-1,i=0,o=1,f=2,g=3,l=4,h=5,v=6,p=7,w=8,b="",m={};e.structuredClone=function e(r){return n(s(r))}}(self);
|
@@ -0,0 +1,279 @@
|
|
1
|
+
|
2
|
+
// structuredClone
|
3
|
+
/* global Map, Set, BigInt */
|
4
|
+
"use strict";
|
5
|
+
|
6
|
+
(function (env) {
|
7
|
+
var VOID = -1;
|
8
|
+
var PRIMITIVE = 0;
|
9
|
+
var ARRAY = 1;
|
10
|
+
var OBJECT = 2;
|
11
|
+
var DATE = 3;
|
12
|
+
var REGEXP = 4;
|
13
|
+
var MAP = 5;
|
14
|
+
var SET = 6;
|
15
|
+
var ERROR = 7;
|
16
|
+
var BIGINT = 8;
|
17
|
+
|
18
|
+
function deserializer($, _) {
|
19
|
+
function as(out, index) {
|
20
|
+
$.set(index, out);
|
21
|
+
return out;
|
22
|
+
}
|
23
|
+
|
24
|
+
function unpair(index) {
|
25
|
+
var i, l;
|
26
|
+
|
27
|
+
if ($.has(index)) {
|
28
|
+
return $.get(index);
|
29
|
+
}
|
30
|
+
|
31
|
+
var type = _[index][0];
|
32
|
+
var value = _[index][1];
|
33
|
+
|
34
|
+
switch (type) {
|
35
|
+
case PRIMITIVE:
|
36
|
+
case VOID:
|
37
|
+
return as(value, index);
|
38
|
+
|
39
|
+
case ARRAY: {
|
40
|
+
var arr = as([], index);
|
41
|
+
for (i = 0, l = value.length; i < l; ++i) {
|
42
|
+
arr.push(unpair(value[i]));
|
43
|
+
}
|
44
|
+
return arr;
|
45
|
+
}
|
46
|
+
|
47
|
+
case OBJECT: {
|
48
|
+
var object = as({}, index);
|
49
|
+
var keys = Object.keys(value);
|
50
|
+
for (i = 0, l = keys.length; i < l; ++i) {
|
51
|
+
var entry = value[keys[i]];
|
52
|
+
object[unpair(entry[0])] = unpair(entry[1]);
|
53
|
+
}
|
54
|
+
|
55
|
+
return object;
|
56
|
+
}
|
57
|
+
|
58
|
+
case DATE:
|
59
|
+
return as(new Date(value), index);
|
60
|
+
|
61
|
+
case REGEXP: {
|
62
|
+
return as(new RegExp(value.source, value.flags), index);
|
63
|
+
}
|
64
|
+
|
65
|
+
case MAP: {
|
66
|
+
var map = as(new Map(), index);
|
67
|
+
for (i = 0, l = value.length; i < l; ++i) {
|
68
|
+
var mapEntry = value[i];
|
69
|
+
map.set(unpair(mapEntry[0]), unpair(mapEntry[1]));
|
70
|
+
}
|
71
|
+
|
72
|
+
return map;
|
73
|
+
}
|
74
|
+
|
75
|
+
case SET: {
|
76
|
+
var set = as(new Set(), index);
|
77
|
+
for (i = 0, l = value.length; i < l; ++i) {
|
78
|
+
set.add(unpair(value[i]));
|
79
|
+
}
|
80
|
+
return set;
|
81
|
+
}
|
82
|
+
|
83
|
+
case ERROR: {
|
84
|
+
return as(new env[value.name](value.message), index);
|
85
|
+
}
|
86
|
+
|
87
|
+
case BIGINT:
|
88
|
+
return as(BigInt(value), index);
|
89
|
+
|
90
|
+
case "BigInt":
|
91
|
+
return as(Object(BigInt(value)), index);
|
92
|
+
}
|
93
|
+
|
94
|
+
return as(new env[type](value), index);
|
95
|
+
}
|
96
|
+
|
97
|
+
return unpair;
|
98
|
+
}
|
99
|
+
|
100
|
+
function deserialize(serialized) {
|
101
|
+
return deserializer(new Map(), serialized)(0);
|
102
|
+
}
|
103
|
+
|
104
|
+
var EMPTY = "";
|
105
|
+
var emptyObject = {};
|
106
|
+
|
107
|
+
function typeOf(value) {
|
108
|
+
if (value instanceof Map) {
|
109
|
+
return [MAP, EMPTY];
|
110
|
+
}
|
111
|
+
|
112
|
+
if (value instanceof Set) {
|
113
|
+
return [SET, EMPTY];
|
114
|
+
}
|
115
|
+
|
116
|
+
var type = typeof value;
|
117
|
+
if (type !== "object" || !value) {
|
118
|
+
return [PRIMITIVE, type];
|
119
|
+
}
|
120
|
+
|
121
|
+
var asString = emptyObject.toString.call(value).slice(8, -1);
|
122
|
+
|
123
|
+
switch (asString) {
|
124
|
+
case "Array":
|
125
|
+
return [ARRAY, EMPTY];
|
126
|
+
|
127
|
+
case "Object":
|
128
|
+
return [OBJECT, EMPTY];
|
129
|
+
|
130
|
+
case "Date":
|
131
|
+
return [DATE, EMPTY];
|
132
|
+
|
133
|
+
case "RegExp":
|
134
|
+
return [REGEXP, EMPTY];
|
135
|
+
}
|
136
|
+
|
137
|
+
if (asString.indexOf("Array") !== -1) {
|
138
|
+
return [ARRAY, asString];
|
139
|
+
}
|
140
|
+
|
141
|
+
if (asString.indexOf("Error") !== -1) {
|
142
|
+
return [ERROR, asString];
|
143
|
+
}
|
144
|
+
|
145
|
+
return [OBJECT, asString];
|
146
|
+
}
|
147
|
+
|
148
|
+
function shouldSkip(type) {
|
149
|
+
return type[0] === PRIMITIVE && (type[1] === "function" || type[1] === "symbol");
|
150
|
+
}
|
151
|
+
|
152
|
+
function serializer($, _) {
|
153
|
+
function as(out, value) {
|
154
|
+
var index = _.push(out) - 1;
|
155
|
+
$.set(value, index);
|
156
|
+
return index;
|
157
|
+
}
|
158
|
+
|
159
|
+
function pair(value) {
|
160
|
+
if ($.has(value)) {
|
161
|
+
return $.get(value);
|
162
|
+
}
|
163
|
+
|
164
|
+
var i, l, keys;
|
165
|
+
var to = typeOf(value);
|
166
|
+
var TYPE = to[0];
|
167
|
+
var typeName = to[1];
|
168
|
+
|
169
|
+
switch (TYPE) {
|
170
|
+
case PRIMITIVE: {
|
171
|
+
var primitiveValue = value;
|
172
|
+
|
173
|
+
switch (typeName) {
|
174
|
+
case "bigint":
|
175
|
+
TYPE = BIGINT;
|
176
|
+
primitiveValue = value.toString();
|
177
|
+
break;
|
178
|
+
|
179
|
+
case "function":
|
180
|
+
case "symbol":
|
181
|
+
throw new TypeError("unable to serialize " + typeName);
|
182
|
+
|
183
|
+
case "undefined":
|
184
|
+
return as([VOID], value);
|
185
|
+
}
|
186
|
+
|
187
|
+
return as([TYPE, primitiveValue], value);
|
188
|
+
}
|
189
|
+
|
190
|
+
case ARRAY: {
|
191
|
+
var arr = [];
|
192
|
+
var arrayIndex = as([typeName || TYPE, arr], value);
|
193
|
+
|
194
|
+
if (typeName) {
|
195
|
+
for (i = 0, l = value.length; i < l; ++i) {
|
196
|
+
arr.push(value[i]);
|
197
|
+
}
|
198
|
+
|
199
|
+
} else {
|
200
|
+
for (i = 0, l = value.length; i < l; ++i) {
|
201
|
+
arr.push(pair(value[i]));
|
202
|
+
}
|
203
|
+
}
|
204
|
+
return arrayIndex;
|
205
|
+
}
|
206
|
+
|
207
|
+
case OBJECT: {
|
208
|
+
if (typeName) {
|
209
|
+
switch (typeName) {
|
210
|
+
case "BigInt":
|
211
|
+
return as([typeName, value.toString()], value);
|
212
|
+
|
213
|
+
case "Boolean":
|
214
|
+
case "Number":
|
215
|
+
case "String":
|
216
|
+
return as([typeName, value.valueOf()], value);
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
var objectEntries = [];
|
221
|
+
var index = as([TYPE, objectEntries], value);
|
222
|
+
keys = Object.keys(value);
|
223
|
+
for (i = 0, l = keys.length; i < l; ++i) {
|
224
|
+
var objectKey = keys[i];
|
225
|
+
if (!shouldSkip(typeOf(value[objectKey]))) {
|
226
|
+
objectEntries.push([pair(objectKey), pair(value[objectKey])]);
|
227
|
+
}
|
228
|
+
}
|
229
|
+
return index;
|
230
|
+
}
|
231
|
+
|
232
|
+
case DATE:
|
233
|
+
return as([TYPE, value.toISOString()], value);
|
234
|
+
|
235
|
+
case REGEXP: {
|
236
|
+
return as([TYPE, {source: value.source, flags: (value.global ? "g" : "") + (value.ignoreCase ? "i" : "") + (value.multiline ? "m" : "")}], value);
|
237
|
+
}
|
238
|
+
|
239
|
+
case MAP: {
|
240
|
+
var mapEntries = [];
|
241
|
+
var mapIndex = as([TYPE, mapEntries], value);
|
242
|
+
value.forEach(function (value, key) {
|
243
|
+
if (!(shouldSkip(typeOf(key)) || shouldSkip(typeOf(value)))) {
|
244
|
+
mapEntries.push([pair(key), pair(value)]);
|
245
|
+
}
|
246
|
+
})
|
247
|
+
|
248
|
+
return mapIndex;
|
249
|
+
}
|
250
|
+
|
251
|
+
case SET: {
|
252
|
+
var setEntries = [];
|
253
|
+
var setIndex = as([TYPE, setEntries], value);
|
254
|
+
value.forEach(function (value) {
|
255
|
+
if (!shouldSkip(typeOf(value))) {
|
256
|
+
setEntries.push(pair(value));
|
257
|
+
}
|
258
|
+
})
|
259
|
+
|
260
|
+
return setIndex;
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
return as([TYPE, {name: typeName, message: value.message}], value);
|
265
|
+
}
|
266
|
+
|
267
|
+
return pair;
|
268
|
+
}
|
269
|
+
|
270
|
+
function serialize(value) {
|
271
|
+
var _ = [];
|
272
|
+
return serializer(new Map(), _)(value), _;
|
273
|
+
}
|
274
|
+
|
275
|
+
env.structuredClone = function structuredClone(any) {
|
276
|
+
return deserialize(serialize(any));
|
277
|
+
};
|
278
|
+
|
279
|
+
})(self);
|