UNPKG

ejson2

Version:
40 lines 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.adjustTypesToJSONValue = void 0; /** * for both arrays and objects, in-place modification. */ const utils_1 = require("../../utils"); const to_json_value_helper_1 = require("./to-json-value-helper"); const adjustTypesToJSONValue = obj => { // Is it an atom that we need to adjust? if (obj === null) { return null; } const maybeChanged = (0, to_json_value_helper_1.toJSONValueHelper)(obj); if (maybeChanged !== undefined) { return maybeChanged; } // Other atoms are unchanged. if (!(0, utils_1.isObject)(obj)) { return obj; } // Iterate over array or object structure. (0, utils_1.keysOf)(obj).forEach(key => { const value = obj[key]; if (!(0, utils_1.isObject)(value) && value !== undefined && !(0, utils_1.isInfOrNaN)(value)) { return; // continue } const changed = (0, to_json_value_helper_1.toJSONValueHelper)(value); if (changed) { obj[key] = changed; return; // on to the next key } // if we get here, value is an object but not adjustable // at this level. recurse. (0, exports.adjustTypesToJSONValue)(value); }); return obj; }; exports.adjustTypesToJSONValue = adjustTypesToJSONValue; //# sourceMappingURL=adjust-types-to-json-value.js.map