Wrapper around the Object.entries method. Returns an array of arrays where each sub array maps to a key:value pair; the first element being the key, and the second element being the value.
Usage:
Obj.keys({ name: "Brian", age: 25, gender: "M" }) // ["name", "age", "gender"]
Wrapper around the Object.freeze method. Returns a frozen instance of the object passed in. Attempts to modify this new frozen object will throw an erro
Usage:
const frozenBrian = Obj.freeze({ name: "Brian", age: 25, gender: "M" })
frozenBrian.age = 26 // Throws error
console.log(frozenBrian.age) // 25
Retrieves data deeply nested within an object.
This prevents having to check for null or undefined values at each nested level of the object.
Usage:
const object = {
a: {
b: {
c: "Hello!"
}
}
}
Obj.getIn("a", "b", "c", object) // "Hello!"
Obj.getIn("x", "y", object) // null
Returns true or false if value passed in is an empty object.
Non-object inputs yield a null return value
Usage:
Obj.isEmpty({}) // true
Obj.isEmpty({ a: "hello" }) // false
Obj.isEmpty(1) // null
Wrapper around the Object.keys method. Returns an array of strings specifying the keys on an object.
Usage:
Obj.keys({ name: "Brian", age: 25, gender: "M" }) // ["name", "age", "gender"]
Returns a new object that has only the specified fields
Non-object inputs yield a null return value
Usage:
Obj.onlyKeys(["name", "age"], { name: "Brian", age: 25, gender: "M" }) // { name: "Brian", age: 25 }
Wrapper around the Object.values method. Returns an array of the values inside an object.
Usage:
Obj.values({ name: "Brian", age: 25, gender: "M" }) // ["Brian", 25, "M"]
Returns a new object that has the specified fields omitted
Non-object inputs yield a null return value
Usage:
Obj.withoutKeys(["age"], { name: "Brian", age: 25, gender: "M" }) // { name: "Brian", gender: "M" }
The Obj module provides utility methods for dealing with objects.