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

@sveltebase/utils

v2.0.1

Published

Small helpers for Svelte 5 apps: cookies, async actions with loading state, toasts, ids, delays, and simple plural formatting.

Readme

@sveltebase/utils

Small helpers for Svelte 5 apps: cookies, async actions with loading state, toasts, ids, delays, and simple plural formatting.

Install

bun add @sveltebase/utils

svelte is a peer dependency. For toast notifications from the async helpers, also install:

bun add svelte-sonner

Cookies

Browser-only helpers around document.cookie. On the server they are no-ops (get returns null).

import { Cookies } from "@sveltebase/utils";

Cookies.set("theme", "dark", {
  expires: 30, // days
  path: "/",
  sameSite: "Lax"
});

Cookies.get("theme");  // "dark" | null
Cookies.remove("theme");

Defaults when options are omitted: path: "/", sameSite: "Lax", and secure when the page is HTTPS. sameSite: "None" always sets secure.

remove accepts optional path and domain — use the same ones you used when setting the cookie.

Async actions

createAsync wraps an async function with reactive loading and error state.

import { createAsync } from "@sveltebase/utils";

const save = createAsync(async (name: string) => {
  const response = await fetch("/api/profile", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ name })
  });

  // Optional: return a toast message
  return response.ok
    ? { success: "Profile saved" }
    : { error: "Could not save profile" };
});

await save.run("Ahror");
save.isLoading(); // true while the request is in flight
save.error;       // last thrown Error, or null

Return values:

  • { success: "..." } — success toast (if svelte-sonner is available)
  • { error: "..." } — error toast; does not set save.error or reject
  • null / void — finishes quietly
  • thrown error — stored on save.error, shown as a toast, and rethrown

Multiple concurrent actions

Track loading per item with a key:

await save.runWithKey(rowId, "New name");
save.isLoading(rowId); // only that row
save.isLoading();      // the shared “global” key

One-off try/catch with toasts

import { tryCatch } from "@sveltebase/utils";

await tryCatch(async () => {
  const response = await fetch("/api/invite", { method: "POST" });
  return response.ok
    ? { success: "Invite sent" }
    : { error: "Could not send invite" };
});

Unlike createAsync, tryCatch swallows thrown errors (and still toasts them). Customize the toast:

await tryCatch(() => loadPrivateData(), {
  onError(error) {
    if (error instanceof SessionExpiredError) {
      return {
        message: "Your session has expired",
        description: "Sign in again to continue."
      };
    }
    // return null/undefined for the default message
  }
});

Toasts are browser-only and load lazily — SSR is fine, and you don’t need a <Toaster /> mounted at import time.

Other helpers

timestamps

timestamps(false); // { createdAt, updatedAt } — same millisecond
timestamps(true);  // { updatedAt }

wait

await wait(250); // resolves after 250ms

createId

const id = createId(); // UUID v4-style

Uses crypto.randomUUID() when available, then getRandomValues(), then a Math.random() fallback.

pluralize

pluralize(0, { zero: "No items", one: "item", other: "items" });
// "No items"

pluralize(1, { one: "item", other: "items" });
// "1 item"

pluralize(4, { one: "item", other: "items" });
// "4 items"

pluralize(3, { other: (n) => `${n} matches found` });
// "3 matches found"
  • zero — only when count is 0
  • one — only when count is 1 (prefixed with 1 )
  • other — everything else (string or function)

License

ISC