# typr

> Mutually exclusive type testing

Latest version **0.2.1** (published 2014-07-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install typr
pnpm add typr
yarn add typr
bun add typr
```

## 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.1 |
| Published | 2014-07-10 |
| First published | 2012-05-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.8 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Eirik Albrigtsen |
| Maintainers | clux |

## Links

- npm: https://www.npmjs.com/package/typr
- Repository: https://github.com/clux/typr
- Issues: http://github.com/clux/typr/issues
- npm.io page: https://npm.io/package/typr

## Recent versions

- 0.2.1 (latest) — 2014-07-10
- 0.2.0 — 2012-10-19
- 0.1.3 — 2012-08-08
- 0.1.2 — 2012-06-15
- 0.1.1 — 2012-06-05
- 0.1.0 — 2012-05-28

## README

# typr
[![npm status](http://img.shields.io/npm/v/typr.svg)](https://www.npmjs.org/package/typr)
[![build status](https://secure.travis-ci.org/clux/typr.svg)](http://travis-ci.org/clux/typr)
[![dependency status](https://david-dm.org/clux/typr.svg)](https://david-dm.org/clux/typr)
[![coverage status](http://img.shields.io/coveralls/clux/typr.svg)](https://coveralls.io/r/clux/typr)
[![locked](http://img.shields.io/badge/stability-locked-14C6C6.svg)](http://nodejs.org/api/documentation.html#documentation_stability_index)

## Mutually Exclusive JS Type Testring
The aim of this module is to completely partition the set of JS objects into a set of types T:

```
T = [Function, Object, Date, Number, String, Boolean, RegExp, Undefined, Arguments, Null, Array]
```

*Prop. 1* For every JS object x, x has exactly one type in T where [typr] returns true for its typecheck.

*Prop. 2* Whether or not an Object has keys and can be looped over is determined by `t.hasKeys` and is completely independent of the type found in prop 1.

*Prop. 3* Number types can be partitioned into 3 sub-types:

- isNaN
- isInfinite
- isNumeric i.e. !isNaN && !isInfinite


These properties are tested extensively.

## Usage
Basic usage:

```javascript
var typr = require('typr');
typr.isFunction(el); // true iff el is a function
```

Read the very short [API](https://github.com/clux/typr/master/api.md).

### Object Keys
The reason for prop 2 is that Objects can masquerade othes instances like
Functions, Strings, RegExps, Dates. Object.keys() (and for-in) will actually work on some
of these. This does not mean they will have interesting keys, but they sometimes
do!

A common trick in node modules to export a function, but additionally attach
properties to it. Such an object will only be a Function by our partitioning
(as that was its original construction), but it is Object-like.

If you would rather test for enumerability of properties, use the extra test for Object-likeness: `hasKeys`.

Note again that this may not be super intuitive:

```javascript
var dualThing = new String("wee");
dualThing.prop = "hi";
Object.keys(dualThing); // [ '0', '1', '2', 'prop' ]

t.isObject(dualThing); // false
t.isString(dualThing); // true
t.hasKeys(dualThing); // true
```

## Installation

```bash
$ npm install typr
```

## Running tests
Install development dependencies

```bash
$ npm install
```

Run the tests

```bash
$ npm test
```

## License
MIT-Licensed. See LICENSE file for details.

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