Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alinex committed Sep 26, 2017
1 parent de7a51f commit 7204e0a
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions doc/howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ import(`${__dirname}/../data/address.schema`)
.then(schema => schema.validate(data))

// or use the validator internal loader
import validator from 'alinex-validator'
validator.schema(`${__dirname}/../data/address.schema`)
import Validator from 'alinex-validator'
new Validator().schema(`${__dirname}/../data/address.schema`)
.then(schema => schema.validate(data))
```

Expand All @@ -108,17 +108,17 @@ console.log(msg)
The validator may also load configuration files from filesystem:

```js
import validator from 'alinex-validator'
import Validator from 'alinex-validator'

const data = validator.load('config/**/*.yml') // alternatively may load an array
const data = new Validator().load('config/**/*.yml') // alternatively may load an array
```

You can also define there to search for relative paths:

```js
import validator from 'alinex-validator'
import Validator from 'alinex-validator'

validator.searchApp('myApp') // search under /etc/myApp an home-dir/.myApp
validator = new Validator().searchApp('myApp') // search under /etc/myApp an home-dir/.myApp
const data = validator.load('config/**/*.yml')
```

Expand Down Expand Up @@ -152,21 +152,14 @@ before validating.

## Check

The check of config files using the CLI:


```bash
$ validator comfig lib/schema.config.js
```

That's the same as loading without using the value through API:

```js
import validator from 'alinex-validator'
import Validator from 'alinex-validator'

import schema from './config.schema.js'

validator.check('config', schema)
new Validator().check('config', schema)
.then((data) => {
console.log(data)
})
Expand All @@ -175,6 +168,7 @@ validator.check('config', schema)
})

// or alternative with loading specific type
const validator = new Validator()
validator.check(validator.load('config', 'yaml'), schema)
.then((data) => {
console.log(data)
Expand All @@ -198,13 +192,13 @@ $ validator comfig lib/schema.config.js local/config.js
To do the same using API use:

```js
import validator from 'alinex-validator'
import Validator from 'alinex-validator'

import schema from './config.schema.js'
// alternative:
// const schema = path.resolve(__dirname, 'config.schema.js')

validator.transform('config', schema, 'local/config.json')
new Validator().transform('config', schema, 'local/config.json')
.catch((err) => {
console.error(err.text())
})
Expand Down

0 comments on commit 7204e0a

Please sign in to comment.