Skip to content

Commit

Permalink
Upgrade conf dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 2, 2019
1 parent 66054bc commit eee6263
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
os:
- osx
language: node_js
node_js:
- '10'
- '8'
- '6'
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"save"
],
"dependencies": {
"conf": "^3.0.0"
"conf": "^4.0.0"
},
"devDependencies": {
"ava": "^1.3.1",
"electron": "^4.1.1",
"ava": "^1.4.1",
"electron": "^4.1.3",
"execa": "^1.0.0",
"xo": "^0.24.0"
},
Expand Down
43 changes: 42 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,48 @@ Type: `Object`

Type: `Object`

Default data.
Default values for the store items.

**Note:** The values in `defaults` will overwrite the `default` key in the `schema` option.

#### schema

type: `Object`

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

Under the hood, the JSON Schema validator [ajv](https://github.com/epoberezkin/ajv) is used to validate your config. We use [JSON Schema draft-07](http://json-schema.org/latest/json-schema-validation.html) and support all [validation keywords](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md) and [formats](https://github.com/epoberezkin/ajv#formats).

You should define your 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. See more [here](https://json-schema.org/understanding-json-schema/reference/object.html#properties).

Example:

```js
const Store = require('electron-store');

const schema = {
foo: {
type: 'number',
maximum: 100,
minimum: 1,
default: 50
},
bar: {
type: 'string',
format: 'url'
}
};

const store = new Store({schema});

console.log(store.get('foo'));
//=> 50

store.set('foo', '1');
// [Error: Config schema violation: `foo` should be number]
```

**Note:** The `default` value will be overwritten by the `defaults` option if set.

#### name

Expand Down

0 comments on commit eee6263

Please sign in to comment.