You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can serialize and serialize custom types by passing a second argument to `stringify` containing an object of types and their _reducers_, and a second argument to `parse` or `unflatten` containing an object of types and their _revivers_:
If a function passed to `stringify` returns a truthy value, it's treated as a match.
111
+
112
+
You can also use custom types with `uneval` by specifying a custom replacer:
113
+
114
+
```js
115
+
devalue.uneval(vector, (value, uneval) => {
116
+
if (value instanceof Vector) {
117
+
return`new Vector(${value.x},${value.y})`;
118
+
}
119
+
}); // `new Vector(30,40)`
120
+
```
121
+
122
+
Note that any variables referenced in the resulting JavaScript (like `Vector` in the example above) must be in scope when it runs.
123
+
81
124
## Error handling
82
125
83
126
If `uneval` or `stringify` encounters a function or a non-POJO, it will throw an error. You can find where in the input data the offending value lives by inspecting `error.path`:
0 commit comments