seroval 0.2.1 → 0.3.0
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/README.md +36 -15
- package/dist/cjs/development/index.cjs +625 -434
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +2 -2
- package/dist/esm/development/index.mjs +625 -434
- package/dist/esm/development/index.mjs.map +4 -4
- package/dist/esm/production/index.mjs +2 -2
- package/dist/types/checks.d.ts +5 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/tree.d.ts +93 -0
- package/dist/types/types.d.ts +7 -3
- package/package.json +2 -2
- package/src/checks.ts +41 -0
- package/src/index.ts +25 -37
- package/src/serialize-primitive.ts +10 -7
- package/src/tree.ts +963 -0
- package/src/types.ts +37 -4
- package/dist/types/array.d.ts +0 -2
- package/dist/types/async.d.ts +0 -4
- package/dist/types/context.d.ts +0 -33
- package/dist/types/is-primitive.d.ts +0 -2
- package/dist/types/is-promise.d.ts +0 -1
- package/dist/types/sync.d.ts +0 -4
- package/src/array.ts +0 -18
- package/src/async.ts +0 -229
- package/src/context.ts +0 -200
- package/src/is-primitive.ts +0 -14
- package/src/is-promise.ts +0 -6
- package/src/sync.ts +0 -199
package/README.md
CHANGED
|
@@ -58,25 +58,25 @@ const result = serialize(object);
|
|
|
58
58
|
Output (as a string):
|
|
59
59
|
|
|
60
60
|
```js
|
|
61
|
-
((h,j,k,m)=>(
|
|
61
|
+
((h,j,k,m)=>(m={number:[0.4178420745429774,-0,NaN,1/0,-1/0],string:["hello world","\x3Cscript>Hello World\x3C/script>"],boolean:[!0,!1],null:null,undefined:void 0,bigint:9007199254740991n,array:h=[,,,,j=new Map([["hello","world"],["mutual",k=new Set(["hello","world"])]])],regexp:/[a-z0-9]+/i,date:new Date("2023-03-13T00:52:11.335Z"),map:j,set:k},h[3]=h,j.set("self",j),k.add(k).add(h),m.self=m,m))()
|
|
62
62
|
|
|
63
63
|
// Formatted for readability
|
|
64
|
-
((h, j, k, m) => (
|
|
65
|
-
number: [0.
|
|
64
|
+
((h, j, k, m) => (m = {
|
|
65
|
+
number: [0.4178420745429774, -0, NaN, 1/0, -1/0],
|
|
66
66
|
string: ["hello world", "\x3Cscript>Hello World\x3C/script>"],
|
|
67
67
|
boolean: [!0, !1],
|
|
68
68
|
null: null,
|
|
69
69
|
undefined: void 0,
|
|
70
|
-
bigint:
|
|
71
|
-
array:
|
|
70
|
+
bigint: 9007199254740991n,
|
|
71
|
+
array: h = [, , , , j = new Map([
|
|
72
72
|
["hello", "world"],
|
|
73
|
-
["mutual",
|
|
73
|
+
["mutual", k = new Set(["hello", "world"])]
|
|
74
74
|
])],
|
|
75
75
|
regexp: /[a-z0-9]+/i,
|
|
76
|
-
date: new Date("2023-
|
|
77
|
-
map:
|
|
78
|
-
set:
|
|
79
|
-
},
|
|
76
|
+
date: new Date("2023-03-13T00:52:11.335Z"),
|
|
77
|
+
map: j,
|
|
78
|
+
set: k
|
|
79
|
+
}, h[3] = h, j.set("self", j), k.add(k).add(h), m.self = m, m))()
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
### Mutual cyclic example
|
|
@@ -102,7 +102,7 @@ const result = serialize({ a, b, c, d });
|
|
|
102
102
|
Output (as a string):
|
|
103
103
|
|
|
104
104
|
```js
|
|
105
|
-
((h,j,k,m,o,q)=>(q={a:h=new Map([["name","a"],["children",[j=new Map([["name","c"],["right",
|
|
105
|
+
((h,j,k,m,o,q)=>(q={a:h=new Map([["name","a"],["children",[j=new Map([["name","c"],["right",o=new Map([["name","b"],["children",k=[,m=new Map([["name","d"]])]]])]]),m]]]),b:o,c:j,d:m},j.set("left",h),k[0]=j,m.set("left",h).set("right",o),q))()
|
|
106
106
|
|
|
107
107
|
// Formatted
|
|
108
108
|
((h, j, k, m, o, q) => (q = {
|
|
@@ -110,18 +110,18 @@ Output (as a string):
|
|
|
110
110
|
["name", "a"],
|
|
111
111
|
["children", [j = new Map([
|
|
112
112
|
["name", "c"],
|
|
113
|
-
["right",
|
|
113
|
+
["right", o = new Map([
|
|
114
114
|
["name", "b"],
|
|
115
|
-
["children",
|
|
115
|
+
["children", k = [, m = new Map([
|
|
116
116
|
["name", "d"]
|
|
117
117
|
])]]
|
|
118
118
|
])]
|
|
119
119
|
]), m]]
|
|
120
120
|
]),
|
|
121
|
-
b:
|
|
121
|
+
b: o,
|
|
122
122
|
c: j,
|
|
123
123
|
d: m
|
|
124
|
-
},
|
|
124
|
+
}, j.set("left", h), k[0] = j, m.set("left", h).set("right", o), q))()
|
|
125
125
|
```
|
|
126
126
|
|
|
127
127
|
## Deserialization
|
|
@@ -172,7 +172,28 @@ The following values are the only values accepted by `seroval`:
|
|
|
172
172
|
- `Date`
|
|
173
173
|
- `Map`
|
|
174
174
|
- `Set`
|
|
175
|
+
- `TypedArray`
|
|
176
|
+
- `Int8Array`
|
|
177
|
+
- `Int16Array`
|
|
178
|
+
- `Int32Array`
|
|
179
|
+
- `Uint8Array`
|
|
180
|
+
- `Uint16Array`
|
|
181
|
+
- `Uint32Array`
|
|
182
|
+
- `Uint8ClampedArray`
|
|
183
|
+
- `Float32Array`
|
|
184
|
+
- `Float64Array`
|
|
185
|
+
- `BigInt64Array`
|
|
186
|
+
- `BigUint64Array`
|
|
187
|
+
- `Error`
|
|
188
|
+
- `AggregateError`
|
|
189
|
+
- `EvalError`
|
|
190
|
+
- `RangeError`
|
|
191
|
+
- `ReferenceError`
|
|
192
|
+
- `SyntaxError`
|
|
193
|
+
- `TypeError`
|
|
194
|
+
- `URIError`
|
|
175
195
|
- `Promise` (with `serializeAsync`)
|
|
196
|
+
- [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol)
|
|
176
197
|
- Cyclic references (both self and mutual)
|
|
177
198
|
|
|
178
199
|
## Sponsors
|