1.0.2 • Published 12 months ago

@radicjs/type-check v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

type-check

type checkers / guards

The @radicjs/type-check package provides a collection of type guards and type checkers for various JavaScript data types. It includes functions to determine if a value is of a specific type, such as number, string, boolean, function, regexp, array, date, error, or object. This package is useful for performing precise type checks in TypeScript and JavaScript projects.

Key Features:

  • Type Guards: Functions to assert the type of a value.
  • Type Checkers: Functions to check if a value is of a specific type.
  • Comprehensive Coverage: Supports a wide range of types including primitives and complex types.
  • Lightweight: Minimal footprint with efficient type checking.

Installation:

npm install @radicjs/type-check
# or
yarn add @radicjs/type-check

Usage:

import { isNumber, isString, kindOf } from '@radicjs/type-check';

console.log(isNumber(123)); // true
console.log(isString('hello')); // true
console.log(kindOf([])); // 'array'

API

export type KindsOf = 'number' | 'string' | 'boolean' | 'function' | 'regexp' | 'array' | 'date' | 'error' | 'object';
export const kindOf = (value: any):KindsOf
export const isNumber = (value: any): value is number =>{}
export const isString = (value: any): value is string =>{}
export const isBoolean = (value: any): value is boolean =>{}
export const isFunction = (value: any): value is Function =>{}
export const isRegExp = (value: any): value is RegExp =>{}
export const isArray = (value: any): value is Array =>{}
export const isDate = (value: any): value is Date => {}
export const isError = (value: any): value is Error =>{}
export const isObject = (value: any): value is object =>{}
export const isNothing = (value: any): value is undefined =>{}
export const isNumericString = (value: any): boolean => isString(value) && !isNaN(value as any);
export const isStringNumber = (value: any): value is string | number => isNumber(value) || isNumericString(value);
export const isNumberObject = (target: any): boolean => {}
export const isES6Promise = (p: any): p is PromiseLike<any> => {}
export const isNativePromise = (p: any): boolean => {}
export const isPromise = <T = any>(p: any): p is PromiseLike<T> => {}
export const isConstructor = (value: any): boolean => {}

Size

  • Total: 7.78 kB
  • Gzip: 2.70 kB

Coverage

StFile% Stmts% Branch% Funcs% LinesUncovered Line #s
šŸ”“All files0000

License:

MIT License

Author:

Robin Radic

Repository:

GitHub - robinradic/radicjs

1.0.2

12 months ago