@migudevelop/types-utils
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

types-utils

A collection of functions to check the types of the values provided.

Table of Contents

Details

Installation

  # NPM
  pnpm install @migudevelop/types-utils

  # NPM
  npm install @migudevelop/types-utils

  # YARN
  yarn add @migudevelop/types-utils

Usage

Using CommonJS

// CommonJS
const typeUtils = require('@migudevelop/types-utils')

console.log(typeUtils.isString('Programming'))

Using ES6 Modules or TypeScript:

// ES6 Modules or TypeScript
import { isString } from '@migudevelop/types-utils'

console.log(isString('Programming'))

Utilities

Check types

  • isString(): Determines whether a value is a string

  • isNumber(): Determines whether a value is a number

  • isBoolean(): Determines whether a value is a boolean

  • isNull(): Determines whether a value is null

  • isArray(): Determines whether a value an array

  • isFunction(): Determines whether a value is a function

  • isUndefined(): Determines whether a value is undefined

  • isNullish(): Determines whether a value is undefined or null

Check empty values

  • isEmptyString(): Determines whether a value is an empty string

  • isEmptyArray(): Determines whether a value is an empty array

Ensure values

  • ensureString(): Determines whether a value is a string and returns it, but otherwise returns an empty string

  • ensureBoolean(): Determines whether a value is a boolean and returns it, but otherwise returns a false value

  • ensureNumber(): Determines whether a value is a number and returns it, but otherwise returns a zero value

  • ensureUndefined(): Determines whether a value is an undefined and returns it, but otherwise returns an undefined value

  • ensureNull(): Determines whether a value is a null and returns it, but otherwise returns a null value

  • ensureArray(): Determines whether a value is an array and returns it, but otherwise returns an empty array


License

MIT License

Copyright (c) 2024 Migudevelop

Package Sidebar

Install

npm i @migudevelop/types-utils

Weekly Downloads

7

Version

1.3.0

License

MIT

Unpacked Size

15.9 kB

Total Files

17

Last publish

Collaborators

  • migudevelop