Skip to content

Commit bec8b86

Browse files
committedNov 26, 2018
Update docs
1 parent b159f54 commit bec8b86

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed
 

‎API.md

+14-8
Original file line numberDiff line numberDiff line change
@@ -137,28 +137,32 @@ var config = Hoek.applyToDefaults(defaults, options, true); // results in { host
137137
```
138138

139139
### applyToDefaultsWithShallow(defaults, options, keys)
140-
keys is an array of key names to shallow copy
140+
keys is an array of dot-separated, or array-based, key paths to shallow copy
141141

142142
Apply options to a copy of the defaults. Keys specified in the last parameter are shallow copied from options instead of merged.
143143

144144
```javascript
145145

146146
var defaults = {
147+
db: {
147148
server: {
148149
host: "localhost",
149150
port: 8000
150151
},
151152
name: 'example'
152-
};
153+
}
154+
};
153155

154156
var options = { server: { port: 8080 } };
155157

156-
var config = Hoek.applyToDefaultsWithShallow(defaults, options, ['server']); // results in { server: { port: 8080 }, name: 'example' }
158+
var config = Hoek.applyToDefaultsWithShallow(defaults, options, ['db.server']); // results in { db: { server: { port: 8080 }, name: 'example' } }
159+
var config = Hoek.applyToDefaultsWithShallow(defaults, options, [['db', 'server']]); // results in { db: { server: { port: 8080 }, name: 'example' } }
157160
```
158161

159162
### deepEqual(b, a, [options])
160163

161-
Performs a deep comparison of the two values including support for circular dependencies, prototype, and properties. To skip prototype comparisons, use `options.prototype = false`
164+
Performs a deep comparison of the two values including support for circular dependencies, prototype, and enumerable properties.
165+
To skip prototype comparisons, use `options.prototype = false`
162166

163167
```javascript
164168
Hoek.deepEqual({ a: [1, 2], b: 'string', c: { d: true } }, { a: [1, 2], b: 'string', c: { d: true } }); //results in true
@@ -218,16 +222,18 @@ flattenedArray = Hoek.flatten(array, target); // results in [4, [5], 1, 2, 3]
218222

219223
### reach(obj, chain, [options])
220224

221-
Converts an object key chain string to reference
225+
Converts an object key chain string or array to reference
222226

223227
- `options` - optional settings
224228
- `separator` - string to split chain path on, defaults to '.'
225229
- `default` - value to return if the path or value is not present, default is `undefined`
226230
- `strict` - if `true`, will throw an error on missing member, default is `false`
227231
- `functions` - if `true` allow traversing functions for properties. `false` will throw an error if a function is part of the chain.
228232

229-
A chain including negative numbers will work like negative indices on an
230-
array.
233+
A chain can be a string that will be split into key names using `separator`,
234+
or an array containing each individual key name.
235+
236+
A chain including negative numbers will work like negative indices on an array.
231237

232238
If chain is `null`, `undefined` or `false`, the object itself will be returned.
233239

@@ -238,7 +244,7 @@ var obj = {a : {b : { c : 1}}};
238244

239245
Hoek.reach(obj, chain); // returns 1
240246

241-
var chain = 'a.b.-1';
247+
var chain = ['a', 'b', -1];
242248
var obj = {a : {b : [2,3,6]}};
243249

244250
Hoek.reach(obj, chain); // returns 6

0 commit comments

Comments
 (0)
Please sign in to comment.