https://github.com/jakesidsmith/tis
Type safe variable checks
https://github.com/jakesidsmith/tis
Last synced: 3 months ago
JSON representation
Type safe variable checks
- Host: GitHub
- URL: https://github.com/jakesidsmith/tis
- Owner: JakeSidSmith
- License: mit
- Created: 2021-03-17T18:26:58.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-05-22T16:50:45.000Z (almost 4 years ago)
- Last Synced: 2025-02-03T04:41:51.994Z (4 months ago)
- Language: TypeScript
- Size: 563 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# 'tis
**Type safe variable checks**
## Install
```shell
npm i @jakesidsmith/tis -P
````-P` is shorthand for `--save-production` and will add this to your package `dependencies`.
Use `-D` (shorthand for `--save-dev`) if you are only using this for testing.
## Available utilities
- `isNumber`: Returns true when the input is a number
- `isString`: Returns true when the input is a string
- `isBoolean`: Returns true when the input is a boolean
- `isUndefined`: Returns true when the input is undefined
- `isDefined`: Returns true when the input is not undefined
- `isNull`: Returns true when the input is null
- `isNullish`: Returns true when the input is null or undefined
- `isArray`: Returns true when the input is an array
- `isObject`: Returns true when the input is an object (includes arrays, excludes null)
- `isFunction`: Returns true when the input is a function or class constructor## Example usage
```ts
import { isObject, isArray, isString } from '@jakesidsmith/tis';const example = (
input: string | number | readonly string[] | Record
) => {
if (isObject(input)) {
if (isArray(input)) {
// Guaranteed to be a readonly string[]
} else {
// Guaranteed to be a Record
}
} else if (isString(input)) {
// Guaranteed to be a string
} else {
// Guaranteed to be a number
}
};
```