# is-a

> type checking "micro library"

Latest version **0.2.5** (published 2013-12-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-a
pnpm add is-a
yarn add is-a
bun add is-a
```

## 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.5 |
| Published | 2013-12-03 |
| First published | 2013-11-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | david tudury |
| Maintainers | dtudury |
| Keywords | typeof, type, checking, testing |

## Links

- npm: https://www.npmjs.com/package/is-a
- Repository: https://github.com/dtudury/is-a
- Issues: https://github.com/dtudury/is-a/issues
- npm.io page: https://npm.io/package/is-a

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 0.2.5 (latest) — 2013-12-03
- 0.2.4 — 2013-12-03
- 0.2.3 — 2013-12-02
- 0.2.2 — 2013-12-02
- 0.2.1 — 2013-12-01
- 0.2.0 — 2013-12-01
- 0.1.4 — 2013-11-30
- 0.1.3 — 2013-11-30
- 0.1.2 — 2013-11-30
- 0.1.1 — 2013-11-29
- 0.1.0 — 2013-11-29

## README

# is-a

  legible type checking "micro library"

  [![Build Status](https://travis-ci.org/dtudury/is-a.png)](https://travis-ci.org/dtudury/is-a)

## Installation

    $ npm install is-a

## Usage

```js
var is = require('is-a');

var StringOrRegExp = [is.STRING, is.REGEXP];

var thing1 = /mischief/;

console.log(is(thing1).a.String); //false
console.log(is(thing1).not.a.Number); //true
console.log(is(thing1).an.Array); //false
console.log(is(thing1).a.RegExp); //true
console.log(is(thing1).a(StringOrRegExp)); //true
console.log(is(thing1).a.Primitive); //false
console.log(is(thing1).a.CoreObject); //true
console.log(is(thing1).not.a.JsonBasicType); //true
console.log(is(thing1).a.BuiltinType); //true


var thing2 = "mayhem";

console.log(is(thing2).a.String); //true
console.log(is(thing2).not.a.Number); //true
console.log(is(thing2).an.Array); //false
console.log(is(thing2).a.RegExp); //false
console.log(is(thing2).a(StringOrRegExp)); //true
console.log(is(thing2).a.Primitive); //true
console.log(is(thing2).a.CoreObject); //true
console.log(is(thing2).not.a.JsonBasicType); //false
console.log(is(thing2).a.BuiltinType); //true


var myType = is.ARRAY;

console.log(myType.is.a.String); //false
console.log(myType.is.not.a.Number); //true
console.log(myType.is.an.Array); //true
console.log(myType.is.a.RegExp); //false
console.log(myType.is.a(StringOrRegExp)); //false
console.log(myType.is.a.Primitive); //false
console.log(myType.is.a.CoreObject); //true
console.log(myType.is.not.a.JsonBasicType); //false
console.log(myType.is.a.BuiltinType); //true
```

## Tests

this is the complete list of tests. `.a`, `.an`, and `.is` are optional, `is(x).not...` is the same as `!is(x)...`

### Testing: is X a Type
* `is(x).Arguments`
* `is(x).an.Array`
* `is(x).a.Boolean`
* `is(x).a.Date`
* `is(x).a.Function`
* `is(x).a.Math`
* `is(x).Null`
* `is(x).a.Number`
* `is(x).an.Object`
* `is(x).a.RegExp`
* `is(x).a.String`
* `is(x).Undefined`

### Testing: is X not a Type
* `is(x).not.Arguments`
* `is(x).not.an.Array`
* `is(x).not.a.Boolean`
* `is(x).not.a.Date`
* `is(x).not.a.Function`
* `is(x).not.a.Math`
* `is(x).not.Null`
* `is(x).not.a.Number`
* `is(x).not.an.Object`
* `is(x).not.a.RegExp`
* `is(x).not.a.String`
* `is(x).not.Undefined`

### Testing: is X a GeneralType
general types are

* `BuiltinType`: one of (Arguments, Array, Boolean, Date, Function, Math, Null, Number, Object, RegExp, String, Undefined)
* `JsonBasicType`: one of (Array, Boolean, Null, Number, Object, String, Undefined)
* `CoreObject`: one of (Array, Boolean, Date, Function, Math, Number, RegExp, String)
* `Primitive`: one of (Boolean, Null, Number, String, Undefined)

general types can be tested for just like simple types

* `is(x).a.BuiltinType`
* `is(x).a.JsonBasicType`
* `is(x).a.CoreObject`
* `is(x).a.Primitive`
* `is(x).a([is.STRING, is.ARRAY])`

`.not` still works

* `is(x).not.a.BuiltinType`
* `is(x).not.a.JsonBasicType`
* `is(x).not.a.CoreObject`
* `is(x).not.a.Primitive`
* `is(x).not.a([is.STRING, is.ARRAY])`

builtin types can be tested too

* `is.ARRAY.a.JsonBasicType`
* `is.REGEXP.a([is.STRING, is.ARRAY])`

## everything else
```js
var is = require('is-a');

var thing1 = /mischief/;

console.log(is(thing1).toString()); // "RegExp"
console.log(is(thing1).toType()); // "[object RegExp]"
```

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