2.1.3 • Published 5 years ago

param-check v2.1.3

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

param-check

Build Status Standard - JavaScript Style Guide

Npm Info

运行时数据校验工具 | a javascript run-time data verification tool.

Install

npm install param-check --save

Usage

Basic usage

import check from 'param-check'

function fn (arg1, arg2) {
	check(arg1).isString()
	check(arg2, 'arg2').greaterThan(1).lessThan(2)
}

Import of specific check

import check from 'param-check/naked'
import isStringCheck from 'param-check/lib/checks/isString'

check.registerCheck(isStringCheck)

function fn (arg) {
	check(arg, 'arg').isString()
}

Custom check

import check from 'param-check'
import isNumber from 'lodash/isNumber'

function isEven (target, name) {
  return isNumber(target) && !(target % 2)
}

check.registerCheck('isEven', isEven)

function fn (arg) {
	check(arg, 'arg').isEven()
}

Custom linkable check

import check from 'param-check'
import isNumber from 'lodash/isNumber'

function isEven (target, name) {
  return isNumber(target) && !(target % 2)
}

function isEventNext (target) {
  return return target + 1
}

check.registerCheck('isEven', isEven, isEventNext)

function fn (arg) {
	check(arg, 'arg').isEven().isEven() // error occurred
}
2.1.3

5 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.1.9

6 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago