@winglet/json
Version:
TypeScript library for safe and efficient JSON data manipulation with RFC 6901 (JSON Pointer) and RFC 6902 (JSON Patch) compliance, featuring prototype pollution protection and immutable operations
15 lines (11 loc) • 633 B
JavaScript
;
var filter = require('@winglet/common-utils/filter');
var compileSegments = require('./utils/compileSegments.cjs');
var error = require('./utils/error.cjs');
var setValueByPointer = require('./utils/setValueByPointer.cjs');
const setValue = (input, pointer, value, overwrite = true) => {
if (!(filter.isPlainObject(input) || filter.isArray(input)))
throw new error.JSONPointerError('INVALID_INPUT', '`input` must be a plain object or an array.', { input });
return setValueByPointer.setValueByPointer(input, compileSegments.compilePointer(pointer), value, overwrite);
};
exports.setValue = setValue;