npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@luwio/utilities

v0.0.4

Published

Template for all libraries powered by JavaScript

Downloads

6,482

Readme

This project provides a set of utility functions to perform various type checks and transformations.

Functions

isNumeric

Checks if the given value is numeric.

Parameters:

  • value: The value to check.

Returns:

  • boolean: True if the value is numeric, false otherwise.
import { isNumeric } from "@/index";

console.log(isNumeric(123)); // true
console.log(isNumeric("123")); // true
console.log(isNumeric("abc")); // false
console.log(isNumeric(null)); // false

isBoolean

Checks if the given value is a boolean.

Parameters:

  • value: The value to check.

Returns:

  • boolean: True if the value is a boolean, false otherwise.
import { isBoolean } from "@/index";

console.log(isBoolean(true)); // true
console.log(isBoolean(false)); // true
console.log(isBoolean("true")); // false
console.log(isBoolean(0)); // false
console.log(isBoolean(1)); // false

isNil

Checks if the given value is null or undefined.

Parameters:

  • value: The value to check.

Returns:

  • boolean: True if the value is null or undefined, false otherwise.
import { isNil } from "@/index";

console.log(isNil(null)); // true   
console.log(isNil(undefined)); // true  
console.log(isNil(0)); // false

isNull

Checks if the given value is null.

Parameters:

  • value: The value to check.

Returns:

  • boolean: True if the value is null, false otherwise.
import { isNull } from "@/index";

console.log(isNull(null)); // true
console.log(isNull(undefined)); // false

isString

Checks if the given value is a string.

Parameters:

  • value: The value to check.

Returns:

  • boolean: True if the value is a string, false otherwise.

import { isString } from "@/index";

console.log(isString("abc")); // true
console.log(isString(123)); // false

isUndef

Checks if the given value is undefined.

Parameters:

  • value: The value to check.

Returns:

  • boolean: True if the value is undefined, false otherwise.

import { isUndef } from "@/index";

console.log(isUndef(undefined)); // true
console.log(isUndef(null)); // false

isFunction

Checks if the given value is a function.

Parameters:

  • value: The value to check.

Returns:

  • boolean: True if the value is a function, false otherwise.
import { isFunction } from "@/index";

console.log(isFunction(() => {})); // true
console.log(isFunction("abc")); // false

isObject

Checks if the given value is an object.

Parameters:

  • value: The value to check.

Returns:

  • boolean: True if the value is an object, false otherwise.
import { isObject } from "@/index";

console.log(isObject({})); // true
console.log(isObject([])); // true
console.log(isObject([], true)); // false

console.log(isObject("abc")); // false

is

Checks if the given value matches the specified type.

Parameters:

  • value: The value to check.
  • predicate: The predicate function to check the type.

Returns:

  • boolean: True if the value matches the type, false otherwise.

import { is } from "@/index";

console.log(is<number>(123, isNumber)); // true
console.log(is<string>("abc", isString)); // true
console.log(is<number>("abc", isNumber)); // false

isNumber

Checks if the given value is a number.

Parameters:

  • value: The value to check.

Returns:

  • boolean: True if the value is a number, false otherwise.

import { isNumber } from "@/index";

console.log(isNumber(123)); // true
console.log(isNumber("123")); // false

hasProp

Checks if the given object has the specified property.

Parameters:

  • obj: The object to check.
  • prop: The property to check for.

Returns:

  • boolean: True if the object has the property, false otherwise.

import { hasProp } from "@/index";

console.log(hasProp({ a: 1 }, "a")); // true
console.log(hasProp({ a: 1 }, "b")); // false

hasPropOfType

Checks if the given object has the specified property of the specified type.

Parameters:

  • obj: The object to check.
  • prop: The property to check for.
  • type: The type to check for.

Returns:

  • boolean: True if the object has the property of the specified type, false otherwise.

import { hasPropOfType } from "@/index";

console.log(hasPropOfType({ a: 1 }, "a", "number")); // true
console.log(hasPropOfType({ a: 1 }, "a", "string")); // false

StringToArray

Converts a string to an array, splitting by the specified delimiter.

Parameters:

  • items: The string to convert.
  • split: The delimiter to split by.
  • callback: Optional callback to transform each item.

Returns:

  • T[]: The resulting array.

import { StringToArray } from "@/index";

console.log(StringToArray("a,b,c", ",")); // ["a", "b", "c"]
console.log(StringToArray("a,b,c", ",", (item) => item.toUpperCase())); // ["A", "B", "C"]

NameOf

Gets the name of the specified property.

