1.2.0 • Published 6 years ago

utils-object v1.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Utils-object

A collection of utilities dealing with object

Keymirror

Like the original FB's keymirror but add support for array and single string

objectUtils.keymirror([1, 2, "a"]);     //{1: "1", 2: "2", a: "a"}
objectUtils.keymirror({1: 1, 2: null, a: "bcd"});   //{1: "1", 2: "2", a: "a"}
objectUtils.keymirror("a"));    //{a: "a"}

Clone

var obj = {a: 1, b: 2};
objectUtils.clone(obj);     //{a: 1, b: 2}

OwnProperties

var obj = {a: 1, b: 2, c: "blah"};
objectUtils.ownProperties(obj); //  [{name: "a", value: 1}, {name: "b", value: 2}, {name: "c", value: "blah"}]

objectUtils.ownProperties(obj).forEach(
    ({name, value}) => {console.log(`Name: ${name}, value: ${value}`)}  //object destructuring is helpful here
);
1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago