0xc14m1z/regler

View on GitHub
src/instanceOf/index.js

Summary

Maintainability
A
0 mins
Test Coverage
import Validator from '../validator'

import throwIf from '../helpers/throwIf'

const INVALID_COMPARE_CLASS =
  'The comparison class must be provided'

function instanceOf(compareClass) {
  throwIf(
    compareClass === undefined,
    TypeError, INVALID_COMPARE_CLASS
  )

  this.test = function test(value) {
    return this.parent.test(value) && value instanceof compareClass
  }

  return this
}

export default Validator.make(instanceOf)