Package Exports
- reach-es5
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (reach-es5) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
reach-es5
Forked from the great Reach package but es5-ified :( to please Webpack Uglify!
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 3
Methods
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, aTypeError
is 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 completechain
cannot be found inobj
. Defaults tofalse
.default
- The value returned if the completechain
cannot be found inobj
, andstrict
isfalse
. Defaults toundefined
.
- Returns
- The value found by traversing
chain
throughobj
. If no value is found, and thestrict
option isfalse
(default behavior), thendefault
is returned.
- The value found by traversing
Traverses an object, obj
. The path through the object is dictated by the chain
string.