@@ -21,11 +21,18 @@ Serialization uses
21
21
[ ` URLSearchParams.toString() ` ] ( https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/toString#return_value )
22
22
which encodes most non-alphanumeric characters.
23
23
24
- - The primitive types ` string ` , ` number ` , and ` bigint ` are serialized using ` .toString() ` .
25
- - The primitive ` boolean ` type is serialized using ` .toString() ` to ` 'true' ` or ` 'false' ` .
24
+ Serialization is guaranteed to be well-defined within each type, i.e.,
25
+ if the type of value for a given key in the query string is fixed and known by
26
+ the consumer parsing the string, it can be unambigously parsed back to the original primitive value.
27
+
28
+ - The primitive type ` string ` is serialized using ` .toString() ` .
29
+ - The primitive ` number ` and ` bigint ` types are serialized using ` .toString() ` .
30
+ - The primitive ` boolean ` type is serialized using ` .toString() ` ,
31
+ e.g., ` { foo: true, bar: false } ` serializes to ` foo=true&bar=false ` .
26
32
- The primitive ` null ` and ` undefined ` values are removed,
27
33
e.g., ` { foo: null, bar: undefined, baz: 1 } ` serializes to ` baz=1 ` .
28
- - ` Date ` objects are detected and serialized using ` Date.toISOString() ` .
34
+ - ` Date ` objects are detected and serialized using ` Date.toISOString() ` ,
35
+ e.g., ` { foo: new Date(0) } ` serializes to ` foo=1970-01-01T00%3A00%3A00.000Z ` .
29
36
- ` Temporal.Instant ` objects are detected and serialized by first converting them to ` Date `
30
37
and then serializing the ` Date ` as above.
31
38
- Arrays are serialized using
@@ -34,12 +41,20 @@ which encodes most non-alphanumeric characters.
34
41
- The array ` { foo: [1, 2] } ` serializes to ` foo=1&foo=2 ` .
35
42
- The single element array ` { foo: [1] } ` serializes to ` foo=1 ` .
36
43
- The empty array ` { foo: [] } ` serializes to ` foo= ` .
37
- - Serialization of the single element array containing the empty string is not supported
38
- and will throw an ` UnserializableParamError ` .
44
+ - Serialization of arrays containing ` null ` or ` undefined ` values
45
+ is not supported and will throw an ` UnserializableParamError ` .
46
+ - Serialization of the single element array containing the empty string
47
+ is not supported and will throw an ` UnserializableParamError ` .
39
48
Otherwise, the serialization of ` { foo: [''] } ` would conflict with ` { foo: [] } ` .
40
49
This serializer chooses to support the more common and more useful case of an empty array.
41
- - Serialization of functions or other objects is not supported
42
- and will throw an ` UnserializableParamError ` .
50
+ - Serialization of objects and nested objects first serializes the keys
51
+ to dot-path format and then serializes the values as above, e.g.,
52
+ ` { foo: 'a', bar: { baz: 'b', fizz: [1, 2] } } ` serializes to
53
+ ` foo=a&bar.baz=b&bar.fizz=1&bar.fizz=2 ` .
54
+ - Serialization of nested arrays or objects nested inside arrays
55
+ is not supported and will throw an ` UnserializableParamError ` .
56
+ - Serialization of functions or other objects is
57
+ is not supported and will throw an ` UnserializableParamError ` .
43
58
44
59
## Installation
45
60
0 commit comments