seroval 0.5.1 → 0.7.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
@@ -186,6 +186,37 @@ console.log(await deserialize(result)); // 100
186
186
  > **Note**
187
187
  > `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.
188
188
 
189
+ ## Serializable references
190
+
191
+ There are values that has no way to be serializable at all, i.e. functions, but usually in an isomorphic code, functions can exist on both client and server-side. What if we can serialize these functions in such a way we can refer to their counterparts?
192
+
193
+ `seroval` has `createReference` that you can use to map user-defined strings to their references.
194
+
195
+ ```js
196
+ import { createReference } from 'seroval';
197
+
198
+ const thisIsAnIsomorphicFunction = createReference(
199
+ // This is (ideally) a unique identifier
200
+ // that is used to map the serialized value
201
+ // to its actual reference (and vice versa)
202
+ 'my-function',
203
+ () => {
204
+ // Ideally this function should exist on both
205
+ // server and client, but we want to add the ability
206
+ // to serialize and deserialize this reference on
207
+ // both sides
208
+ }
209
+ );
210
+
211
+ // we can now serialize this
212
+ const serialized = toJSON(thisIsAnIsomorphicFunction); // or any of the serializer
213
+ thisIsAnIsomorphicFunction === fromJSON(serialized); // true
214
+ ```
215
+
216
+ > **Note**
217
+ > It can only accept objects, functions and symbols and it doesn't actually
218
+ > serialize their values but only the string you used to identify the reference
219
+
189
220
  ## Supports
190
221
 
191
222
  The following values are the only values accepted by `seroval`:
@@ -209,6 +240,8 @@ The following values are the only values accepted by `seroval`:
209
240
  - `Map`
210
241
  - `Set`
211
242
  - `Object.create(null)`
243
+ - `ArrayBuffer`
244
+ - `DataView`
212
245
  - `TypedArray`
213
246
  - `Int8Array`
214
247
  - `Int16Array`
@@ -229,10 +262,19 @@ The following values are the only values accepted by `seroval`:
229
262
  - `SyntaxError`
230
263
  - `TypeError`
231
264
  - `URIError`
232
- - `Promise` (with `serializeAsync`)
265
+ - `Promise` (with `serializeAsync` and `toJSONAsync`)
233
266
  - [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol)
234
267
  - [Well-known symbols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#static_properties)
268
+ - Web API
269
+ - [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL)
270
+ - [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
271
+ - [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) (with `serializeAsync` and `toJSONAsync`)
272
+ - [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) (with `serializeAsync` and `toJSONAsync`)
273
+ - [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers)
274
+ - [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
275
+ - If `FormData` has a `Blob`/`File` entry, it can only be serialized with `serializeAsync` and `toJSONAsync`
235
276
  - Cyclic references (both self and mutual)
277
+ - Isomorphic references (a reference that exist on both the serializer and deserializer side)
236
278
 
237
279
  ## Compat
238
280
 
@@ -318,6 +360,14 @@ By default, all feature flags are enabled. The following are the feature flags a
318
360
  - Throws when attempted to use
319
361
  - Also throws if `BigInt` is disabled.
320
362
  - Disables serialization of `BigInt64Array` and `BigUint64Array`
363
+ - `WebAPI`
364
+ - Throws and disables the following usage:
365
+ - [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL)
366
+ - [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
367
+ - [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
368
+ - [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File)
369
+ - [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers)
370
+ - [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
321
371
 
322
372
  ## Sponsors
323
373