https://github.com/simplisticated/easy-types
Better way of working with types in TypeScript
https://github.com/simplisticated/easy-types
Last synced: 6 months ago
JSON representation
Better way of working with types in TypeScript
- Host: GitHub
- URL: https://github.com/simplisticated/easy-types
- Owner: simplisticated
- License: mit
- Created: 2022-09-01T17:07:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-22T19:05:39.000Z (about 3 years ago)
- Last Synced: 2025-02-10T01:39:13.770Z (about 1 year ago)
- Language: TypeScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## At a Glance
**easy-types** is a better way of working with types in TypeScript. Much better than the normal approach suggested by JavaScript. If you are tired of using `typeof`, `Array.isArray`, `=== null` and other annoying things, then this library is a solution.
## How to Get Started
Type in Terminal:
```
npm install --save @russo-programmisto/easy-types
```
or, if you prefer **yarn** over **npm**, type:
```
yarn add @russo-programmisto/easy-types
```
Then add import instruction to your code:
```typescript
import { getType, Type } from '@russo-programmisto/easy-types'
```
## Requirements
Basic knowledge of TypeScript and NPM.
## Usage
```typescript
const obj = {};
const type = getType(obj);
type === Type.object // true
type === Type.null // false
// get type easily
getType("") === Type.string // true
getType(undefined) === Type.undefined // true
// or even easier
isType("", Type.string) // true
// check whether it's array or object
isType(obj, Type.array, Type.object)
// check missing values
isNullOrUndefined(obj)
// check empty values
isEmptyString("") // true
isEmptyArray([]) // true
isEmptyObject({}) // true
// or you can simply use `isEmpty` method that works for strings, arrays, and non-array objects:
isEmpty("") // true
isEmpty([]) // true
isEmpty({}) // true
// combine checks
isEmpty(obj.field) || isNullOrUndefined(obj.field)
```
## License
**types** is available under the MIT license. See the [LICENSE](./LICENSE) file for more info.