is-what
Advanced tools
Comparing version 3.1.1 to 3.1.2
{ | ||
"name": "is-what", | ||
"version": "3.1.1", | ||
"description": "JS type check (TypeScript supported) functions like `isAnyObject() isArray()` etc. A simple & small integration.", | ||
"version": "3.1.2", | ||
"description": "JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.", | ||
"main": "dist/index.cjs.js", | ||
@@ -6,0 +6,0 @@ "module": "dist/index.esm.js", |
@@ -9,22 +9,53 @@ # is What? 🙉 | ||
**Motivation:** I built is-what because the existing solutions were all too complex. | ||
**Motivation:** I built is-what because the existing solutions were all too complex or too poorly built. | ||
### Functions | ||
I was looking for: | ||
- A simple way to check any kind of type (including non-primitives) | ||
- Be able to check if an object is a plain object `{}` or not ‼️ | ||
- Let TypeScript automatically know what type a value is when checking | ||
isPlainObject, isAnyObject, isString, isNumber, isBoolean, isFunction, isArray, isUndefined, isNull, isRegExp, isDate, isSymbol, isPrimitive, isType, getType | ||
And that's exactly what `is-what` is! (what a great wordplay 😃) | ||
### Usage | ||
## Included functions in is-what | ||
**The important ones:** | ||
isPlainObject, isAnyObject | ||
**The regulars:** | ||
isString, isNumber, isBoolean, isFunction, isArray, isUndefined, isNull, isRegExp, isDate, isSymbol, isPrimitive | ||
**The special ones:** | ||
isType, getType | ||
## Usage | ||
is-what is really easy to use, and all functions above work just like you'd expect. | ||
**The regular ones** above all return `true` or `false`. | ||
```js | ||
import { isString, isType, getType } from 'is-what' | ||
import { isString, isDate, isNumber } from 'is-what' | ||
isString('') // returns true | ||
isDate(new Date()) // returns true | ||
isNumber(0) // returns true | ||
``` | ||
**The special ones** you'll probably won't need much | ||
```js | ||
import { getType, isType } from 'is-what' | ||
getType('') // returns 'String' | ||
// pass a Type as second param: | ||
isType('', String) // returns true | ||
getType('') // returns 'String' | ||
``` | ||
#### isPlainObject vs isAnyObject | ||
And **the important ones**... | ||
### isPlainObject vs isAnyObject | ||
Checking for a JavaScript object can be really difficult. In JavaScript you can create classes that will behave just like JavaScript objects but might have completely different prototypes. With is-what I went for this classification: | ||
@@ -41,3 +72,3 @@ - `isPlainObject` will only return `true` on plain JavaScript objects and not on classes or others | ||
} | ||
const specialObject = new SpecialObject('I am a special object! I am a class!!!') | ||
const specialObject = new SpecialObject('I am a special object! I am a class instance!!!') | ||
@@ -58,3 +89,3 @@ // let's check: | ||
#### Useful number & date exception: | ||
### Useful number & date exception: | ||
@@ -68,3 +99,3 @@ Checking for `isNumber` and `isDate` will return `false` if the payload is `NaN` or an invalid date. This is done intentionally and especially useful when you need to check if numbers or dates are correct in your functions! | ||
### TypeScript usage example: | ||
## TypeScript usage example: | ||
@@ -110,4 +141,12 @@ is-what makes TypeScript know the type during if statements. This means that a check returns the type of the payload for TypeScript users. | ||
### Source code | ||
## Meet the family | ||
- [is-what](https://github.com/mesqueeb/is-what) | ||
- [merge-anything](https://github.com/mesqueeb/merge-anything) | ||
- [filter-anything](https://github.com/mesqueeb/filter-anything) | ||
- [find-and-replace-anything](https://github.com/mesqueeb/find-and-replace-anything) | ||
- copy-anything (WIP) | ||
## Source code | ||
It's litterally just these functions: | ||
@@ -132,7 +171,1 @@ | ||
See the full source code [here](https://github.com/mesqueeb/is-what/blob/master/src/index.ts). | ||
## Tests | ||
``` | ||
npm run test | ||
``` |
35116
166