seroval 0.1.0 → 0.2.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/LICENSE +1 -1
- package/README.md +35 -4
- package/dist/cjs/development/index.cjs +423 -255
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +2 -2
- package/dist/esm/development/index.mjs +423 -255
- package/dist/esm/development/index.mjs.map +4 -4
- package/dist/esm/production/index.mjs +2 -2
- package/dist/types/async.d.ts +4 -0
- package/dist/types/context.d.ts +33 -0
- package/dist/types/index.d.ts +6 -5
- package/dist/types/is-primitive.d.ts +2 -0
- package/dist/types/is-promise.d.ts +1 -0
- package/dist/types/serialize-primitive.d.ts +2 -0
- package/dist/types/sync.d.ts +4 -0
- package/dist/types/types.d.ts +9 -0
- package/package.json +2 -2
- package/src/async.ts +229 -0
- package/src/context.ts +200 -0
- package/src/get-identifier.ts +1 -0
- package/src/index.ts +69 -453
- package/src/is-primitive.ts +14 -0
- package/src/is-promise.ts +6 -0
- package/src/serialize-primitive.ts +32 -0
- package/src/sync.ts +199 -0
- package/src/types.ts +32 -0
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
MIT License Copyright (c) 2023 <
|
|
1
|
+
MIT License Copyright (c) 2023 Alexis Munsayac <alexis.munsayac@gmail.com>
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ pnpm add seroval
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
23
|
```js
|
|
24
|
-
import
|
|
24
|
+
import { serialize } from 'seroval';
|
|
25
25
|
|
|
26
26
|
const object = {
|
|
27
27
|
number: [Math.random(), -0, NaN, Infinity, -Infinity],
|
|
@@ -52,7 +52,7 @@ object.array.push(object.map);
|
|
|
52
52
|
object.map.set('mutual', object.set);
|
|
53
53
|
object.set.add(object.array);
|
|
54
54
|
|
|
55
|
-
const result =
|
|
55
|
+
const result = serialize(object);
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
Output (as a string):
|
|
@@ -82,7 +82,7 @@ Output (as a string):
|
|
|
82
82
|
### Mutual cyclic example
|
|
83
83
|
|
|
84
84
|
```js
|
|
85
|
-
import
|
|
85
|
+
import { serialize } from 'seroval';
|
|
86
86
|
|
|
87
87
|
const a = new Map([['name', 'a']]);
|
|
88
88
|
const b = new Map([['name', 'b']]);
|
|
@@ -96,7 +96,7 @@ d.set('right', b);
|
|
|
96
96
|
a.set('children', [c, d]);
|
|
97
97
|
b.set('children', [c, d]);
|
|
98
98
|
|
|
99
|
-
const result =
|
|
99
|
+
const result = serialize({ a, b, c, d });
|
|
100
100
|
```
|
|
101
101
|
|
|
102
102
|
Output (as a string):
|
|
@@ -124,6 +124,32 @@ Output (as a string):
|
|
|
124
124
|
}, o[0] = j, j.set("left", h), m.set("left", h).set("right", k), q))()
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
+
## Deserialization
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
import { serialize, deserialize } from 'seroval';
|
|
131
|
+
|
|
132
|
+
const value = undefined;
|
|
133
|
+
console.log(deserialize(serialize(value)) === value);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Promise serialization
|
|
137
|
+
|
|
138
|
+
`seroval` allows Promise serialization through `serializeAsync`.
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
import { serializeAsync } from 'seroval';
|
|
142
|
+
|
|
143
|
+
const value = Promise.resolve(100);
|
|
144
|
+
|
|
145
|
+
const result = await serializeAsync(value); // "Promise.resolve(100)"
|
|
146
|
+
|
|
147
|
+
console.log(await deserialize(result)); // 100
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
> **Note**
|
|
151
|
+
> `seroval` can only serialize the resolved value and so the output will always be using `Promise.resolve`. If the Promise fulfills with rejection, the rejected value is thrown before serialization happens.
|
|
152
|
+
|
|
127
153
|
## Supports
|
|
128
154
|
|
|
129
155
|
The following values are the only values accepted by `seroval`:
|
|
@@ -146,8 +172,13 @@ The following values are the only values accepted by `seroval`:
|
|
|
146
172
|
- `Date`
|
|
147
173
|
- `Map`
|
|
148
174
|
- `Set`
|
|
175
|
+
- `Promise` (with `serializeAsync`)
|
|
149
176
|
- Cyclic references (both self and mutual)
|
|
150
177
|
|
|
178
|
+
## Sponsors
|
|
179
|
+
|
|
180
|
+

|
|
181
|
+
|
|
151
182
|
## License
|
|
152
183
|
|
|
153
184
|
MIT © [lxsmnsyc](https://github.com/lxsmnsyc)
|