reach v1.0.1
reach
Safely retrieve nested object keys. Inspired by the Hoek module's reach() method.
const Reach = require('reach');
const obj = {
foo: {
bar: {
baz: 3
}
}
};
Reach(obj, 'foo.bar.baz');
// Returns 3Methods
Reach exports a single function, described below.
reach(obj, chain [, options])
- Arguments
obj(object) - An object to retrieve a value from.chain(string) - A string specifying the path to traverse withinobj. Path segments are delimited by periods ('.') by default. If a non-string is provided, aTypeErroris thrown.options(object) - A configuration object supporting the following keys.separator(string) - Path segment delimiter. Defaults to'.'.strict(boolean) - Iftrue, an error is thrown when the completechaincannot be found inobj. Defaults tofalse.default- The value returned if the completechaincannot be found inobj, andstrictisfalse. Defaults toundefined.
- Returns
- The value found by traversing
chainthroughobj. If no value is found, and thestrictoption isfalse(default behavior), thendefaultis returned.
- The value found by traversing
Traverses an object, obj. The path through the object is dictated by the chain string.
8 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago