Skip to content

Commit

Permalink
Add .reset() method (#84)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
husek and sindresorhus committed Nov 17, 2019
1 parent 11f89d6 commit 6d7157c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,27 @@ process.on('uncaughtException', error => {

const store = new Store({name: 'electron-store'});

const storeWithSchema = new Store({
name: 'electron-store-with-schema',
schema: {
foo: {
default: 42
}
}
});

store.set('unicorn', '🦄');
assert.strictEqual(store.get('unicorn'), '🦄');

store.delete('unicorn');
assert.strictEqual(store.get('unicorn'), undefined);

storeWithSchema.set('foo', 77);
assert.strictEqual(storeWithSchema.get('foo'), 77);

storeWithSchema.reset('foo');
assert.strictEqual(storeWithSchema.get('foo'), 42);

// To be checked in AVA
store.set('ava', '🚀');

Expand Down
1 change: 1 addition & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ store.set({
store.delete('foo');
store.get('foo');
store.get('foo', 42);
store.reset('foo');
store.has('foo');
store.clear();

Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ Set multiple items at once.

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

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

Reset items to their default values, as defined by the `defaults` or `schema` option.

#### .has(key)

Check if an item exists.
Expand Down

0 comments on commit 6d7157c

Please sign in to comment.