Socket
Book a DemoInstallSign in
Socket

param-check

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

param-check

A js library for runtime parameter checking.

2.1.3
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
2
Weekly downloads
 
Created
Source

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
}

FAQs

Package last updated on 27 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.