Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Nov 19, 2023
1 parent cb0b9bf commit d8fbd41
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 62 deletions.
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
))();
```

Expand Down
4 changes: 2 additions & 2 deletions docs/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))()
```

Expand Down Expand Up @@ -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)
Expand Down
32 changes: 17 additions & 15 deletions packages/seroval/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
))();
```

Expand Down
42 changes: 12 additions & 30 deletions packages/seroval/test2.js
Original file line number Diff line number Diff line change
@@ -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));
serializeWithTarget(y, Feature.ArrowFunction | Feature.ObjectAssign);
serializeWithTarget(y, 0);

0 comments on commit d8fbd41

Please sign in to comment.