1.0.0 • Published 2 years ago

@russo-programmisto/easy-types v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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:

import { getType, Type } from '@russo-programmisto/easy-types'

Requirements

Basic knowledge of TypeScript and NPM.

Usage

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 file for more info.