Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/cheton/ensure-type
- Owner: cheton
- License: mit
- Created: 2020-10-14T08:23:41.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-30T08:21:08.000Z (over 3 years ago)
- Last Synced: 2024-10-30T00:00:12.881Z (20 days ago)
- Language: JavaScript
- Size: 51.8 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
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