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

@dif.sh/svelte

v0.5.0

Published

Svelte 5 adapter for @dif.sh/sdk — SSR-safe assignment, a server load helper, and exposure stores.

Readme

@dif.sh/svelte

Svelte 5 + SvelteKit adapter for @dif.sh/sdk.

It does the SSR-safe parts for you:

  • Server assignmentdifLoad() mints a stable anonymous dif_uid cookie, derives audience attributes from request headers, and assigns every registered experiment with the SDK's pure assigner (no exposure firing, no shared state).
  • No flicker — the client reuses the server's decision and the same dif_uid, so the first client render matches SSR.
  • Client-only exposures — the experiment() store fires exactly one exposure on the client, never on the server.
npm i @dif.sh/sdk @dif.sh/svelte

Usage

src/routes/+layout.server.ts — assign on the server:

import "$lib/dif/generated/client"; // side effect: registers active experiments
import { difLoad } from "@dif.sh/svelte/server";

export const load = (event) => ({ dif: difLoad(event) });

src/routes/+layout.svelte — init the SDK once and publish the data to context:

<script lang="ts">
  import { setContext } from "svelte";
  import { initDif, DIF_CONTEXT_KEY } from "@dif.sh/svelte";
  import { PUBLIC_DIF_PUBLISHABLE_KEY, PUBLIC_DIF_CLOUD_URL } from "$env/static/public";

  let { data, children } = $props();
  setContext(DIF_CONTEXT_KEY, data.dif);
  initDif({
    data: data.dif,
    publishableKey: PUBLIC_DIF_PUBLISHABLE_KEY,
    apiUrl: PUBLIC_DIF_CLOUD_URL, // https://cloud.dif.sh (or your own deployment)
  });
</script>

{@render children()}

Any component — read an experiment as a store:

<script lang="ts">
  import { experiment, track } from "@dif.sh/svelte";
  const cta = experiment("insights-cta-copy", {
    control: () => "Read more",
    variant_a: () => "Get the full breakdown",
  });
</script>

<a onclick={() => track("insights_cta_click")}>{$cta.value}</a>

ISR note

On an ISR-cached route the server load doesn't re-run per visitor, so the cached HTML is shared. There, experiment() falls back to assigning on the client from the dif_uid cookie — the server renders the control branch and the client swaps once after hydration. Don't server-assign on an ISR route unless you also vary the cache key on the headers difLoad reads.

Preview & QA forcing

Anyone can force a variant by opening a ?_dif= link — no code, no devtools. initDif reads it automatically (both difLoad server-side and the client):

# force one experiment (persists for the tab session, then auto-clears)
https://staging.niftic.com/insights/foo?_dif=insights-cta-copy=variant_a
# multiple at once
…?_dif=insights-cta-copy=variant_a,home-hero=control
# clear
…?_dif=off
# generate the exact link from the CLI
npx dif qa --force insights-cta-copy=variant_a --preview-url https://staging.niftic.com/insights/foo

A small preview badge appears whenever a force is active (showing the experiment → variant and a one-click clear). A forced assignment never fires an exposure, so QA can't pollute results. The force is stored in a session _dif cookie (survives navigation, clears on tab close) and the param is stripped from the address bar. Works in production too — pass allowOverrides: false to initDif/difLoad to disable per-env, or preview: false to hide the badge.

API

  • difLoad(event, opts?)DifData — server load helper (@dif.sh/svelte/server).
  • attributesFromHeaders(headers)AttributeBag — default header mapping; override via opts.deriveAttributes.
  • initDif(opts) — client init; call once in the root layout. opts.allowOverrides / opts.preview (default true).
  • experiment(id, branches)Readable<{ value, variant }>.
  • track(metric, opts?) — fire a metric event.
  • DIF_CONTEXT_KEY — the context key for DifData.