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 CHANGED
@@ -1,4 +1,4 @@
1
- MIT License Copyright (c) 2023 <author>
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 seroval from 'seroval';
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 = seroval(object);
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 seroval from 'seroval';
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 = seroval({ a, b, c, d });
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
+ ![Sponsors](https://github.com/lxsmnsyc/sponsors/blob/main/sponsors.svg?raw=true)
181
+
151
182
  ## License
152
183
 
153
184
  MIT © [lxsmnsyc](https://github.com/lxsmnsyc)