@npmcli/config 2.3.2 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/lib/index.js +14 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -218,6 +218,29 @@ Note that it's usually enough (and more efficient) to just check
|
|
|
218
218
|
`config.valid`, since each data object is marked for re-evaluation on every
|
|
219
219
|
`config.set()` operation.
|
|
220
220
|
|
|
221
|
+
### `config.isDefault(key)`
|
|
222
|
+
|
|
223
|
+
Returns `true` if the value is coming directly from the
|
|
224
|
+
default definitions, if the current value for the key config is
|
|
225
|
+
coming from any other source, returns `false`.
|
|
226
|
+
|
|
227
|
+
This method can be used for avoiding or tweaking default values, e.g:
|
|
228
|
+
|
|
229
|
+
> Given a global default definition of foo='foo' it's possible to read that
|
|
230
|
+
> value such as:
|
|
231
|
+
>
|
|
232
|
+
> ```js
|
|
233
|
+
> const save = config.get('foo')
|
|
234
|
+
> ```
|
|
235
|
+
>
|
|
236
|
+
> Now in a different place of your app it's possible to avoid using the `foo`
|
|
237
|
+
> default value, by checking to see if the current config value is currently
|
|
238
|
+
> one that was defined by the default definitions:
|
|
239
|
+
>
|
|
240
|
+
> ```js
|
|
241
|
+
> const save = config.isDefault('foo') ? 'bar' : config.get('foo')
|
|
242
|
+
> ```
|
|
243
|
+
|
|
221
244
|
### `config.save(where)`
|
|
222
245
|
|
|
223
246
|
Save the config file specified by the `where` param. Must be one of
|
package/lib/index.js
CHANGED
|
@@ -401,6 +401,20 @@ class Config {
|
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
+
// Returns true if the value is coming directly from the source defined
|
|
405
|
+
// in default definitions, if the current value for the key config is
|
|
406
|
+
// coming from any other different source, returns false
|
|
407
|
+
isDefault (key) {
|
|
408
|
+
const [defaultType, ...types] = [...confTypes]
|
|
409
|
+
const defaultData = this.data.get(defaultType).data
|
|
410
|
+
|
|
411
|
+
return hasOwnProperty(defaultData, key)
|
|
412
|
+
&& types.every(type => {
|
|
413
|
+
const typeData = this.data.get(type).data
|
|
414
|
+
return !hasOwnProperty(typeData, key)
|
|
415
|
+
})
|
|
416
|
+
}
|
|
417
|
+
|
|
404
418
|
invalidHandler (k, val, type, source, where) {
|
|
405
419
|
this.log.warn(
|
|
406
420
|
'invalid config',
|