validator/types/boolean.js

20 lines
479 B
JavaScript
Raw Normal View History

2020-06-03 15:49:04 +00:00
const Base = require('./base.js')
const util = require('util')
class TypeBoolean extends Base {
constructor () {
super()
this._type = 'boolean'
}
validate (value) {
if (value === undefined && this._required) return `required`
if (value === undefined) return null
/* eslint-disable-next-line */
if (typeof value !== this._type) return `${util.inspect(value, false, null)} type not ${this._type}`
return null
}
}
module.exports = TypeBoolean