From d8fbd415fea53d6ef19d80597ed3b61c75aff997 Mon Sep 17 00:00:00 2001 From: "Alexis H. Munsayac" Date: Sun, 19 Nov 2023 17:56:35 +0800 Subject: [PATCH] Fix docs --- README.md | 32 +++++++++++++++-------------- docs/compatibility.md | 4 ++-- packages/seroval/README.md | 32 +++++++++++++++-------------- packages/seroval/test2.js | 42 +++++++++++--------------------------- 4 files changed, 48 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 75c203b4..3810f171 100644 --- a/README.md +++ b/README.md @@ -59,12 +59,12 @@ console.log(result); Output (as a string): ```js -((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))() +((h,j,k,m,o)=>(o={number:[0.3325212548332517,-0,0/0,1/0,-1/0],string:["hello world","\x3Cscript>Hello World\x3C/script>"],boolean:[!0,!1],null:null,undefined:void 0,bigint:9007199254740991n,array:h=[,,,,k=(j=[],new Map([["hello","world"],["mutual",m=new Set(["hello","world"])]]))],regexp:/[a-z0-9]+/i,date:new Date("2023-11-19T09:25:24.118Z"),map:k,set:m},h[3]=h,k.set("self",k),m.add(m).add(h),o.self=o,o))() // Formatted for readability -((h, j, k, m) => ( - (m = { - number: [0.7499861043679861, -0, 0 / 0, 1 / 0, -1 / 0], +((h, j, k, m, o) => ( + (o = { + number: [0.3325212548332517, -0, 0 / 0, 1 / 0, -1 / 0], string: ["hello world", "\x3Cscript>Hello World\x3C/script>"], boolean: [!0, !1], null: null, @@ -75,21 +75,23 @@ Output (as a string): , , , - (j = new Map([ - ["hello", "world"], - ["mutual", (k = new Set(["hello", "world"]))], - ])), + (k = + ((j = []), + new Map([ + ["hello", "world"], + ["mutual", (m = new Set(["hello", "world"]))], + ]))), ]), regexp: /[a-z0-9]+/i, - date: new Date("2023-10-19T05:11:59.516Z"), - map: j, - set: k, + date: new Date("2023-11-19T09:25:24.118Z"), + map: k, + set: m, }), (h[3] = h), - j.set("self", j), - k.add(k).add(h), - (m.self = m), - m + k.set("self", k), + m.add(m).add(h), + (o.self = o), + o ))(); ``` diff --git a/docs/compatibility.md b/docs/compatibility.md index d04aa1ce..b88f51aa 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -21,7 +21,7 @@ serializeWithTarget(y, 0); ``` ```js -(function(h){return (h=Object.create(null),h.self=h,h.example="Hello World",h)})() +(function(h){return (h=(h=Object.create(null),h.example="Hello World",h),h.self=h,h)})() (h=>(h=Object.assign(Object.create(null),{example:"Hello World"}),h.self=h,h))() ``` @@ -65,7 +65,7 @@ By default, all feature flags are enabled. The following are the feature flags a - [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) - Disables serialization of `Set` - [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) - - Disables serialization of well-known symbols and `Iterable`. + - Disables serialization of well-known symbols, `Iterable` and `AsyncIterable`. - [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) - Disables serialization of `TypedArray` - [`BigIntTypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array) diff --git a/packages/seroval/README.md b/packages/seroval/README.md index 75c203b4..3810f171 100644 --- a/packages/seroval/README.md +++ b/packages/seroval/README.md @@ -59,12 +59,12 @@ console.log(result); Output (as a string): ```js -((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))() +((h,j,k,m,o)=>(o={number:[0.3325212548332517,-0,0/0,1/0,-1/0],string:["hello world","\x3Cscript>Hello World\x3C/script>"],boolean:[!0,!1],null:null,undefined:void 0,bigint:9007199254740991n,array:h=[,,,,k=(j=[],new Map([["hello","world"],["mutual",m=new Set(["hello","world"])]]))],regexp:/[a-z0-9]+/i,date:new Date("2023-11-19T09:25:24.118Z"),map:k,set:m},h[3]=h,k.set("self",k),m.add(m).add(h),o.self=o,o))() // Formatted for readability -((h, j, k, m) => ( - (m = { - number: [0.7499861043679861, -0, 0 / 0, 1 / 0, -1 / 0], +((h, j, k, m, o) => ( + (o = { + number: [0.3325212548332517, -0, 0 / 0, 1 / 0, -1 / 0], string: ["hello world", "\x3Cscript>Hello World\x3C/script>"], boolean: [!0, !1], null: null, @@ -75,21 +75,23 @@ Output (as a string): , , , - (j = new Map([ - ["hello", "world"], - ["mutual", (k = new Set(["hello", "world"]))], - ])), + (k = + ((j = []), + new Map([ + ["hello", "world"], + ["mutual", (m = new Set(["hello", "world"]))], + ]))), ]), regexp: /[a-z0-9]+/i, - date: new Date("2023-10-19T05:11:59.516Z"), - map: j, - set: k, + date: new Date("2023-11-19T09:25:24.118Z"), + map: k, + set: m, }), (h[3] = h), - j.set("self", j), - k.add(k).add(h), - (m.self = m), - m + k.set("self", k), + m.add(m).add(h), + (o.self = o), + o ))(); ``` diff --git a/packages/seroval/test2.js b/packages/seroval/test2.js index b9d4d16d..1ebc00b5 100644 --- a/packages/seroval/test2.js +++ b/packages/seroval/test2.js @@ -1,33 +1,15 @@ +import { serialize, Feature } from 'seroval'; -import { serialize } from './dist/esm/development/index.mjs'; +const y = Object.create(null); +y.self = y; +y.example = 'Hello World'; -// const instance = new Serializer({ -// globalIdentifier: 'test', -// onData: console.log, -// }); +function serializeWithTarget(value, disabledFeatures) { + const result = serialize(value, { + disabledFeatures, + }); + console.log(result); +} -// const example = { foo: 'bar' }; - -// function* hello() { -// yield example; -// } - -// instance.write('foo', hello()); -// instance.write('bar', hello()); - -const example = { - a: new Map(), - b: new Set(), -}; - -example.a.set(example.a, example.b); - -const example2 = { - foo: new Map(), - bar: new Set(), -}; - -example2.foo.set(example2.foo, example2.bar); -example2.heck = example; - -console.log(serialize(example2)); \ No newline at end of file +serializeWithTarget(y, Feature.ArrowFunction | Feature.ObjectAssign); +serializeWithTarget(y, 0); \ No newline at end of file