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

@canonical/utils

v0.17.1

Published

Standard utility functions for Canonical's Web Engineering team

Downloads

1,378

Readme

@canonical/utils

Utility functions for the Pragma design system. This package contains battle-tested helpers that have proven useful across multiple packages.

Installation

bun add @canonical/utils

Available Functions

debounce

Creates a debounced version of a function that waits until a specified delay has passed since the last call before executing. Useful for search inputs, resize handlers, and other high-frequency events.

import { debounce } from "@canonical/utils";

const debouncedSearch = debounce(async (query: string) => {
  const response = await fetch(`/api/search?q=${query}`);
  return response.json();
}, 300);

// Multiple rapid calls result in only one execution
await debouncedSearch("hello"); // Cancelled by next call
await debouncedSearch("hello w"); // Cancelled by next call
await debouncedSearch("hello world"); // Executes after 300ms

// Cancel a pending execution
const promise = debouncedSearch("query");
promise.cancel();

The debounced function returns a promise and includes a cancel method. Each new call cancels any pending execution from previous calls.

throttle

Throttles a function to execute at most once per specified interval. Useful for scroll handlers, continuous input events, and rate-limited operations.

import { throttle } from "@canonical/utils";

const throttledResize = throttle(() => {
  console.log("Window resized");
}, 500);

window.addEventListener("resize", throttledResize);
// Logs at most once every 500ms during continuous resizing

humanizeNumber

Formats numbers for human readability with appropriate suffixes and precision.

import { humanizeNumber } from "@canonical/utils";

humanizeNumber(1234); // "1.2K"
humanizeNumber(1234567); // "1.2M"

pluralize

Returns the singular or plural form of a word based on a count.

import { pluralize } from "@canonical/utils";

pluralize(1, "item", "items"); // "item"
pluralize(5, "item", "items"); // "items"

casing

Converts strings between different case conventions.

import { casing } from "@canonical/utils";

casing.toCamelCase("hello-world"); // "helloWorld"
casing.toKebabCase("helloWorld"); // "hello-world"

invariant

Throws an error if a condition is false. Useful for asserting assumptions in code.

import { invariant } from "@canonical/utils";

invariant(user != null, "User must be defined");
// TypeScript now knows user is not null

Design Philosophy

Functions only enter this package after proving useful across multiple packages. Premature abstraction is actively avoided. If a utility is only needed in one place, it belongs in that package until a second use case emerges.

Each function is fully typed with comprehensive JSDoc comments. The package has no runtime dependencies, keeping bundle impact minimal.