What is @types/object-path?
@types/object-path provides TypeScript type definitions for the object-path library, which allows for easy manipulation and access of deep properties within JavaScript objects.
What are @types/object-path's main functionalities?
Get a value at a given path
This feature allows you to retrieve the value at a specified path within an object. If the path does not exist, it returns undefined.
const objectPath = require('object-path');
const obj = { a: { b: { c: 42 } } };
const value = objectPath.get(obj, 'a.b.c');
console.log(value); // 42
Set a value at a given path
This feature allows you to set a value at a specified path within an object. If the path does not exist, it will be created.
const objectPath = require('object-path');
const obj = { a: { b: { } } };
objectPath.set(obj, 'a.b.c', 42);
console.log(obj); // { a: { b: { c: 42 } } }
Delete a value at a given path
This feature allows you to delete the value at a specified path within an object. If the path does not exist, the object remains unchanged.
const objectPath = require('object-path');
const obj = { a: { b: { c: 42 } } };
objectPath.del(obj, 'a.b.c');
console.log(obj); // { a: { b: { } } }
Check if a path exists
This feature allows you to check if a specified path exists within an object. It returns true if the path exists, otherwise false.
const objectPath = require('object-path');
const obj = { a: { b: { c: 42 } } };
const exists = objectPath.has(obj, 'a.b.c');
console.log(exists); // true
Other packages similar to @types/object-path
lodash
Lodash is a popular utility library that provides a wide range of functions for manipulating arrays, objects, and other data types. It includes similar functionalities for deep property access and manipulation, such as _.get, _.set, and _.has. Compared to object-path, Lodash offers a broader set of utilities beyond just object manipulation.
dot-prop
dot-prop is a small utility for accessing and manipulating object properties using dot notation. It provides similar functionalities to object-path, such as get, set, delete, and has methods. dot-prop is lightweight and focused specifically on property access and manipulation, making it a good alternative for those who need a minimalistic solution.
deepdash
Deepdash is an extension for Lodash that adds deep traversal and manipulation capabilities. It provides similar functionalities to object-path, such as deep get, set, and delete operations. Deepdash is useful for those who are already using Lodash and need additional deep manipulation features.