Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const config = new Conf({projectName: 'foo'});
config.set('unicorn', '🦄');
console.log(config.get('unicorn'));
//=> '🦄'
console.log(config.getAll({unicorn: '🦄'}));
//=> {unicorn: '🦄', foo: {bar: true}}

// Use dot-notation to access nested properties
config.set('foo.bar', true);
Expand Down Expand Up @@ -64,7 +66,7 @@ Type: `object`

[JSON Schema](https://json-schema.org) to validate your config data.

This will be the [`properties`](https://json-schema.org/understanding-json-schema/reference/object.html#properties) object of the JSON schema. That is, define `schema` as an object where each key is the name of your data's property and each value is a JSON schema used to validate that property.
This will be the [`properties`](https://json-schema.org/understanding-json-schema/reference/object.html#properties) object of the JSON schema. That is, define `schema` as an object where each key is the name of your data's property and each value is a JSON schema used to validate that property.

Example:

Expand Down Expand Up @@ -405,6 +407,10 @@ Set multiple items at once.

Get an item or `defaultValue` if the item does not exist.

#### .getAll(defaultValue?)

Get all config items or `defaultValue` if no items exist.

#### .reset(...keys)

Reset items to their default values, as defined by the `defaults` or `schema` option.
Expand Down
10 changes: 10 additions & 0 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@
return key in store ? store[key] : defaultValue;
}

/**
Get all config items.

@param defaultValue - The default value if no items exist.
*/
getAll(defaultValue?: T): T {
const store = this.store;

Check failure on line 191 in source/index.ts

View workflow job for this annotation

GitHub Actions / Node.js 18 on macos-latest

Use object destructuring.

Check failure on line 191 in source/index.ts

View workflow job for this annotation

GitHub Actions / Node.js 18 on ubuntu-latest

Use object destructuring.
return Object.keys(store).length === 0 && defaultValue !== undefined ? defaultValue : store;
}

/**
Set an item or multiple items at once.

Expand Down
Loading