UNPKG

@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

13 lines (10 loc) 550 B
import { isPlainObject, isArray } from '@winglet/common-utils/filter'; import { compilePointer } from './utils/compileSegments.mjs'; import { JSONPointerError } from './utils/error.mjs'; import { getValueByPointer } from './utils/getValueByPointer.mjs'; const getValue = (value, pointer) => { if (!(isPlainObject(value) || isArray(value))) throw new JSONPointerError('INVALID_INPUT', '`input` must be a plain object or an array.', { input: value }); return getValueByPointer(value, compilePointer(pointer)); }; export { getValue };