seroval 0.4.1 → 0.5.1
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 +21 -9
- package/dist/cjs/development/index.cjs +682 -225
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +3 -2
- package/dist/esm/development/index.mjs +682 -225
- package/dist/esm/development/index.mjs.map +4 -4
- package/dist/esm/production/index.mjs +3 -2
- package/dist/types/compat.d.ts +1 -1
- package/dist/types/context.d.ts +4 -4
- package/dist/types/quote.d.ts +1 -0
- package/dist/types/tree/deserialize.d.ts +4 -0
- package/dist/types/tree/primitives.d.ts +13 -9
- package/dist/types/tree/shared.d.ts +4 -1
- package/dist/types/tree/symbols.d.ts +33 -0
- package/dist/types/tree/types.d.ts +74 -28
- package/dist/types/types.d.ts +2 -1
- package/package.json +4 -4
- package/src/compat.ts +1 -1
- package/src/context.ts +39 -45
- package/src/index.ts +6 -1
- package/src/quote.ts +12 -1
- package/src/tree/async.ts +48 -32
- package/src/tree/deserialize.ts +288 -0
- package/src/tree/iterator.ts +14 -0
- package/src/tree/primitives.ts +155 -32
- package/src/tree/serialize.ts +109 -73
- package/src/tree/shared.ts +46 -2
- package/src/tree/symbols.ts +65 -0
- package/src/tree/sync.ts +47 -31
- package/src/tree/types.ts +85 -17
- package/src/types.ts +4 -1
package/README.md
CHANGED
|
@@ -59,11 +59,11 @@ console.log(result);
|
|
|
59
59
|
Output (as a string):
|
|
60
60
|
|
|
61
61
|
```js
|
|
62
|
-
((h,j,k,m)=>(m={number:[0.
|
|
62
|
+
((h,j,k,m)=>(m={number:[0.28952097444015235,-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-22T02:53:41.129Z"),map:j,set:k},h[3]=h,j.set("self",j),k.add(k).add(h),m.self=m,m))()
|
|
63
63
|
|
|
64
64
|
// Formatted for readability
|
|
65
65
|
((h, j, k, m) => (m = {
|
|
66
|
-
number: [0.
|
|
66
|
+
number: [0.28952097444015235, -0, NaN, 1 / 0, -1 / 0],
|
|
67
67
|
string: ["hello world", "\x3Cscript>Hello World\x3C/script>"],
|
|
68
68
|
boolean: [!0, !1],
|
|
69
69
|
null: null,
|
|
@@ -74,7 +74,7 @@ Output (as a string):
|
|
|
74
74
|
["mutual", k = new Set(["hello", "world"])]
|
|
75
75
|
])],
|
|
76
76
|
regexp: /[a-z0-9]+/i,
|
|
77
|
-
date: new Date("2023-03-
|
|
77
|
+
date: new Date("2023-03-22T02:53:41.129Z"),
|
|
78
78
|
map: j,
|
|
79
79
|
set: k
|
|
80
80
|
}, h[3] = h, j.set("self", j), k.add(k).add(h), m.self = m, m))()
|
|
@@ -149,7 +149,7 @@ console.log(JSON.stringify(result));
|
|
|
149
149
|
```
|
|
150
150
|
|
|
151
151
|
```json
|
|
152
|
-
{"t":{"t":
|
|
152
|
+
{"t":{"t":16,"i":0,"d":{"k":["number","string","boolean","null","undefined","bigint","array","regexp","date","map","set","self"],"v":[{"t":15,"i":1,"l":5,"a":[{"t":0,"s":0.4350045546286634},{"t":5},{"t":8},{"t":6},{"t":7}]},{"t":15,"i":2,"l":2,"a":[{"t":1,"s":"hello world"},{"t":1,"s":"\\x3Cscript>Hello World\\x3C/script>"}]},{"t":15,"i":3,"l":2,"a":[{"t":2,"s":true},{"t":2,"s":false}]},{"t":3},{"t":4},{"t":9,"s":"9007199254740991"},{"t":15,"i":4,"l":5,"a":[null,null,null,{"t":10,"i":4},{"t":14,"i":5,"d":{"k":[{"t":1,"s":"hello"},{"t":1,"s":"self"},{"t":1,"s":"mutual"}],"v":[{"t":1,"s":"world"},{"t":10,"i":5},{"t":13,"i":6,"l":4,"a":[{"t":1,"s":"hello"},{"t":1,"s":"world"},{"t":10,"i":6},{"t":10,"i":4}]}],"s":3}}]},{"t":12,"i":7,"c":"[a-z0-9]+","m":"i"},{"t":11,"i":8,"s":"2023-03-22T02:55:33.504Z"},{"t":10,"i":5},{"t":10,"i":6},{"t":10,"i":0}],"s":12}},"r":0,"i":true,"f":8191,"m":[4,5,6,0]}
|
|
153
153
|
```
|
|
154
154
|
|
|
155
155
|
Then you can feed it to `fromJSON`:
|
|
@@ -208,6 +208,7 @@ The following values are the only values accepted by `seroval`:
|
|
|
208
208
|
- `Date`
|
|
209
209
|
- `Map`
|
|
210
210
|
- `Set`
|
|
211
|
+
- `Object.create(null)`
|
|
211
212
|
- `TypedArray`
|
|
212
213
|
- `Int8Array`
|
|
213
214
|
- `Int16Array`
|
|
@@ -230,11 +231,12 @@ The following values are the only values accepted by `seroval`:
|
|
|
230
231
|
- `URIError`
|
|
231
232
|
- `Promise` (with `serializeAsync`)
|
|
232
233
|
- [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol)
|
|
234
|
+
- [Well-known symbols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#static_properties)
|
|
233
235
|
- Cyclic references (both self and mutual)
|
|
234
236
|
|
|
235
237
|
## Compat
|
|
236
238
|
|
|
237
|
-
`serialize`, `serializeAsync`, `toJSON` and `toJSONAsync` can accept a `{ disabledFeatures: number }` option. The `disabledFeatures` defines how
|
|
239
|
+
`serialize`, `serializeAsync`, `toJSON` and `toJSONAsync` can accept a `{ disabledFeatures: number }` option. The `disabledFeatures` defines how the output code would look like when serialized by `serialize`, `serializeAsync` and `compileJSON`.
|
|
238
240
|
|
|
239
241
|
```js
|
|
240
242
|
import { serialize, Feature } from 'seroval';
|
|
@@ -281,31 +283,41 @@ By default, all feature flags are enabled. The following are the feature flags a
|
|
|
281
283
|
- [`AggregateError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError)
|
|
282
284
|
- Compiles down to `Error` instead.
|
|
283
285
|
- [`ArrayPrototypeValues`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
|
|
284
|
-
- Used for
|
|
286
|
+
- Used for `Iterable`, uses `Symbol.iterator` instead.
|
|
285
287
|
- [`ArrowFunction`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)
|
|
286
|
-
- Uses function expressions for top-level and for deferred Promise values
|
|
287
|
-
- method shorthands (if `MethodShortand` is not set) or function expressions for
|
|
288
|
+
- Uses function expressions for top-level and for deferred `Promise` values
|
|
289
|
+
- method shorthands (if `MethodShortand` is not set) or function expressions for `Iterable`.
|
|
288
290
|
- [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
|
|
289
291
|
- Throws when attempted to use, includes `BigIntTypedArray`
|
|
292
|
+
- Disables use of `BigInt`, `BigInt64Array` and `BigUint64Array`
|
|
290
293
|
- [`ErrorPrototypeStack`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack)
|
|
291
294
|
- Skipped when detected.
|
|
295
|
+
- Affects both `Error` and `AggregateError`
|
|
292
296
|
- [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
|
|
293
297
|
- Throws when attempted to use.
|
|
298
|
+
- Disables serialization of `Map`
|
|
294
299
|
- [`MethodShorthand`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions)
|
|
295
300
|
- Uses function expressions instead.
|
|
301
|
+
- Only affects `Iterable`
|
|
296
302
|
- [`ObjectAssign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
|
|
297
303
|
- Uses manual object assignments instead.
|
|
304
|
+
- Affects `Iterable`, `Error`, `AggregateError` and `Object.create(null)`
|
|
298
305
|
- [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
|
299
306
|
- Throws when attempted to use in `serializeAsync` and `toJSONAsync`.
|
|
307
|
+
- Disables serialization of `Promise`
|
|
300
308
|
- [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
|
|
301
309
|
- Throws when attempted to use.
|
|
302
|
-
-
|
|
310
|
+
- Disables serialization of `Set`
|
|
311
|
+
- [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)
|
|
303
312
|
- Throws when attempted to use.
|
|
313
|
+
- This disables serialization of well-known symbols and `Iterable`.
|
|
304
314
|
- [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
|
|
305
315
|
- Throws when attempted to use.
|
|
316
|
+
- Disables serialization of `TypedArray`
|
|
306
317
|
- [`BigIntTypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array)
|
|
307
318
|
- Throws when attempted to use
|
|
308
319
|
- Also throws if `BigInt` is disabled.
|
|
320
|
+
- Disables serialization of `BigInt64Array` and `BigUint64Array`
|
|
309
321
|
|
|
310
322
|
## Sponsors
|
|
311
323
|
|