An open API service indexing awesome lists of open source software.

https://github.com/vitalishapovalov/typecheck

Super-simple type checkers
https://github.com/vitalishapovalov/typecheck

type-predicates typechecking typescript utilities-js utilities-library

Last synced: 2 months ago
JSON representation

Super-simple type checkers

Awesome Lists containing this project

README

          

# Type checking library

[![npm version](https://badge.fury.io/js/%40js-utilities%2Ftypecheck.svg)](https://badge.fury.io/js/%40js-utilities%2Ftypecheck)
[![Build Status](https://travis-ci.org/vitalishapovalov/Typecheck.svg?branch=master)](https://travis-ci.org/vitalishapovalov/Typecheck)

A set of super-simple type checkers. Each checker returns `boolean` value. Most checkers are typescript [type predicates](https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates).

## Installation

```bash
npm i -S @js-utilities/typecheck
```

## Usage example

```typescript
import { isCallable } from "@js-utilities/typecheck";

const a: unknown = global.value;

if (isCallable(a)) a();
```

## Available checkers:

| Checker | Return type |
| -------------------- | -------------------------------|
| `isCallable` | `boolean` |
| `isFunction` | `value is Function` |
| `isArrowFunction` | `boolean` |
| `isArray` | `value is T[]` |
| `isObject` | `value is T` |
| `isBoolean` | `value is boolean` |
| `isUndefined` | `value is undefined` |
| `isNumber` | `value is number` |
| `isString` | `value is string` |
| `isSymbol` | `value is symbol` |
| `isNull` | `value is null` |
| `isMap` | `value is Map` |
| `isSet` | `value is Set` |
| `isWeakSet` | `value is WeakSet` |
| `isWeakMap` | `value is WeakMap` |
| `isPromise` | `value is Promise` |

## License

[MIT License](https://github.com/vitalishapovalov/Typecheck/blob/master/LICENSE)