# check-arg-types

> Pass in `arguments` and an array of the expected types (as string descriptions) and throw if they don't match.

Latest version **2.0.1** (published 2023-09-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install check-arg-types
pnpm add check-arg-types
yarn add check-arg-types
bun add check-arg-types
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2023-09-20 |
| First published | 2015-08-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 18.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Adrian Unger |
| Maintainers | staydecent |
| Keywords | check, args, types, arguments, type-checking, type |

## Links

- npm: https://www.npmjs.com/package/check-arg-types
- Repository: https://github.com/staydecent/check-arg-types
- Homepage: https://github.com/staydecent/check-arg-types#readme
- Issues: https://github.com/staydecent/check-arg-types/issues
- npm.io page: https://npm.io/package/check-arg-types

## Recent versions

- 2.0.1 (latest) — 2023-09-20
- 2.0.0 — 2021-03-24
- 1.1.2 — 2018-07-11
- 1.1.1 — 2018-07-11
- 1.1.0 — 2016-04-21
- 1.0.3 — 2015-08-11
- 1.0.2 — 2015-08-09
- 1.0.1 — 2015-08-09
- 1.0.0 — 2015-08-09

## README

# check-arg-types

[![Build Status](https://travis-ci.org/staydecent/check-arg-types.svg?branch=master)](https://travis-ci.org/staydecent/check-arg-types)

Pass in `arguments` and an array of the expected types (as string descriptions) and throw if they don't match. Simple to adopt and only ~320 bytes.

```javascript
function test(a, b, c) {
  check(arguments, ['string', 'number', 'boolean']);
  return a + b + c;
}

test('hey', 1, 'true'); // Uncaught TypeError: Expected 'boolean' given 'string' for argument at index 2
```

### Allow multiple types

```javascript
// `a` can be a string or number
function example(a, b) {
  check(arguments, [['string', 'number'], 'number']);
  return a + b;
}
```

### Can skip checking for some arguments

```javascript
// `b` can be any type
function example(a, b, c) {
  check(arguments, ['string', '-any', 'numbers');
  return a + b + c;
}
```

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