What is obj-case?
The obj-case npm package provides utilities for manipulating and accessing properties within JavaScript objects using dot notation. It simplifies the process of getting, setting, and deleting nested properties.
What are obj-case's main functionalities?
Get Property
This feature allows you to retrieve the value of a nested property within an object using a dot-notated string.
const objCase = require('obj-case');
const obj = { a: { b: { c: 42 } } };
const value = objCase.get(obj, 'a.b.c');
console.log(value); // 42
Set Property
This feature allows you to set the value of a nested property within an object using a dot-notated string.
const objCase = require('obj-case');
const obj = { a: { b: { } } };
objCase.set(obj, 'a.b.c', 42);
console.log(obj); // { a: { b: { c: 42 } } }
Delete Property
This feature allows you to delete a nested property within an object using a dot-notated string.
const objCase = require('obj-case');
const obj = { a: { b: { c: 42 } } };
objCase.del(obj, 'a.b.c');
console.log(obj); // { a: { b: { } } }
Other packages similar to obj-case
lodash
Lodash is a popular utility library that provides a wide range of functions for manipulating arrays, objects, and other data types. It includes methods like _.get, _.set, and _.unset for working with nested properties, similar to obj-case.
dot-prop
Dot-prop is a lightweight package specifically designed for getting, setting, and deleting nested properties in objects using dot notation. It offers similar functionality to obj-case but is more focused and minimalistic.
object-path
Object-path is another utility library for accessing and manipulating deep properties in objects using dot notation. It provides a comprehensive set of methods for working with nested properties, similar to obj-case.
obj-case
Work with objects of different cased keys. Anything supported by nbubna/Case. Makes finding and editing objects between languages a little more forgiving while still not modifying the original JSON.
Installation
Install with component(1):
$ component install segmentio/obj-case
API
.find(obj, key)
Returns the value for the object with the given key
var obj = { my : { super_cool : { climbingShoes : 'x' }}};
objCase.find(obj, 'my.superCool.CLIMBING SHOES');
.del(obj, key)
Deletes a nested key
var obj = { 'a wild' : { mouse : { APPEARED : true }}};
objCase.del(obj, 'aWild.mouse.appeared');
console.log(obj);
.replace(obj, key)
Replaces a nested key
var obj = { replacing : { keys : 'is the best' }};
objCase.replace(obj, 'replacing.keys', 'is just okay');
console.log(obj)
License
MIT