0.1.8 • Published 2 years ago

roy-type-assert v0.1.8

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

type-assert

The utility which is used to assert a variable's type

Build Setup

# install dependencies
npm install

# start development server for debug
npm run dev

# build in production
npm run build

Install

npm install --save roy-type-assert

Usage

import { VariableType, getType, isNullOrUndefined, isStringEmpty, getFloatInfo, isPrimitiveType } from 'roy-type-assert';

getType(10) === VariableType.bNumber;
isNullOrUndefined(undefined) === true;
isNullOrUndefined(null) === true;
isStringEmpty('') === true;
isPrimitiveType(5) === true;
let { isNumber, isFloat, pointRightCount } = getFloatInfo(1.53);

Options

VariableType

Enum ValueData Type
bUndefinedundefined
bNullnull
bNumbernumber
bBooleanboolean
bStringstring
bFunctionfunction
bRegExpregexp
bArrayarray
bDatedate
bErrorerror
bNodenode
bElementelement
bDocumentdocument
bArraylistarraylist
bObjectobject

API Reference

getType API signature

function getType(obj: any): VariableType;

isPrimitiveType API signature

function isPrimitiveType(o: any): boolean;

isNullOrUndefined API signature

function isNullOrUndefined(v: any): boolean;

isStringEmpty API signature

function isStringEmpty(str: any): boolean;

getFloatInfo API signature

function getFloatInfo(n: number): {
  isNumber: boolean;
  isFloat: boolean;
  pointRightCount: number;
};

Type Guards

function isFunction(o: any): boolean;
function isUndefined(o: any): o is undefined;
function isNull(o: any): o is null;
function isNumber(o: any): o is number;
function isBoolean(o: any): o is boolean;
function isString(o: any): o is string;
function isArray<T>(o: any): o is Array<T>;
function isDate(o: any): o is Date;
0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago