Get and set nested JavaScript object properties using MongoDB-like dot notation, supporting array indexing and wildcard array paths. Version 0.9.0 is the latest stable release (last updated 2020). Lightweight, zero-dependency utility for manipulating deep object structures. Key differentiators: supports array property notation (e.g., 'comments.title' returns array of titles), optional map transform on get, and combined array indexing/wildcard for complex nested queries. Minimal API with only `get` and `set` methods.
npm install mpathNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic get/set operations with array indexing and array property notation on nested objects.
Use mpath.get('array.0.field', obj) for a specific index; use mpath.get('array.field', obj) to get an array of field values across all array elements.Ensure the value array length matches the number of elements in the target array. For example, mpath.set('comments.title', ['a', 'b'], obj) when comments has two items.Ensure the path exists up to the parent before setting. Consider initializing nested objects beforehand.
Consider using lodash.get/set or native optional chaining for modern projects requiring ESM or TypeScript.
Check that the path exists or use a safe-get pattern: mpath.get(path, obj) || defaultValue. For setting, ensure parent is defined.
Use const mpath = require('mpath'); then mpath.set(...). Do not use import mpath from 'mpath'.Ensure the value array length equals the number of items in the target array path. For example, if obj.items has 3 elements, value must be an array of length 3.
No dependency data recorded yet.