# iwt

> iwt is a javascript utility that returns the value passed in when the passed variable is the value of the type you want, otherwise it returns the value of the default type.

Latest version **1.0.8** (published 2019-10-14) · ISC license · 0 weekly downloads

## Install

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

## 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 | 1.0.8 |
| Published | 2019-10-14 |
| First published | 2019-10-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | jxchen |
| Maintainers | jxchenvip |
| Keywords | iwt, getValue, typeOf |

## Links

- npm: https://www.npmjs.com/package/iwt
- npm.io page: https://npm.io/package/iwt

## Recent versions

- 1.0.8 (latest) — 2019-10-14
- 1.0.7 — 2019-10-14

## README

# iwt

iwt is a javascript utility that returns the value passed in when the passed variable is the value of the type you want, otherwise it returns the value of the default type.

<!-- iwt是一个javascript实用程序，当传递的变量是所需类型的值时，它会返回传入的值，否则它将返回默认类型的值。
 -->

## Example Usage

```js
var iwt = require("iwt");
```

```js
const arr = { a: ["a"], b: 1 };
const obj = { a: { a: 1 }, b: 1 };

iwt.array(arr.a); // ['a'];
iwt.array(arr.b); // [];
iwt.array(arr.b, ["b"]); // ['b'];

iwt.object(obj.a); // {a: 1};
iwt.object(obj.b); // {};
iwt.object(obj.b, { b: 1 }); // {b: 1};

// ...
// iwt.null
// iwt.undefined
// iwt.function
// iwt.boolean
// iwt.number
// iwt.null
// iwt.null

const get = require("lodash/get");
const a = {};
iwt.object(get(a, "b.c.e.f.g.h")); // {};
```

## API

| methods                           | return value                                                                                                |
| --------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| array(any, defaultValue)          | []                                                                                                          |
| object(any, defaultValue)         | {}                                                                                                          |
| function(any, defaultValue)       | new Function()                                                                                              |
| boolean(any, defaultValue)        | true                                                                                                        |
| string(any, defaultValue)         | ''                                                                                                          |
| number(any, defaultValue)         | 0                                                                                                           |
| undefined(any, defaultValue)      | undefined                                                                                                   |
| null(any, defaultValue)           | null                                                                                                        |
| date(any, defaultValue)           | new Date()                                                                                                  |
| regExp(any, defaultValue)         | new RegExp()                                                                                                |
| symbol(any, defaultValue)         | Symbol('symbol')                                                                                            |
| getValue(type, any, defaultValue) | 无                                                                                                          |
| typeOf(any)                       | "number","string","function", "regExp", "null", "undefined", "date", "boolean", "object", "array", "symbol" |

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