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

utilyx

v1.0.11

Published

Modern utility helper library for cleaner, faster TypeScript/JavaScript development ๐Ÿš€๐Ÿ”ง

Readme

Utilyx

A comprehensive collection of utility functions for common JavaScript/TypeScript operations.

Installation

npm install utilyx

Usage

import { 
  timeAgo,
  getTimeDiff,
  formatDate,
  msToTime,
  toTitleCase,
  truncateText,
  randomUUID,
  slugify,  
  isEmail,
  isURL,
  camelToSnake,
  snakeToCamel,
  reverseString,
  countWords,
  isPalindrome,
  trimExtraSpaces,
  maskEmail,
  generateRandomString,
  generateTokenBase64,
  debounce,
  throttle,
  deepClone,
  deepEqual,
  shuffleArray,
  uniqueArray,
  copyToClipboard,
  localStorageUtils
 
} from 'utilyx';

Available Functions

Date Utilities

timeAgo(date: string): string

Converts a date to a human-readable "time ago" format.

timeAgo('2024-03-20T10:00:00Z') // Returns: "2 days ago"
timeAgo(new Date()) // Returns: "just now"

getTimeDiff(start: Date | string, end: Date | string)

Calculates the time difference between two dates.

getTimeDiff('2024-03-20', '2024-03-22') 
// Returns: { days: 2, hours: 0, mins: 0, secs: 0 }

formatDate(date: Date | string, format: string): string

Formats a date according to the specified format string.

formatDate(new Date(), 'YYYY-MM-DD') // Returns: "2024-03-22"

Conversion Utilities

msToTime(ms: number): string

Converts milliseconds to a human-readable time format.

msToTime(90061) // Returns: "1m 30s"

String Utilities

toTitleCase(str: string, lowercaseRest?: boolean): string

Converts a string to title case (capitalizes first letter of each word).

toTitleCase('hello world') // Returns: "Hello World"
toTitleCase('hElLo wOrLd', false) // Returns: "HElLo WOrLd"

camelToSnake(str: string, uppercase?: boolean): string

Converts camelCase to snake_case.

camelToSnake('myVarName') // Returns: "my_var_name"
camelToSnake('myVarName', true) // Returns: "MY_VAR_NAME"

snakeToCamel(str: string, pascal?: boolean): string

Converts snake_case to camelCase.

snakeToCamel('my_var_name') // Returns: "myVarName"
snakeToCamel('my_var_name', true) // Returns: "MyVarName"

slugify(str: string, separator?: string, preserveCase?: boolean): string

Generates a URL-friendly slug from a string.

slugify('Hello World!') // Returns: "hello-world"
slugify('Hello World!', '_', true) // Returns: "Hello_World"

truncateText(str: string, maxLength: number, ellipsis?: string, preserveWords?: boolean): string

Truncates text to a specified length and adds ellipsis.

truncateText('Hello World', 8) // Returns: "Hello..."
truncateText('Hello World', 8, '..', false) // Returns: "Hello wo.."

reverseString(str: string): string

Reverses a string.

reverseString('hello') // Returns: "olleh"

countWords(str: string): number

Counts words in a string (split by spaces).

countWords('Hello world') // Returns: 2
countWords('') // Returns: 0

isPalindrome(str: string, caseSensitive?: boolean, ignoreSpaces?: boolean): boolean

Checks if a string is a palindrome.

isPalindrome('Madam') // Returns: true
isPalindrome('A man a plan a canal Panama') // Returns: true
isPalindrome('Racecar', true) // Returns: false

trimExtraSpaces(str: string): string

Trims extra spaces between words.

trimExtraSpaces('Hello   world') // Returns: "Hello world"

maskEmail(email: string): string

Masks the local part of an email address.

maskEmail('[email protected]') // Returns: "us**@domain.com"

generateRandomString(length?: number, options?: object): string

Generates a random string with customizable options.

generateRandomString(8) // Returns: "A3b7GhK9"
generateRandomString(6, { includeNumbers: false }) // Returns: "aBcDef"

randomUUID(): string

Generates a random UUID (v4 style).

randomUUID() // Returns: "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"

generateTokenBase64(length?: number): string

Generates a cryptographically secure random token encoded in base64.

generateTokenBase64(16) // Returns: 'QkVmX1ZydXNvYkZBS3pWag==' (base64 string of 16 random bytes)

Validation Utilities

isEmail(str: string): boolean

Validates if a string is a valid email address.

isEmail('[email protected]') // Returns: true
isEmail('invalid-email') // Returns: false

isURL(str: string): boolean

Validates if a string is a valid URL.

isURL('https://example.com') // Returns: true
isURL('not-a-url') // Returns: false

Array Utilities

shuffleArray<T>(arr: T[]): T[]

Randomly shuffles the elements of an array.

const numbers = [1, 2, 3, 4, 5];
shuffleArray(numbers) // Returns: [3, 1, 5, 2, 4] (random order)

uniqueArray<T>(arr: T[]): T[]

Removes duplicate elements from an array.

const numbers = [1, 2, 2, 3, 3, 4];
uniqueArray(numbers) // Returns: [1, 2, 3, 4]

Function Utilities

debounce<T extends (...args: any[]) => void>(fn: T, delay: number)

Creates a debounced function that delays invoking the provided function until after the specified delay has elapsed.

const debouncedFn = debounce(() => console.log('debounced'), 1000);

throttle<T extends (...args: any[]) => void>(fn: T, delay: number)

Creates a throttled function that only invokes the provided function at most once per specified delay.

const throttledFn = throttle(() => console.log('throttled'), 1000);

Object Utilities

deepClone<T>(obj: T): T

Creates a deep clone of an object.

const original = { a: { b: 1 } };
const cloned = deepClone(original);

deepEqual(a: any, b: any): boolean

Performs a deep equality check between two values.

deepEqual({ a: 1, b: { c: 2 } }, { a: 1, b: { c: 2 } }) // Returns: true

Browser Utilities

copyToClipboard(str: string): Promise<void>

Copies a string to the clipboard.

await copyToClipboard('Hello World!') // Copies to clipboard

localStorageUtils

A collection of utilities for working with localStorage.

// Get value
localStorageUtils.get('key') // Returns: value or null

// Set value
localStorageUtils.set('key', { data: 'value' })

// Remove value
localStorageUtils.remove('key')

Development

# Install dependencies
npm install

# Build the library
npm run build

๐Ÿ’ฌ Why utilyx?

A modern utility toolkit that doesn't try to be lodash โ€” just the stuff you actually use, written clean, typed tight.

Built for creators, side-projects, frameworks, and startups who don't want to waste time reinventing functions again.


๐Ÿ”ฎ Coming Soon

  • ๐Ÿ“ฆ Native ESM build
  • ๐Ÿ’… React UI utils (buttons, modals, etc.)
  • ๐ŸŒ CDN-friendly version

๐Ÿค Contribute

Want to add your favorite utility?
Open an issue or pull request โ€” let's build this together ๐Ÿ’ช


License

MIT