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 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.9039984824241858,-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-16T11:57:24.849Z"),map:j,set:k},h[3]=h,j.set("self",j),k.add(k).add(h),m.self=m,m))()
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.9039984824241858, -0, NaN, 1 / 0, -1 / 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-16T11:57:24.849Z"),
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":8,"i":0,"d":{"k":["number","string","boolean","null","undefined","bigint","array","regexp","date","map","set","self"],"v":[{"t":7,"i":1,"a":[{"t":0,"s":0.7047255726239685},{"t":0,"s":"-0"},{"t":0,"s":null},{"t":0,"s":"1/0"},{"t":0,"s":"-1/0"}]},{"t":7,"i":2,"a":[{"t":0,"s":"\"hello world\""},{"t":0,"s":"\"\\x3Cscript>Hello World\\x3C/script>\""}]},{"t":7,"i":3,"a":[{"t":0,"s":"!0"},{"t":0,"s":"!1"}]},{"t":0,"s":null},{"t":0,"s":"void 0"},{"t":1,"s":"9007199254740991n"},{"t":7,"i":4,"a":[null,null,null,{"t":2,"i":4},{"t":6,"i":5,"d":{"k":[{"t":0,"s":"\"hello\""},{"t":0,"s":"\"self\""},{"t":0,"s":"\"mutual\""}],"v":[{"t":0,"s":"\"world\""},{"t":2,"i":5},{"t":5,"i":6,"a":[{"t":0,"s":"\"hello\""},{"t":0,"s":"\"world\""},{"t":2,"i":6},{"t":2,"i":4}]}],"s":3}}]},{"t":4,"i":7,"s":"/[a-z0-9]+/i"},{"t":3,"i":8,"s":"2023-03-16T12:01:29.836Z"},{"t":2,"i":5},{"t":2,"i":6},{"t":2,"i":0}],"s":12}},"r":0,"i":true,"f":8191,"m":[4,5,6,0]}
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 various code output of `serialize`, `serializeAsync` and `compileJSON`.
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 iterables, uses `Symbol.iterator` instead (if `SymbolIterator` is not set).
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 iterables.
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
- - [`SymbolIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
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