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

handy-utils-ts

v1.0.1

Published

A lightweight utility library with handy string, number and array helpers.

Readme


A lightweight and handy TypeScript utility library for working with strings, numbers, arrays, and other common operations.

Supports both modular usage and global prototype extension, giving you flexibility in how you integrate it into your project.


📦 Installation

# npm
npm install handy-utils-ts

# pnpm
pnpm install handy-utils-ts

# yarn
yarn add handy-utils-ts

📚 Table of Contents


🔧 Usage

Standard (Modular) Usage

You can import utilities individually for better tree-shaking and clarity:

import { capitalize } from "handy-utils-ts/str";
import { clamp } from "handy-utils-ts/num";
import { unique } from "handy-utils-ts/arr";

console.log(capitalize("hello world")); // Hello world
console.log(clamp(10, 0, 5)); // 5
console.log(unique([1, 2, 2, 3])); // [1, 2, 3]

Global Usage via tsconfig

If you prefer using utilities directly on native types (like "hello".$capitalize()), you can enable global augmentation.

Step 1: Update tsconfig.json

{
  "compilerOptions": {
    "types": ["handy-utils-ts/global"]
  }
}

Step 2: Use Globally Augmented Methods

const name = "john doe";
console.log(name.$capitalize()); // John doe

const nums = [1, 2, 2, 3];
console.log(nums.$unique()); // [1, 2, 3]

const score = 110;
console.log(score.$clamp(0, 100)); // 100

⚠️ Prototype methods are prefixed with $ to avoid conflicts with native methods.


🧰 Features

String Utilities

  • capitalize(str)

  • camelCase(str)

  • kebabCase(str)

  • snakeCase(str)

  • truncate(str, length)

  • Global equivalents:

    • "example".$capitalize()
    • "some text".$camelCase()

Number Utilities

  • clamp(num, min, max)

  • isEven(num)

  • isOdd(num)

  • random(min, max)

  • Global equivalents:

    • 42.$isEven()
    • 100.$clamp(0, 50)

Array Utilities

  • unique(arr)

  • chunk(arr, size)

  • flatten(arr)

  • compact(arr)

  • Global equivalents:

    • [1, 2, 2].$unique()
    • [1, [2, 3]].$flatten()

Miscellaneous

  • sleep(ms)
  • deepClone(obj)
  • isEmpty(value)
  • debounce(fn, delay)
  • throttle(fn, delay)

⚙️ Configuration for Global Usage

Global augmentation is opt-in and non-invasive, designed for ergonomics without affecting native behavior.

TypeScript Compatibility

Global methods are added through module augmentation and are fully typed. You get autocomplete and type safety for:

  • string.$capitalize()
  • number.$clamp(...)
  • array.$unique()

Example tsconfig snippet

{
  "compilerOptions": {
    "types": ["handy-utils-ts/global"],
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "Node"
  }
}

🧪 Testing

This library is tested with modern TypeScript and includes comprehensive unit tests.

You can run tests using:

npm test

🛠️ Contributing

Contributions are welcome! Whether it's a bug fix, new utility, or improvement. All PRs are appreciated.

Steps to Contribute

  1. Fork the repository

  2. Clone your fork locally:

    git clone https://github.com/YOUR_USERNAME/handy-utils-ts.git
  3. Create a new branch for your feature or fix:

    git checkout -b feature/my-awesome-feature
  4. Write tests for any new functions

  5. Commit your changes:

    git commit -m "Add: my-awesome-feature"
  6. Push to your fork:

    git push origin feature/my-awesome-feature
  7. Open a Pull Request on the main repo

Guidelines

  • Keep functions atomic and reusable
  • Use TypeScript and type definitions
  • Add unit tests for every new utility
  • Maintain naming conventions ($ prefix for globals)

Thank you for helping make this project better! 🚀


📄 License

MIT © 2025 [Olushola (GeekyGeeky)]