JavaScript typecheck
npm install @konata9/typecheck.jsReally simple type check function tool with Pure JavaScript. Check varible type in JavaScript.
Rewrited by TypeScript
``shell`
npm i @konata9/typecheck.js
require usage has benn changed!
`javascript
import typecheck from '@konata9/typecheck.js';
// or
import { typeCheck } from '@konata9/typecheck.js';
// or
const { typecheck } = require('@konata9/typecheck.js');
const arr = [];
typecheck(arr); // array
`
The target is the varible you want to check. The return type string in table below.
| type | example | return |
| --------- | --------------------------- | --------- |
| string | typecheck("a") | string |typecheck(1)
| number | | number |typecheck(true)
| boolean | | boolean |typecheck(null)
| null | | null |typecheck(undefined)
| undefined | | undefined |typecheck({})
| Object | | object |typecheck([])
| Array | | array |typecheck(new Set())
| Set | | set |typecheck(new Map())
| Map | | map |typecheck(Symbol())
| Symobol | | symbol |typecheck((a, b)=> a + b)
| Function | | function |
This module is tested by mocha. You can find the test case in test folder or run the test command below (You need full source on the github page).
`shell``
npm run test