Parameters:

  • prop: The property to get the name of.

Returns:

  • string: The name of the property.

import { NameOf } from "@/index";

console.log(NameOf("a")); // "a"
console.log(NameOf(123)); // "123"

UniqueBy

Removes duplicate objects from an array based on a specified property.

Parameters:

  • array: The array to process.
  • key: The property to check for uniqueness.

Returns:

  • T[]: The array with unique objects.
import { UniqueBy } from "@/index";

console.log(UniqueBy([{ id: 1 }, { id: 2 }, { id: 1 }], "id")); // [{ id: 1 }, { id: 2 }]

ChunkArray

Splits an array into chunks of a specified size.

Parameters:

  • array: The array to split.
  • size: The size of each chunk.

Returns:

  • T[][]: The array split into chunks.
import { ChunkArray } from "@/index";

console.log(ChunkArray([1, 2, 3, 4, 5], 2)); // [[1, 2], [3, 4], [5]]

DeepClone

Creates a deep clone of the given object.

Parameters:

  • obj: The object to clone.

Returns:

  • T: The deep-cloned object.
import { DeepClone } from "@/index";

const input = { a: 1, b: { c: 2 } };
const output = DeepClone(input);
console.log(output); // { a: 1, b: { c: 2 } }
console.log(output !== input); // true

DeepMerge

Merges two objects deeply.

Parameters:

  • obj1: The first object.
  • obj2: The second object.

Returns:

  • T: The merged object.
import { DeepMerge } from "@/index";

const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { b: { d: 3 }, e: 4 };
console.log(DeepMerge(obj1, obj2)); // { a: 1, b: { c: 2, d: 3 }, e: 4 }

GroupBy

Groups an array of objects by a specified property.

Parameters:

  • array: The array to group.
  • key: The property to group by.

Returns:

  • Record<string, T[]>: The grouped object.
import { GroupBy } from "@/index";

const input = [{ category: "A" }, { category: "B" }, { category: "A" }];
console.log(GroupBy(input, "category")); 
// { A: [{ category: "A" }, { category: "A" }], B: [{ category: "B" }] }

Sleep

Pauses execution for a specified duration.

Parameters:

  • ms: The duration to sleep in milliseconds.

Returns:

  • Promise<void>: A promise that resolves after the specified duration.
import { Sleep } from "@/index";

const start = Date.now();
await Sleep(100);
const end = Date.now();
console.log(end - start >= 100); // true

Capitalize

Capitalizes the first letter of the given string.

Parameters:

  • value: The string to capitalize.

Returns:

  • string: The capitalized string.
import { Capitalize } from "@/index";

console.log(Capitalize("hello")); // "Hello"
console.log(Capitalize("Hello")); // "Hello"
console.log(Capitalize("hELLO")); // "HELLO"
console.log(Capitalize("")); // ""

Debounce

Creates a debounced function that delays invoking the provided function until after the specified wait time has elapsed since the last time the debounced function was invoked.

Parameters:

  • func: The function to debounce.
  • wait: The number of milliseconds to delay.

Returns:

  • Function: The debounced function.
import { Debounce } from "@/index";

let counter = 0;
const increment = () => {
  counter++;
};
const debouncedIncrement = Debounce(increment, 100);

debouncedIncrement();
debouncedIncrement();
debouncedIncrement();

setTimeout(() => {
  console.log(counter); // 1
}, 150);

FlattenedValue

Gets the value of a nested property in an object using a dot-separated path.

Parameters:

  • obj: The object to query.
  • separator: The separator used in the path.
  • path: The path of the property to get.

Returns:

  • T | undefined: The value of the nested property, or undefined if the property does not exist.
import { FlattenedValue } from "@/index";

const input = { a: { b: { c: 1 } }, d: 2 };
console.log(FlattenedValue<number>(input, '.', 'a.b.c')); // 1
console.log(FlattenedValue<number>(input, '.', 'd')); // 2
console.log(FlattenedValue<number>(input, '.', 'a.b')); // { c: 1 }
console.log(FlattenedValue<number>(input, '.', 'a.b.x')); // undefined

PickKeys

Selects specified keys from an object and returns a new object with only those keys.

Parameters:

  • obj: The object to pick keys from.
  • keys: An array of keys to pick.

Returns:

  • Partial<T>: A new object with only the specified keys.
import { PickKeys } from "@/index";

const input = { a: 1, b: 2, c: 3 };
const keys = ["a", "c"];
console.log(PickKeys(input, keys)); // { a: 1, c: 3 }