ejson2
Version:
Extended JSON Evolved
28 lines • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromJSONValueHelper = void 0;
/**
* Either return the argument changed to have the non-json
* rep of itself (the Object version) or the argument itself.
* DOES NOT RECURSE. For actually getting the fully-changed value, use
* EJSON.fromJSONValue
*/
const utils_1 = require("../../utils");
const built_in_converters_1 = require("../built-in-converters");
const fromJSONValueHelper = value => {
if ((0, utils_1.isObject)(value) && value !== null) {
const keys = (0, utils_1.keysOf)(value);
if (keys.length <= 2 &&
keys.every(k => typeof k === 'string' && k.substr(0, 1) === '$')) {
for (let i = 0; i < built_in_converters_1.builtinConverters.length; i++) {
const converter = built_in_converters_1.builtinConverters[i];
if (converter.matchJSONValue(value)) {
return converter.fromJSONValue(value);
}
}
}
}
return value;
};
exports.fromJSONValueHelper = fromJSONValueHelper;
//# sourceMappingURL=from-json-value-helper.js.map