https://github.com/unadlib/be-type
be-type is based on ECMAScript2015+ proxy feature
https://github.com/unadlib/be-type
typecheck
Last synced: 12 months ago
JSON representation
be-type is based on ECMAScript2015+ proxy feature
- Host: GitHub
- URL: https://github.com/unadlib/be-type
- Owner: unadlib
- License: mit
- Created: 2017-09-22T11:27:05.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-28T16:24:44.000Z (over 8 years ago)
- Last Synced: 2025-06-16T22:54:08.706Z (about 1 year ago)
- Topics: typecheck
- Language: JavaScript
- Homepage:
- Size: 42 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# be-type
be-type is based on ECMAScript2015+ proxy feature
[](https://travis-ci.org/unadlib/be-type)
[](https://coveralls.io/github/unadlib/be-type?branch=master)
[](https://www.npmjs.com/package/be-type)
[](https://www.npmjs.com/package/be-type)
[](https://www.npmjs.com/package/be-type)
### Usage
```bash
yarn add be-type
npm install --save be-type
```
JavaScript:
```javascript
import be from 'be-type';
be.function(()=>{}); // true
```
Custom type check:
```javascript
//be.js
import be,{setBe} from 'be-type';
export default setBe({
Negative:(value)=> be.Number(negative) && negative < 0
})
//other.js
import be from '../be.js';
be.Negative(-1); // true
```
### API
#### Interface Rule:
1. If the first letter of the API is **lowercase**, then it refers to toString.call(value), the type returned by call.
> be.function(()=>{}) `equivalent` toString.call(()=>{}) ==== "[object Function]"
> be.generatorFunction(function* (){}) `equivalent` toString.call(function* (){}) ==== "[object GeneratorFunction]"
> be.uint8Array(new Uint8Array()) `equivalent` toString.call(new Uint8Array()) ==== "[object Uint8Array]"
> etc..
2. if the first letter of the API is **Uppercase**, it means not toString.call(value), Custom type returned by call
#### Default built-in type check:
| Interface | Spec |
| :------------ | -----------------------------------------:|
| Function | plain function |
| Object | plain object |
| String | basic string |
| Number | basic number |
| Boolean | basic boolean |
| NaN | strict equality to `NaN` |
| Nil | `null` or `undefined` |
| Empty | none length |
| Infinity | strict equality to `Infinity` |
| Finite | basic number and not `NaN` or `Infinity` |
| Native | pristine native function |
| SafeInteger | based on Number.isSafeInteger |
| Integer | based on Number.isInteger |
| Element | HTML Element |