Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

feat: add isDefault method #27

Merged
merged 1 commit into from
Jan 10, 2022
Merged

Conversation

ruyadorno
Copy link
Contributor

Add a new method isDefault(key) that enables a way to know if the
value to be returned by a config.get(key) call is coming from the
default definitions or any other different source. In case it's coming
from the default values this method returns true, it returns false
otherwise.

This addition is going to allow for effectively managing different
default values in the npm cli on a command-basis, e.g:

The save config default value in the npm cli is true, so that in
npm install and other commands that value is always going to default
to true if no user config is provided. Now let's say we want to use a
different value in npm update, for example save=false. This change
enables us to have a conditional check to see if the save config value
is coming from the default source, thus providing a way to use a
different value instead of the default:

const save = config.isDefault('save') ? false : config.get('save')

Relates to: npm/cli#4223
Relates to: npm/statusboard#324

References

Add a new method `isDefault(key)` that enables a way to know if the
value to be returned by a `config.get(key)` call is coming from the
default definitions or any other different source. In case it's coming
from the default values this method returns `true`, it returns `false`
otherwise.

This addition is going to allow for effectively managing different
default values in the npm cli on a command-basis, e.g:

The `save` config default value in the npm cli is `true`, so that in
`npm install` and other commands that value is always going to default
to true if no user config is provided. Now let's say we want to use a
different value in `npm update`, for example `save=false`. This change
enables us to have a conditional check to see if the `save` config value
is coming from the default source, thus providing a way to use a
different value instead of the default:

    const save = config.isDefault('save') ? false : config.get('save')

Relates to: npm/cli#4223
Relates to: npm/statusboard#324
@ruyadorno ruyadorno requested a review from a team as a code owner January 10, 2022 18:10
@ruyadorno ruyadorno merged commit 30ca48d into npm:main Jan 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants