Members
(inner) renameKeys
Creates a new object with the own properties of the provided object, but the
keys renamed according to the keysMap object as {oldKey: newKey}
.
When some key is not found in the keysMap, then it's passed as-is.
Methods
(inner) allKeysContaining(str, obj) → {Object}
Takes a string and an object, and returns a flattened copy of the object with any key in the object that contains the specified string regardless of the depth each key is located at within the object
Parameters:
Name | Type | Description |
---|---|---|
str |
String | string to search for in each key |
obj |
Object | object to search for keys in |
Returns:
Object with keys that contain the specified string
- Type
- Object
Example
const obj = {
a1: 'something',
a2: 'something else',
a3: { b: { dragon: true } }
}
allKeysContaining('rag', obj) //=> { 'a.b.dragon': true }
(inner) anyPropSatisfies(predicate, obj) → {Boolean}
Takes a predicate and an object and returns true if the value of any of the objects properties pass the predicate
Parameters:
Name | Type | Description |
---|---|---|
predicate |
function | pass or fail each key's value |
obj |
Object | object to analyze |
Returns:
true if any key's value passes the predicate
- Type
- Boolean
(inner) makeLenses(propNames) → {Object}
Takes a list of string prop names, and returns an object where each key is a lens for its respective prop
Parameters:
Name | Type | Description |
---|---|---|
propNames |
Array.<string> | list of property names |
Returns:
map of lenses
- Type
- Object
(inner) mapKeys(fn, data) → {Object}
Takes a function (g) and an object and returns an object where each key is the result of invoking g with that key
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | function applied to each key |
data |
Object | object to map keys from |
Returns:
- Type
- Object
Example
const obj { a: 1, b: 2, c: 3 }
const upper = key => key.toUpperCase()
const upperCaseKeys = mapKeys(upper)
const upperCaseKeys(obj)
//=> { A: 1, B: 2, C: 3 }
(inner) pickDeep(pathToProp, pickList, obj) → {Object}
Return a whitelisted set of keys from nested object path
Parameters:
Name | Type | Description |
---|---|---|
pathToProp |
Array.<String> | list of strings used as path to prop |
pickList |
Array.<String> | list of property names to pick |
obj |
Object | object to pick properties from |
Returns:
clone of the object at the specified path of the original object with all but the specified keys removed
- Type
- Object
Example
const obj = {
one: {
two: {
three: {
animal: {
type: 'fish',
name: 'mark',
game: 'polo',
},
},
},
},
}
const path = ['one', 'two', 'three', 'animal']
const props = ['name', 'game']
pickDeep(path, props, obj) //=> { name: 'mark', game: 'polo' }