1
This commit is contained in:
27
parent_dir/node_modules/brillout/json-serializer/dist/esm/parse.js
generated
vendored
Normal file
27
parent_dir/node_modules/brillout/json-serializer/dist/esm/parse.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
export { parse };
|
||||
import { types } from './types';
|
||||
function parse(str) {
|
||||
// We don't use the reviver option in `JSON.parse(str, reviver)` because it doesn't support `undefined` values
|
||||
const value = JSON.parse(str);
|
||||
return modifier(value);
|
||||
}
|
||||
function modifier(value) {
|
||||
if (typeof value === 'string') {
|
||||
return reviver(value);
|
||||
}
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
Object.entries(value).forEach(([key, val]) => {
|
||||
;
|
||||
value[key] = modifier(val);
|
||||
});
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function reviver(value) {
|
||||
for (const { match, deserialize } of types) {
|
||||
if (match(value)) {
|
||||
return deserialize(value, parse);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
Reference in New Issue
Block a user