@npmcli/config
Advanced tools
Comparing version 2.3.2 to 2.4.0
@@ -404,2 +404,16 @@ // TODO: set the scope config from package.json or explicit cli config | ||
// Returns true if the value is coming directly from the source defined | ||
// in default definitions, if the current value for the key config is | ||
// coming from any other different source, returns false | ||
isDefault (key) { | ||
const [defaultType, ...types] = [...confTypes] | ||
const defaultData = this.data.get(defaultType).data | ||
return hasOwnProperty(defaultData, key) | ||
&& types.every(type => { | ||
const typeData = this.data.get(type).data | ||
return !hasOwnProperty(typeData, key) | ||
}) | ||
} | ||
invalidHandler (k, val, type, source, where) { | ||
@@ -406,0 +420,0 @@ this.log.warn( |
{ | ||
"name": "@npmcli/config", | ||
"version": "2.3.2", | ||
"version": "2.4.0", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "lib" |
@@ -221,2 +221,25 @@ # `@npmcli/config` | ||
### `config.isDefault(key)` | ||
Returns `true` if the value is coming directly from the | ||
default definitions, if the current value for the key config is | ||
coming from any other source, returns `false`. | ||
This method can be used for avoiding or tweaking default values, e.g: | ||
> Given a global default definition of foo='foo' it's possible to read that | ||
> value such as: | ||
> | ||
> ```js | ||
> const save = config.get('foo') | ||
> ``` | ||
> | ||
> Now in a different place of your app it's possible to avoid using the `foo` | ||
> default value, by checking to see if the current config value is currently | ||
> one that was defined by the default definitions: | ||
> | ||
> ```js | ||
> const save = config.isDefault('foo') ? 'bar' : config.get('foo') | ||
> ``` | ||
### `config.save(where)` | ||
@@ -223,0 +246,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45648
972
248