Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/cheton/ensure-type

Ensure runtime type safety and perform type coercion if needed.
https://github.com/cheton/ensure-type

Last synced: 10 days ago
JSON representation

Ensure runtime type safety and perform type coercion if needed.

Awesome Lists containing this project

README

        

# ensure-type [![Build Status](https://travis-ci.com/cheton/ensure-type.svg?branch=master)](https://travis-ci.com/cheton/ensure-type) [![Coverage Status](https://coveralls.io/repos/github/cheton/ensure-type/badge.svg?branch=master)](https://coveralls.io/github/cheton/ensure-type?branch=master)

[![NPM](https://nodei.co/npm/ensure-type.png?downloads=true&stars=true)](https://www.npmjs.com/package/ensure-type)

Ensure runtime type safety and perform type coercion if needed.

## Install

```
$ npm install --save ensure-type
```

## Usage

```js
import { ensureArray } from 'ensure-type';

ensureArray(null);
//=> []

ensureArray('apple');
//=> ['apple']

ensureArray(['apple', 'banana']);
//=> ['apple', 'banana']
```

## API

### Array
- [`ensureArray`](docs/ensureArray.md)

### BigInt
- [`ensureBigInt`](docs/ensureBigInt.md)

### Boolean
- [`ensureBoolean`](docs/ensureBoolean.md)

### Function
- [`ensureFunction`](docs/ensureFunction.md)

### Number
- [`ensureNumber`](docs/ensureNumber.md)
- [`ensureNegativeNumber`](docs/ensureNegativeNumber.md)
- [`ensurePositiveNumber`](docs/ensurePositiveNumber.md)
- [`ensureFiniteNumber`](docs/ensureFiniteNumber.md)
- [`ensureNegativeFiniteNumber`](docs/ensureNegativeFiniteNumber.md)
- [`ensurePositiveFiniteNumber`](docs/ensurePositiveFiniteNumber.md)
- [`ensureInteger`](docs/ensureInteger.md)
- [`ensureNegativeInteger`](docs/ensureNegativeInteger.md)
- [`ensurePositiveInteger`](docs/ensurePositiveInteger.md)
- [`ensureNonNegativeInteger`](docs/ensureNonNegativeInteger.md)
- [`ensureNonPositiveInteger`](docs/ensureNonPositiveInteger.md)

### Object
- [`ensurePlainObject`](docs/ensurePlainObject.md)

### String
- [`ensureString`](docs/ensureString.md)

## License

MIT