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 🙏

© 2026 – Pkg Stats / Ryan Hefner

utils-core

v1.0.11

Published

This package offers a comprehensive collection of widely-used utility functions for both JavaScript and TypeScript projects, designed to streamline development

Readme

Core Utility Functions for Javascript and Typescript.(Node.js and React.js)

This package offers a comprehensive collection of widely-used utility functions for both JavaScript and TypeScript projects, designed to streamline development

Usage

First install the package via npm:

$ npm install utils-core --save

To use the package in your module:

import { randomString } from "utils-core";

const randomSring = randomString(8);
const { randomString } = require("utils-core");

const randomSring = randomString(8);

Features

| Name | Description | Ex.Input | Ex.Output | | ------------- | ------------- | ------------- | ------------- | | uniqueArray(array) | Removes duplicates from an array. | [1, 2, 2, 3, 4, 4, 5] | [1, 2, 3, 4, 5] | | uniqueArrayByKey(arr: T[], key: keyof T) | Returns a new array with unique objects based on a specified key property | (arr: T[], key: keyof T) => T[] | uniqueArrayByKey([{id:1},{id:1},{id:2}], 'id') → [{id:1},{id:2}] | | deepUniqueArray(arr, compareFn?) | Removes duplicate items from an array using deep comparison or custom compare function | (arr: T[], compareFn?: (a: T, b: T) => boolean) => T[] | deepUniqueArray([{a:1}, {a:1}, {a:2}]) → [{a:1}, {a:2}] | | shuffleArray(array) | Shuffles the elements of an array randomly. | [1, 2, 3, 4, 5] | [3, 1, 5, 2, 4] | | flattenArray(array) | Flattens a nested array to a single-level array. | [[1, 2], [3, [4, 5]], 6] | [1, 2, 3, 4, 5, 6] | | sleep(ms: number) | Delays execution for a specified number of milliseconds. Returns a Promise. | 2000 | Resolves after 2 seconds. | | formatBytes(bytes: number, decimals: number) | Converts bytes into a human-readable format (e.g., KB, MB). | formatBytes(5000, 2) | "4.88 KB" | | hexToRgb(hex: string) | Converts a hex color code to RGB. | #ffffff | { r: 255, g: 255, b: 255 } | | formatDate(date: Date) | Formats a Date object to YYYY-MM-DD string. | new Date('2023-10-05') | '2023-10-05' | | copyToClipboard(text: string) | Copies the provided text to the clipboard. (for frontend) | "Hello, World!" | Copied | | scrollToTop() | Smoothly scrolls the page to the top (for frontend) | void | Scrolls to the top of the page | | getFileExtension(filename: string) | Extracts the file extension from a given filename. | example.js | "js" | | getDecimalFormating(num: number | undefined | string, isDecimal: boolean - default true) | Formats a number into a decimal string with optional decimal places. | getDecimalFormating(1234.567, true) | "1,234.57" | | parseJSON(str: string) | Parses a JSON string. Returns the parsed object or the original string if parsing fails. | '{"name": "John", "age": 30}' | { name: 'John', age: 30 } | | randomString(length: Integer) | Generates a random alphanumeric string of a specified length. | 5 | "a1b2c" | | truncateString(str: string, length: number) | Truncates a string to a specified length and appends "..." if necessary. | truncateString("Hello, world!", 5) | "Hello..." | | capitalize(str: string) | Capitalizes the first character of a string. Returns empty if input is falsy. | "hello" | "Hello" | | capitalizeName(name: string) | Returns the initials of a name in uppercase. | "john doe" | "JD" | | capitalizeWords(str: string, splitLetter: string) | Capitalizes the first letter of each word in a string based on a delimiter. | capitalizeName("date_available", _) | "Date Available" | | isObject(value) | Checks if the value is an object (not an array). | { key: 'value' } | true | | isArray(value) | Checks if a value is an array. | [1, 2, 3] | true | | isFunction(value) | Checks if the provided value is a function. | function | true | | isString(value) | Checks if the provided value is of type string. | "hello" | true | | isNumber(value) | Checks if the provided value is a valid number. | 42 | true | | isEmpty(value) | Checks if a value is an empty object or array. Returns true if the value is an empty object or array, otherwise false. | {} | true | | isEmptyObject(value: object) | Checks if an object is empty (has no keys). | {} | true | | objectToQueryString(obj: Record<string, any>) | Converts an object into a URL-encoded query string. | obj: Record<string, any> | string | | deepObjectToQueryString(obj: any, prefix: string) | Converts a nested object into a URL-encoded query string. | deepObjectToQueryString(obj, "") | string | | shortenAddress(address: string) | Shortens a wallet address by showing first 5 and last 5 characters with ellipsis in between | (address: string | undefined) => string | shortenAddress("0x71C7656EC7ab88b098defB751B7401B5f6d8976F") → "0x71C...8976F" | | convertDecToHex(num: number) | Converts a decimal number to its hexadecimal string representation | (num: number) => string | convertDecToHex(255) → "ff" | | convertHexToDec(str: string or number) | Converts a hexadecimal string or number to its decimal equivalent | (str: string | number) => number | convertHexToDec("0x1a") → 26 | | convertNumberToCurrency(num: number, locales?, currency?) | Converts a number to currency format using Intl.NumberFormat | (num: number, locales = "en-US", currency = "USD") => string | convertNumberToCurrency(1234.56) → "$1,234.56" | | safeCall(fn, ...fallbacks) | Safely attempts to execute a function, falling back to subsequent functions if errors occur | (fn: () => T, ...fallbacks: Array<() => T>) => T | safeCall(() => throw Error(), () => 42) → 42 | | safeCallT(fn, ...fallbacks) | Safely executes a function, falling back to alternative functions if it throws | (fn: () => T, ...fallbacks: Array<() => T>) => T | safeCallT(() => mightThrow(), () => fallbackValue) → returns result or fallback | | noop() | A no-operation function that does nothing and returns void | () => void | noop() → (void) |