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

ts-handy-kit

v1.1.9

Published

A collection of useful TypeScript helper functions for string, date/time manipulation, accessibility, and function utilities.

Readme

ts-handy-kit

A collection of useful TypeScript helper functions for string, date/time manipulation, accessibility, and function utilities.

Installation

npm install ts-handy-kit

Usage

Import the helpers you need:

import {
  capitalizeFirstLetter,
  dateToISO,
  getDateString,
  getTimeString,
  debounce,
  throttle,
  convertTimeZone,
  copyToClipboard,
  dateDifference,
  timeDifference,
  isFalsy,
  retry,
  scrollToTop,
  getCurrentDateISO,
  getCurrentTimeString,
  isValidDate
} from 'ts-handy-kit';

// Capitalize the first letter of a string
console.log(capitalizeFirstLetter('hello world')); // "Hello world"

// Convert date/time to ISO string
console.log(dateToISO('2024-06-01T12:34:56Z')); // "2024-06-01T12:34:56.000Z"

// Get only the date part
console.log(getDateString('2024-06-01T12:34:56Z')); // "2024-06-01"

// Get only the time part
console.log(getTimeString('2024-06-01T12:34:56Z')); // "12:34:56"

// Convert time to another time zone (three-letter code: UTC, EST, IST, etc.)
console.log(convertTimeZone('2024-06-01T12:00:00Z', 'IST')); // e.g. "2024-06-01T17:30:00.000Z"
console.log(convertTimeZone('2024-06-01T12:00:00Z', 'EST')); // e.g. "2024-06-01T08:00:00.000Z"

// Copy to clipboard (browser only)
copyToClipboard('Copied text!').then(success => console.log(success));

// Difference in dates (days)
console.log(dateDifference('2024-06-01', '2024-06-03')); // 2

// Difference in time (milliseconds)
console.log(timeDifference('2024-06-01T10:00:00Z', '2024-06-01T10:00:01Z')); // 1000

// Check for falsy values
console.log(isFalsy(0)); // true
console.log(isFalsy('hello')); // false

// Retry an async function
retry(async () => {
  // your async logic
}, 3).then(result => console.log(result)).catch(err => console.error(err));

// Scroll to top (browser only)
scrollToTop();

// Get current date and time
console.log(getCurrentDateISO()); // e.g. "2024-06-01"
console.log(getCurrentTimeString()); // e.g. "12:34:56"

// Check if a date string is valid
console.log(isValidDate('2024-06-01')); // true
console.log(isValidDate('invalid-date')); // false

Helpers

capitalizeFirstLetter(str: unknown): string
    Capitalizes the first letter of a string. Returns an empty string for invalid input.

dateToISO(input: unknown): string
    Converts a date/time input to an ISO string. Returns an empty string for invalid input.

getDateString(input: unknown): string
    Returns the date part (YYYY-MM-DD) from a date/time input. Returns an empty string for invalid input.

getTimeString(input: unknown): string
    Returns the time part (HH:mm:ss) from a date/time input. Returns an empty string for invalid input.

debounce(fn, wait): Function
    Returns a debounced version of the function that delays execution until after `wait` milliseconds have elapsed since the last call.

throttle(fn, wait): Function
    Returns a throttled version of the function that only executes once per `wait` milliseconds.

convertTimeZone(dateStr, zone): string
    Converts a date/time string to a specified three-letter time zone code (`UTC`, `EST`, `IST`, etc.).

copyToClipboard(text): Promise<boolean>
    Copies a string to the clipboard (browser only).

dateDifference(date1, date2): number
    Returns the difference in days between two dates.

timeDifference(time1, time2): number
    Returns the difference in milliseconds between two times.

isFalsy(value): boolean
    Checks if a value is falsy in JavaScript.

retry(fn, retries): Promise<any>
    Retries an async function a specified number of times.

scrollToTop(): void
    Scrolls the window to the top (browser only).

getCurrentDateISO(): string
    Returns the current date in ISO format (YYYY-MM-DD).

getCurrentTimeString(): string
    Returns the current time in HH:mm:ss format.

isValidDate(dateStr): boolean
    Checks if a date string is valid.

--- Accessibility & ARIA Helpers ---

ariaPropTypes: string[]
    List of valid ARIA attribute names.

isAriaDisabled(props: { 'aria-disabled'?: boolean | string }): boolean
    Checks if ARIA disabled is set in props.

getAriaProps(props: Record<string, any>): Record<string, any>
    Returns only ARIA props from an object.

getAriaRole(props: Record<string, any>): string | undefined
    Returns the ARIA role from props.

createAriaAttributes(config: Record<string, any>): Record<string, any>
    Creates ARIA attributes from a config object.

generateId(prefix?: string): string
    Generates a unique ID for ARIA attributes.

visuallyHiddenStyle: React.CSSProperties
    CSS style for visually hidden elements.

getActiveElement(): Element | null
    Returns the currently active (focused) element in the document.

isActiveElementFocusable(): boolean
    Checks if the currently active element is focusable.

Contributing

Feel free to open issues or submit pull requests for new helpers or improvements!

License

ISC