# oftype

> A JavaScript module for checking variable runtime type

Latest version **0.1.2** (published 2014-08-09) · MIT license · 0 weekly downloads

## Install

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

## 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.2 |
| Published | 2014-08-09 |
| First published | 2014-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Shuping LIU |
| Maintainers | liushuping |
| Keywords | JavaScript, Type, Check, Node |

## Links

- npm: https://www.npmjs.com/package/oftype
- Repository: https://github.com/liushuping/oftype
- Issues: https://github.com/liushuping/oftype/issues
- npm.io page: https://npm.io/package/oftype

## 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.1.2 (latest) — 2014-08-09
- 0.1.1 — 2014-08-07
- 0.1.0 — 2014-08-07
- 0.0.1 — 2014-08-06

## README

oftype
======

A JavaScript module for checking variable runtime type

[![build status](https://travis-ci.org/liushuping/oftype.svg)](https://travis-ci.org/liushuping/oftype.svg)

## Usage
```javascript
var oftype = require('oftype');
var x = 123;
var y = true;
var z = /abc/;
var u = undefined;
var n = null;

function Obj() {
    this.name = 'ABC';
}

var o = new Obj();

//check if variable x is of Number type.
oftype(123, Number); //true

//check if variable y is of Boolean type.
oftype(y, Boolean); //true

//check if variable z is of RegExp type.
oftype(z, RegExp); //true

//check if variable u is of undefined type.
//undefined is a type which has an only value undefined.
oftype(u, undefined); //true

//check if variable n is of null type.
//stricly, null is no actually a type, but here we treat
// it as a type just like how we treat undefined.
oftype(n, null); //true;

//check if variable o is of Obj type.
oftype(o, Obj); //true;

//check if variable o is of Object type.
oftype(o, Object); //true;

```

## API
The signature of `oftype` is
```javascript
oftype(value, type, options);
```
`value`: could be any variable or value;

* `type`: could be any type identifier, e.g.: Number, Boolean, String, Date, RegExp, Array, Object and any other customized complex type.

* `options` is optional and has below hash values:

 * `nullAsObject`: treat `null` value as `Object` type, so with this option testing `null` against `Object` type returns `true`. Default value of this option is `false`.

 * `primitiveObject`: treat primitive object as primitive type. for example, testing `new Number(1)` against Number will return `false` when this option is set to `false`; but will return `true` when this option is set to `true`.

Alternatively, to avoid setting the options in every function call, the options could also be set globally:
```javascript
oftype.nullAsObject = true;
oftype.primitiveObject = true;
```
## Test
Make sure `mocha` is installed globally

```
npm test
```

## License
MIT

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