validator/types/object.js

19 lines
475 B
JavaScript
Raw Normal View History

2020-06-03 15:49:04 +00:00
const Base = require('./base.js')
const util = require('util')
class TypeObject extends Base {
constructor () {
super()
this._type = 'object'
}
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 = TypeObject