# param-types

> Parameter types validator

Latest version **0.1.0** (published 2017-01-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install param-types
pnpm add param-types
yarn add param-types
bun add param-types
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2017-01-14 |
| First published | 2017-01-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | LaySent |
| Maintainers | laysent |
| Keywords | parameter, params, param, validation, schema, type, check |

## Links

- npm: https://www.npmjs.com/package/param-types
- npm.io page: https://npm.io/package/param-types

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 0.1.0 (latest) — 2017-01-14

## README

![build status](https://travis-ci.org/laysent/paramTypes.svg?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/laysent/paramTypes/badge.svg?branch=master)](https://coveralls.io/github/laysent/paramTypes?branch=master)

## Motivation

Since JavaScript is a dynamic programming language with weak type system built-in, it requires much
more cautious when writing and using APIs. Library such as [React](https://github.com/facebook/react)
provides a way to force property validation using `propTypes`.

With the similar ideas, **paramTypes** will do the same trick to enhance function calls in
development mode. While in production mode, the validation will be removed so that the performance
won't be affected.

## How to use

**paramTypes.validate** is the core API to call. It's a high order function that requires two steps
to setup. First configure, then validate.

Here is an example:

```JavaScript
import * as paramTypes from 'paramTypes';

// define
const validator = paramTypes.validate(
  'function name', // this will be used in error message to help locate the issue
  paramTypes.number.isRequired,
  paramTypes.restOf(paramTypes.string.isRequired),
);

function example(num, ...names) {
  validator(num, ...names);
  // do something
}

example(1, 'Anna', 'Bob', 'Claire');

```

**paramTypes** provides similar validators as `propTypes` in React.

Also, it provides two mode of validation.

+ Use **paramTypes.validate** to validate parameters and output warning in console only

  The actual workflow won't be affected in this way.

+ Use **paramTypes.validateWithError** to validate parameters and throw the first error occurs.

  The actual workflow will be interrupted in this way.

## Production Mode

Do not forget to remove validation in production mode.

To do this, all you need to do is set `process.env.NODE_ENV` to `"production"`.

---
_Source: https://npm.io/package/param-types · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
