seroval 0.3.0 → 0.4.0-alpha.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 CHANGED
@@ -58,11 +58,11 @@ const result = serialize(object);
58
58
  Output (as a string):
59
59
 
60
60
  ```js
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))()
61
+ ((h,j,k,m)=>(m={number:[0.5623457676854244,-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-14T11:16:24.879Z"),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
64
  ((h, j, k, m) => (m = {
65
- number: [0.4178420745429774, -0, NaN, 1/0, -1/0],
65
+ number: [0.5623457676854244, -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,
@@ -73,7 +73,7 @@ Output (as a string):
73
73
  ["mutual", k = new Set(["hello", "world"])]
74
74
  ])],
75
75
  regexp: /[a-z0-9]+/i,
76
- date: new Date("2023-03-13T00:52:11.335Z"),
76
+ date: new Date("2023-03-14T11:16:24.879Z"),
77
77
  map: j,
78
78
  set: k
79
79
  }, h[3] = h, j.set("self", j), k.add(k).add(h), m.self = m, m))()
@@ -196,6 +196,91 @@ The following values are the only values accepted by `seroval`:
196
196
  - [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol)
197
197
  - Cyclic references (both self and mutual)
198
198
 
199
+ ## Compat
200
+
201
+ `serialize` and `serializeAsync` can accept a `{ target: string | string[] }` options. The `target` property decides what the serialization output would look like. The default target is `es2023`.
202
+
203
+ ```js
204
+ import { serialize } from 'seroval';
205
+
206
+ const y = Object.create(null);
207
+ y.self = y;
208
+ y.example = 'Hello World';
209
+
210
+ function serializeWithTarget(value, target) {
211
+ console.log('Target is', target)
212
+ const result = serialize(value, {
213
+ target,
214
+ });
215
+ console.log(result);
216
+ }
217
+
218
+ serializeWithTarget(y, 'es5');
219
+ serializeWithTarget(y, 'es2023');
220
+ ```
221
+
222
+ Output
223
+
224
+ ```
225
+ Target is es5
226
+ (function(h){return (h=Object.create(null),h.self=h,h.example="Hello World",h)})()
227
+ Target is es2023
228
+ (h=>(h=Object.assign(Object.create(null),{example:"Hello World"}),h.self=h,h))()
229
+ ```
230
+
231
+ You can also combine targets:
232
+
233
+ ```js
234
+ serialize(value, {
235
+ targets: ['chrome85', 'edge85'],
236
+ });
237
+ ```
238
+
239
+ Supported runtimes:
240
+
241
+ - `es`
242
+ - Valid values are `es5`, `es6` and above (e.g. `es2020`).
243
+ - Desktop
244
+ - `chrome`
245
+ - `edge`
246
+ - `safari`
247
+ - `firefox`
248
+ - `opera`
249
+ - Mobile
250
+ - `ios`
251
+ - `samsung`
252
+ - Runtimes
253
+ - `deno`
254
+ - `node`
255
+
256
+ > **Note**
257
+ > Version for runtimes excluding `es` can use semver format (`major.minor.patch`) e.g. `chrome110`, `node0.12`
258
+
259
+ Feature flags and compat attempt:
260
+
261
+ - `AggregateError`
262
+ - Compiles down to `Error` instead.
263
+ - `Array.prototype.values`
264
+ - Used for iterables, uses `Symbol.iterator` instead.
265
+ - Arrow functions
266
+ - Uses function expressions for top-level, and either method shorthands or function expressions for iterables.
267
+ - `BigInt`
268
+ - Throws when attempted to use, includes `BigInt64Array` and `BigUint64Array`
269
+ - `Map`
270
+ - Throws when attempted to use.
271
+ - Method shorthands
272
+ - Uses function expressions instead.
273
+ - `Object.assign`
274
+ - Uses manual object assignments instead.
275
+ - `Promise`
276
+ - Throws when attempted to use, specially in `serializeAsync`.
277
+ - `Set`
278
+ - Throws when attempted to use.
279
+ - `Symbol.iterator`
280
+ - Throws when attempted to use.
281
+ - `TypedArray`
282
+ - Throws when attempted to use.
283
+
199
284
  ## Sponsors
200
285
 
201
286
  ![Sponsors](https://github.com/lxsmnsyc/sponsors/blob/main/sponsors.svg?raw=true)