This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

param-check

2.1.3 • Public • Published

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
}

Dependencies (1)

Dev Dependencies (12)

Package Sidebar

Install

npm i param-check

Weekly Downloads

1

Version

2.1.3

License

MIT

Unpacked Size

1.07 MB

Total Files

114

Last publish

Collaborators

  • y3g
  • yusangeng