Skip to content

Commit

Permalink
fix: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed May 20, 2019
1 parent eeafb5b commit ad53e4b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var schema = {
var validator = osom(schema)

// validate it!
validator({title: ' 23 '}) // => {title: '23'}
validator({ title: ' 23 ' }) // => {title: '23'}
```

## Usage
Expand Down Expand Up @@ -115,7 +115,7 @@ var schema = {
}

var validator = osom(schema)
validator({age: '23'}) // => {age: 23}
validator({ age: '23' }) // => {age: 23}
```

### casting
Expand All @@ -135,7 +135,7 @@ var schema = {
}

var validator = osom(schema)
validator({age: '23'}) // => TypeError("Expected a {string} for 'age'.")
validator({ age: '23' }) // => TypeError("Expected a {string} for 'age'.")
```

### required
Expand Down Expand Up @@ -201,7 +201,7 @@ var schema = {
}

var validator = osom(schema)
validator({age: ' 23 '}) // => { age: '23' }
validator({ age: ' 23 ' }) // => { age: '23' }
```

### validate
Expand All @@ -223,7 +223,7 @@ var schema = {
}

var validator = osom(schema)
validator({age: 25}) // => TypeError("Fail '25' validation for 'age'.")
validator({ age: 25 }) // => TypeError("Fail '25' validation for 'age'.")
```

Providing a object brings you the possibility set up a custom error message:
Expand All @@ -242,7 +242,7 @@ var schema = {
}

var validator = osom(schema)
validator({age: 25}) // => TypeError("expected a millenial value instead of 25!")
validator({ age: 25 }) // => TypeError("expected a millenial value instead of 25!")
```

## Defining Global Rules
Expand All @@ -267,7 +267,7 @@ var globalFields = {
}

var validator = osom(schema, globalFields)
validator({age: ' 23 '}) // => {age: '23'}
validator({ age: ' 23 ' }) // => {age: '23'}
```

No problem if later you need to avoid it for a specific case.
Expand All @@ -289,7 +289,7 @@ var globalFields = {
}

var validator = osom(schema, globalFields)
validator({age: ' 23 '}) // => {age: ' 23 '}
validator({ age: ' 23 ' }) // => {age: ' 23 '}
```

## Tips
Expand Down
42 changes: 21 additions & 21 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ const osom = require('..')
describe('schema defintion', function () {
describe('simple rule', function () {
it('empty value', function () {
[{age: Number}, {age: { type: Number }}].forEach(function (rule) {
[{ age: Number }, { age: { type: Number } }].forEach(function (rule) {
osom(rule)().should.be.eql({})
})
})

describe('providing value', function () {
it('Number', function () {
[
{age: Number},
{age: { type: Number }}
{ age: Number },
{ age: { type: Number } }
].forEach(function (rule) {
osom(rule)({age: '23'}).should.be.eql({age: 23})
osom(rule)({ age: '23' }).should.be.eql({ age: 23 })
})
})

it('Array', function () {
[
{age: Array},
{age: { type: Array }}
{ age: Array },
{ age: { type: Array } }
].forEach(function (rule) {
osom(rule)({age: ['23']}).should.be.eql({age: ['23']})
osom(rule)({ age: ['23'] }).should.be.eql({ age: ['23'] })
})
})
})
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('schema defintion', function () {
}

var validator = osom(schema)
validator().should.be.eql({age: 23})
validator().should.be.eql({ age: 23 })
})

it('based in a fn', function () {
Expand All @@ -69,7 +69,7 @@ describe('schema defintion', function () {
}

var validator = osom(schema)
validator().should.be.eql({age: 23})
validator().should.be.eql({ age: 23 })
})
})

Expand All @@ -86,7 +86,7 @@ describe('schema defintion', function () {
}

var validator = osom(schema)
validator({age: ' 23 '}).should.be.eql({age: '23'})
validator({ age: ' 23 ' }).should.be.eql({ age: '23' })
})

describe('support required values', function () {
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('schema defintion', function () {
it('enable (by default)', function () {
var schema = { age: Array }
var validator = osom(schema)
validator({age: '23'}).should.be.eql({age: ['23']})
validator({ age: '23' }).should.be.eql({ age: ['23'] })
})
})

Expand All @@ -134,9 +134,9 @@ describe('schema defintion', function () {
}

var errMessage = "Expected {string} for 'age'."
var validator = osom(schema, {casting: false})
var validator = osom(schema, { casting: false })

;[{age: 23}].forEach(function (obj) {
;[{ age: 23 }].forEach(function (obj) {
;(function () { validator(obj) }).should.throw(errMessage)
})
})
Expand All @@ -149,8 +149,8 @@ describe('schema defintion', function () {
}
}

var validator = osom(schema, {casting: false})
;[null, {}, {age: null}].forEach(function (data) {
var validator = osom(schema, { casting: false })
;[null, {}, { age: null }].forEach(function (data) {
validator(data).should.be.eql({})
})
})
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('schema defintion', function () {

var validator = osom(schema)
var errMessage = "Fail '25' validation for 'age'."
;(function () { validator({age: 25}) }).should.throw(errMessage)
;(function () { validator({ age: 25 }) }).should.throw(errMessage)
})

it('based in a object key', function () {
Expand All @@ -211,7 +211,7 @@ describe('schema defintion', function () {

var validator = osom(schema)
var errMessage = "Fail '25' validation for 'age'."
;(function () { validator({age: 25}) }).should.throw(errMessage)
;(function () { validator({ age: 25 }) }).should.throw(errMessage)
})

it('just run validator when the field is present', function () {
Expand All @@ -226,7 +226,7 @@ describe('schema defintion', function () {
}

var validator = osom(schema)
validator({name: 'foo bar'}).should.be.eql({name: 'foo bar'})
validator({ name: 'foo bar' }).should.be.eql({ name: 'foo bar' })
})

it('custom error message', function () {
Expand All @@ -244,7 +244,7 @@ describe('schema defintion', function () {

var validator = osom(schema)
var errMessage = 'expected a millenial value instead of 25!'
;(function () { validator({age: 25}) }).should.throw(errMessage)
;(function () { validator({ age: 25 }) }).should.throw(errMessage)
})
})
})
Expand Down Expand Up @@ -285,7 +285,7 @@ describe('error', function () {
var validator = osom(schema)

try {
validator({age: 25})
validator({ age: 25 })
} catch (err) {
err.key.should.be.equal('age')
err.value.should.be.equal(25)
Expand All @@ -311,6 +311,6 @@ describe('behavior', function () {
}

var validator = osom(schema, globalFields)
validator({age: ' 23 '}).should.be.eql({age: '23'})
validator({ age: ' 23 ' }).should.be.eql({ age: '23' })
})
})

0 comments on commit ad53e4b

Please sign in to comment.