0.0.5 • Published 7 months ago

qolib v0.0.5

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

QoLib for JavaScript

A small JavaScript library that enhances Quality of Life by solving various problems.

TypeChecker

A set of methods for checking data types in JavaScript.

import { isNumber } from 'qolib'

isNumber(10)   // true
isNumber('10') // true
isNumber([10]) // false
isNumber(null) // false
isNumber('')   // false

List of checkers

isNullChecks if the value is null
isUndefinedChecks if the value is undefined
isNoneChecks if the value is null or undefined
isBoolChecks if the value is a boolean
isObjectChecks if the value is an object
isArrayChecks if the value is an array
isStringChecks if the value is a string
isEmptyStringChecks if the string is empty
isWhiteSpaceStringChecks if the string is empty or consists only of whitespace
isNumberChecks if the value is a number or a string containing a number
isFunctionChecks if the value is a function
isIterableChecks if the value is iterable

DateTime

Gets a string representation of the date and time in the specified format.

import { dateTime } from 'qolib'

// Current date and time in the format 'YYYY-MM-DD HH:mm:ss'
dateTime()

// Current date in the format 'DD-MM-YYYY'
dateTime('%d-%m-%Y')

// Custom date in the format 'YYYY-MM-DD HH:mm:ss'
dateTime(customDateObject)

// Custom date in the format 'DD-MM-YYYY'
dateTime(customDateObject, '%d-%m-%Y')

Random

Generates a random integer between minimum and maximum values.

import { random } from 'qolib'

random(0, 4) // random int between 0-4 inclusive

RangeNumber

Creates a range of numbers with the specified step (default is 1). The function uses lazy evaluation, which allows to create a conditionally infinite range.

import { range } from 'qolib'

for (const number in range(0, 5)) {
  console.log(number) // 0, 1, 2, 3, 4, 5
}

console.log(...range(-5, 5, 2)) // -5, -3, -1, 1, 3, 5

Installation

npm i qolib