The configuration object is a map of paths to coercion types.
These paths may also contain wildcards ('*'), which matches any single element in the path at that position.
However, it will not match multiple elements (or no elements) in the path.
For example, 'foo.*' will match 'foo.bar', but not'foo' or 'foo.bar.baz'.
Paths containing numbers (e.g. 'arr.0') will match both arr: ['me!'] and arr: { '0': 'me!' }.
🚨Important: There must be a '*' key in the configuration object, which will be used as the default coercion for all paths that do not have a specific coercion defined.
This key is required, and the configuration will throw an error if it is not present.
Overview
This method of configuring the numerical deserialization behavior uses a configuration object that maps paths to coercion types.
If you'd prefer to use a more flexible approach, you can use the CollNumCoercionFn type to define the coercion for each path.
Example
The configuration object
The configuration object is a map of paths to coercion types.
These paths may also contain wildcards (
'*'
), which matches any single element in the path at that position.'foo.*'
will match'foo.bar'
, but not'foo'
or'foo.bar.baz'
.Paths containing numbers (e.g.
'arr.0'
) will match botharr: ['me!']
andarr: { '0': 'me!' }
.Using a single CollNumCoercion
You may simply use
{ '*': '<type>' }
to return a single coercion type for all paths.This is specifically optimized to be just as fast as using
() => '<type>'
.See