# is-explicit

> Combines instance of operator and typeof operator in a way that works seamlessly with objects and literals.

Latest version **3.0.1** (published 2019-01-25) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2019-01-25 |
| First published | 2016-02-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 19.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ben Gaumond |
| Maintainers | benzed |
| Keywords | is, operator, explicit, type-check, type |

## Links

- npm: https://www.npmjs.com/package/is-explicit
- Repository: https://github.com/BenZed/is-explicit
- Homepage: https://github.com/BenZed/is-explicit#readme
- Issues: https://github.com/BenZed/is-explicit/issues
- npm.io page: https://npm.io/package/is-explicit

## Dependencies (1)

- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.3.1

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 3.0.1 (latest) — 2019-01-25
- 3.0.0 — 2019-01-15
- 2.1.0 — 2018-05-30
- 2.0.0 — 2018-05-17
- 1.4.1 — 2017-09-16
- 1.4.0 — 2017-09-16
- 1.3.0 — 2017-07-28
- 1.2.2 — 2017-06-22
- 1.2.1 — 2017-06-22
- 1.2.0 — 2017-06-21
- 1.1.0 — 2016-09-07
- 1.0.6 — 2016-08-29
- 1.0.5 — 2016-08-28
- 1.0.4 — 2016-06-28
- 1.0.3 — 2016-05-24
- … 3 more at https://npm.io/package/is-explicit/versions

## README

# is-explicit

# Why ?
- You want to do explicit type checks.
- You don't want to have to differentiate between ```typeof``` and ```instanceof```
- You keep a cool head and bring justice to chaos.

# 2.0

Breaking changes from the 1.x release, but the resulting
changes make ```is-explicit``` faster and more composable.

# Usage

``npm install is-explicit``
```js
import is from 'is-explicit'
```

## Does a variable have a value?
```js
is.defined(undefined)         //false
is.defined(null)              //false
is.defined(NaN)               //false
is.defined(10)                //true
```

## Is a variable a specific type?
```js
is([], Object)         //true
is([], Array)          //true

is(true, Boolean)      //true
is(false, Boolean)     //true
is(10, Number)         //true

is('str', String)      //true
is('str', Object)      //false

is(new String('str'), String)   //true
is(new String('str'), Object)   //true

is(/expr/, RegExp)             //true
is(/expr/, Object)             //true

is(function(){}, Object)       //true
is(function(){}, Function)     //true

is(new function(){}, Object)   //true
is(new function(){}, Function) //False

is(Array, Object)      //true
is(Array, Function)    //true
is(Array, Array)       //false

is(Symbol(), Symbol)        //true
is(Symbol.iterator, Symbol) //true
is(Symbol(), Object)        //false
```

## Is a variable a custom type?
```js
function Foo() {}
is (new Foo(), Foo) // true

const foo = function(){}
const bar = function(){}

is(new foo(), foo) // true
is(new bar(), foo) // false
```

## Is a variable one of multiple types?

```js
is('str', [Number, Boolean, String]) // true
```

## Types are expected to be functions:
```js
is('str', 'otherstring') //throws Error
```

## Is a value an Array of a specific type?
```js
is.arrayOf(['str'], String)                       // == true
is.arrayOf([0, false, new Date(), 'str'], String) // == false
is.arrayOf([0,'str',10,'cake'], [String, Number]) // == true,

```

## Is a value an Object of a specific type?
```js
is.objectOf([ 0, 'str' ], String)                     // == false
is.objectOf({ }, String)                              // == false
is.objectOf({ foo: '1', bar: '2' }, String)           // == true
is.objectOf({ foo: '1', bar: 2 }, [ String, Number ]) // == true

```

## Is a value a plain Object?
```js
is.plainObject(['str'])             // == false
is.plainObject(new Date())          // == false
is.plainObject({})                  // == true
is.plainObject(new Object())        // == true

function FooBar() { }

is.plainObject(new FooBar)           // == false
```

## Binding

Binding is now binds it to a type:

```js
class Foo { }

const isFoo = Foo::is

isFoo(new Foo()) // true
```

Bind to multiple types:

```js
const isBoolOrFunc = [ Boolean, Function ]::is

isBoolOrFunc(false) // true

```

Better composition:
```js
const mixed = [ 0, 'string', 1, true, 2, Symbol('bad') ]

const numbers = mixed.filter(Number::is)
```

## Shortcuts

```js
import is from 'is-explicit'

const value = 'whatever'

is.string(value)    // == String::is(value)
is.number(value)    // == Number::is(value)
is.bool(value)      // == Boolean::is(value)
is.func(value)      // == Function::is(value)
is.symbol(value)    // == Symbol::is(value)
is.primitive(value) // == [ Boolean, Number, String ]::is(value)

is.arrayOf.string(value)    // == String::is.arrayOf
is.arrayOf.number (value)   // == Number::is.arrayOf
is.arrayOf.bool(value)      // == Boolean::is.arrayOf
is.arrayOf.symbol(value)    // == Symbol::is.arrayOf
is.arrayOf.func(value)      // == Function::is.arrayOf
is.arrayOf.primitive(value) // == [ Boolean, Number, String ]::is.arrayOf

is.objectOf.string(value)    // == String::is.objectOf
is.objectOf.number (value)   // == Number::is.objectOf
is.objectOf.bool(value)      // == Boolean::is.objectOf
is.objectOf.symbol(value)    // == Symbol::is.objectOf
is.objectOf.func(value)      // == Function::is.objectOf
is.objectOf.primitive(value) // == [ Boolean, Number, String ]::isArrayOf


```

## Additional Helpers

```js
import is from 'is-explicit'

is.defined() // returns true if input is not null, undefined or NaN

is.arrayOf.plainObject() // returns true if input is an array of plain objects

is.instanceable() // returns true if input is a function with a prototype (ie: arrow functions will return false)

is.subclassOf() // returns true if input is a class that extends the provided type

```

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