# basetype

> basic javascript type

Latest version **0.1.4** (published 2017-01-10) · MIT license · 0 weekly downloads

## Install

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

## 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.4 |
| Published | 2017-01-10 |
| First published | 2016-09-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ddchen |
| Maintainers | ddchen |
| Keywords | type, js, javascript, basic |

## Links

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

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.1.4 (latest) — 2017-01-10
- 0.1.3 — 2016-12-12
- 0.1.2 — 2016-10-23
- 0.1.1 — 2016-10-18
- 0.1.0 — 2016-09-30

## README

# basetype

Provide basic type validation functions and simple type composition.

[![Build Status](https://travis-ci.org/LoveKino/basetype.svg)](https://travis-ci.org/LoveKino/basetype.svg)
[![Coverage Status](https://coveralls.io/repos/github/LoveKino/basetype/badge.svg?branch=master)](https://coveralls.io/github/LoveKino/basetype?branch=master)

## install

`npm i basetype --save`

## type function

Type function is a boolean function, accept one argument and return boolean value.

eg:
```js
let {likeArray} = require('basetype');

likeArray(123); // => false
likeArray([1, 2, 3]); // => true
```

## basic types

```js
isUndefined, isNull, isFalsy, likeArray, isString, isObject, isFunction, isNumber, isBool, isNode, isPromise, isReadableStream, isWritableStream
```

## compose types

- and

```js
let newType = and(isObject, isArray);
newType([1, 2, 3]); // true
newType({}); // false
```

- or

```js
let newType = or(isNumber, isBool);
newType(4); // true
newType(true); // true
newType("123"); // false
```

- not

```js
let newType = not(isNumber);
newType(1); // false
newType("123"); // true
```

- mapType

```js
let type = mapType({
    a: isNumber,
    b: isBool
});

type({
    a: 3,
    b: false
}); //true

type({
    a: 3,
    b: {}
}); //false
```

- listType

```js
let type = listType(isNumber);
type([1, 2, 3]); //true
type([1, {}, 3]); //false
```

- any

```js
any([1, 2, 3], isNumber); //true
any([1, {}, 3], isNumber); //false
```

- exist

```js
exist([1, 2, 3], isString); //false
exist([1, {}, 3], isNumber); // true
```

## function arguments type

```js
let fun = funType((a, b) => a + b, [
    isNumber,
    isNumber
]);

fun(1, 2); // 3
fun('1', 2); // TypeError
```

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