# type-guard

> Guard is a type checker that aims to make type checking function arguments easier and more readable.

Latest version **0.2.3** (published 2014-12-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install type-guard
pnpm add type-guard
yarn add type-guard
bun add type-guard
```

## 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.2.3 |
| Published | 2014-12-04 |
| First published | 2014-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Robert Hurst |
| Maintainers | robertwhurst |
| Keywords | types, type-checking, util |

## Links

- npm: https://www.npmjs.com/package/type-guard
- Repository: git@github.com:RobertWHurst/Guard
- Homepage: https://github.com/RobertWHurst/Guard
- Issues: https://github.com/RobertWHurst/Guard/issues
- npm.io page: https://npm.io/package/type-guard

## Dependencies (1)

- [inherits](https://npm.io/package/inherits.md) ^2.0.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.2.3 (latest) — 2014-12-04
- 0.2.2 — 2014-10-09
- 0.2.1 — 2014-10-05
- 0.2.0 — 2014-10-05
- 0.1.1 — 2014-09-03
- 0.0.1 — 2014-08-31
- 0.0.0 — 2014-08-30

## README

[![Circle CI](https://circleci.com/gh/RobertWHurst/Guard/tree/master.png?style=badge)](https://circleci.com/gh/RobertWHurst/Guard/tree/master)

Guard
=====

Guard is a simple type checker function that aims to make it easier to check 
the types of arguments or values in a function. When a guard finds an invalid
value it throws an error. The error thrown has a modified stack trace that
originates from where guard was called to make for easier debugging.

```
npm install type-guard
```

```javascript

var guard = require('type-guard');


function hello(name) {
  guard('name', name, 'string');
  console.log('Hello ' + name);
}

hello('Robert');
// Hello Robert

hello(1);
// GuardError: name must be a string
//     at hello (/Users/user/Developer/JS/hello.js:14:3)
//     at Object.<anonymous> (/Users/user/Developer/JS/hello.js:18:1)
//     at Module._compile (module.js:456:26)
//     at Object.Module._extensions..js (module.js:474:10)
//     at Module.load (module.js:356:32)
//     at Function.Module._load (module.js:312:12)
//     at Function.Module.runMain (module.js:497:10)
```

# Docs

## guard()

```
guard(string:key, *:val, string:type) => undefined
```
The guard function accepts a key, the name of your argument, a value, the
argument itself, and a type. The supported types are `object`, `string`,
`boolean`, `number`, `array`, `regexp`, `date`, `function`, `null`, and
`undefined`.

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