tn-validate
TypeScript icon, indicating that this package has built-in type declarations

4.1.4 • Public • Published

Main module - validate()

import { validate } from 'tn-validate'

const value: any
const criteria: Criterion[]

validate(value, ...criteria)

Singular Modules

Better TypeScript Support with singular modules

  • isString()
  • isSymbol()
  • isNumber()
  • isBoolean()
  • isFunction()
  • isUndefined()
  • isNull()
  • isArray()
  • isObject()
  • isRegExp()
  • isDate()
  • isValidDate()
  • isJson()
  • isNumString()
  • isArrObject()
  • isNullUndefined()
  • isStrArr()
  • isNumArr()
  • isBoolArr()
  • isNumStrArr()

Type Criterion

type CustomValidator = (value: number) => boolean

type Criterion =
  | 'string'
  | StringConstructor
  | 'number'
  | NumberConstructor
  | 'boolean'
  | BooleanConstructor
  | 'function'
  | FunctionConstructor
  | 'array'
  | ArrayConstructor
  | 'object'
  | ObjectConstructor
  | 'regexp'
  | RegExpConstructor
  | 'date'
  | DateConstructor
  | 'valid-date'
  | 'json'
  | 'null'
  | 'undefined'
  | RegExp
  | CustomValidator

Examples

validate('any')
validate('string', String)
validate('school', String, Boolean)
validate(50, Number, val => val > 0 && val < 100)
validate('{}', 'json')
validate(/^\w+$/, RegExp)
validate('foo-bar', /^foo-.+/)

Readme

Keywords

none

Package Sidebar

Install

npm i tn-validate

Weekly Downloads

39

Version

4.1.4

License

MIT

Unpacked Size

23.4 kB

Total Files

46

Last publish

Collaborators

  • turnova