Skip to content

jucian0/object-path

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Object Path - TDD implementation

An immutable implementation of dot-prop

tests

Get, set, or delete a property from a nested object using a dot path

get(object, path, defaultValue?) Get the value of the property at the given path.

Returns a value if any.

const obj = {
  property: {
    test: "A",
  },
};

const result = get(obj, "property");

Set the property at the given path to the given value.

set(object, path, value)

Returns a object.

const obj = {
  property: {
    test: "A",
  },
};

const result = set(obj, "property", "B");

Delete the property at the given path.

delete(object, path)

Returns a object without the property deleted.

const obj = {
  property: {
    test: "A",
  },
};

const result = del(obj, "property.test");

Merge the property that has an array or an object.

merge(object, path)

Returns a object with the property and value passed by argument merged.

const obj = {
  property: {
    test: [1, 2],
  },
};

const result = merge(obj, "property.test", [3, 4]);

Run Tests

yarn test

About

An immutable implementation of dot-prop.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published