# wots

> A very simple "typeof" detection

Latest version **0.3.2** (published 2021-06-06) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2021-06-06 |
| First published | 2017-07-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >10.x |
| Dependencies | 0 |
| Unpacked size | 15.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Grzegorz |
| Maintainers | tvardy |
| Keywords | isArray, isDate, isNaN, isInfinity, isNull, isUndefined, isObject, isRegExp, isString, kind, type, typeof |

## Links

- npm: https://www.npmjs.com/package/wots
- Repository: https://github.com/tvardy/wots
- Homepage: https://github.com/tvardy/wots#readme
- Issues: https://github.com/tvardy/wots/issues
- npm.io page: https://npm.io/package/wots

## 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.3.2 (latest) — 2021-06-06
- 0.3.1 — 2021-06-06
- 0.3.0 — 2021-02-28
- 0.2.2 — 2020-04-29
- 0.2.1 — 2017-08-22
- 0.2.0 — 2017-07-05
- 0.1.4 — 2017-07-04
- 0.1.3 — 2017-07-03
- 0.0.1 — 2017-07-03

## README

# why?

The library was written as a simple coding exercise, but then appeared useful to share :wink:

# how?

```bash
npm install --save wots
```

and then

```javascript
// use as ES6 module
import wots from 'wots';

// use in NodeJs
var wots = require('wots');

// use as global variable via UnPKG
<script src="https://unpkg.com/wots"></script>

// ... then ...

if (wots(myNotAlwaysNumericVariable) === 'NaN') {
  // do some stuff
  // e.g. console.log('I cannot count on it')
} else if (wots(myNotAlwaysNumericVariable) === 'Infinity') {
  // do some other stuff
  // e.g. console.log('Please do not force me to use this value in a loop!')
}
```


# what?

`wots()` function returns reasonable type names for tested values:

| description         | input                               | result        |
| :------------------ | :---------------------------------- |:------------- |
| null                | `null`                              | `'null'`      |
| undefined           | `undefined`                         | `'undefined'` |
| strings             | `'foo'`                             | `'string'`    |
|                     | `''`                                | `'string'`    |
|                     | `['Hello', 'world!'].join(' ')`     | `'string'`    |
|                     | `new String()`                      | `'string'`    |
| numbers             | `5`                                 | `'number'`    |
|                     | `parseInt(42)`                      | `'number'`    |
|                     | `new Number('3')`                   | `'number'`    |
|                     | `NaN`                               | `'NaN'`       |
|                     | `Infinity`                          | `'Infinity'`  |
|                     | `1 / -0`                            | `'Infinity'`  |
| boolean values      | `false`                             | `'boolean'`   |
|                     | `!!nonEmptyVariable`                | `'boolean'`   |
|                     |`new Boolean('0')`                   | `'boolean'`   |
| regular expressions | `/^test$/g`                         | `'regexp'`    |
|                     | `new RegExp('needle', 'i')`         | `'regexp'`    |
| arrays              | `['foo', 'bar', 'baz']`             | `'array'`     |
|                     | `new Array(10)`                     | `'array'`     |
| objects             | `{ foo: 'bar'}`                     | `'object'`    |
|                     | `{}`                                | `'object'`    |
|                     | `new Object()`                      | `'object'`    |
|                     | `Object.create(null)`               | `'object`     |
| functions           | `function () {}`                    | `'function'`  |
|                     | `new Function('return null')`       | `'function'`  |
| date objects        | `new Date()`                        | `'date'`      |
| errors              | `new Error('error!')`               | `'error'`     |
|                     | `new TypeError('type error!')`      | `'error'`     |
| arguments objects   | `(function(){return arguments;})()` | `'arguments'` |
| class constructors  | `new MyClass()`                     | `'myclass'`   |
|                     | `new Buffer()`                      | `'buffer'`    |
|                     | `new XMLHttpRequest()`              | `'xmlhttprequest'` |
| promises            | `new Promise(function() {})`        | `'promise'`   |
|                     | `Promise.resolve('data')`           | `'promise'`   |
|                     | `Promise.reject(new Error('Oop!'))` | `'promise'`   |

**Note:** for more examples see [test file](./index.test.js)

Since version 0.2.0 the library also exposes static methods listed below:

```javascript
wots.isNull()
wots.isUndefined()
wots.isString()
wots.isNumber()
wots.isNaN()
wots.isInfinity()
wots.isBoolean()
wots.isRegExp()
wots.isArray()
wots.isObject()
wots.isFunction()
wots.isDate()
wots.isError()
wots.isArguments()
wots.isPromise()
```

# the name

`wots` basically stands for `what is` but is shorter :wink:

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