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

@variantlabs/js

v0.2.0-alpha.2

Published

VariantLabs browser SDK

Readme

@variantlabs/js

npm license

Browser SDK for VariantLabs — feature flags, experiments, and AI config, with deterministic assignment and built-in telemetry.

Using React? @variantlabs/react wraps this package in a provider and hooks.

Install

npm install @variantlabs/js

Quickstart

import { initVariantLabs } from "@variantlabs/js"

const vl = initVariantLabs({
  apiKey: "pk_live_...",
  appKey: "web",
  environmentKey: "production",
})

await vl.init()

const { value, variantKey } = await vl.get("checkout-button-color")
document.querySelector("#buy")!.style.background = value as string

// Later — report what happened.
vl.trackOutcome({ assignmentId: ..., outcomeKey: "purchase", success: true })

init() resolves once configs are available. It hydrates synchronously from localStorage first, so a returning visitor gets their assignment without waiting on the network.

Identity

You don't have to supply a subject key. On first visit the SDK generates and persists an anonymous ID in localStorage, plus a per-tab session ID in sessionStorage. Both are attached to every evaluation automatically.

// Anonymous — uses the generated persistent ID.
await vl.get("homepage-hero")

// Identified — pass your own key once the user logs in.
await vl.get("homepage-hero", { subjectKey: user.id })

Because assignment is a pure hash of the subject key, the same user gets the same variant on every device and every page load. Set persistAnonymousId: false to opt out of storage entirely.

Measuring outcomes

withAssignment is the ergonomic path — it evaluates, runs your code, and records duration plus success/failure in one step.

const summary = await vl.withAssignment(
  "summarizer-model",
  { subjectKey: user.id },
  async (assignment) => callModel(assignment.value),
  { outcomeKey: "summary_generated" },
)

Or track manually when the outcome arrives later:

const assignment = await vl.get("checkout-flow", { subjectKey: user.id })

// ...user completes checkout minutes later...
vl.trackOutcome({
  assignmentId: assignment.assignmentId,
  outcomeKey: "purchase",
  success: true,
  numericValue: order.total,
})

Options

initVariantLabs({
  apiKey: "pk_live_...",          // required
  appKey: "web",                  // required
  environmentKey: "production",   // required
  baseUrl: "https://api.variantlabs.io",

  persistAnonymousId: true,       // localStorage anon ID (default: true)
  configCacheTtlMs: 60_000,       // how long a cached config stays fresh

  defaultAttributes: { tier: "pro" },   // merged into every evaluation
  serviceName: "storefront",
  serviceVersion: "2.1.0",

  emitter: { maxBatchSize: 50, flushIntervalMs: 5_000 },
  logger: myLogger,
  fetchImpl: myFetch,             // injectable for tests
})

Flushing

Events are batched and flushed on an interval. The SDK also flushes automatically when the page is hidden (visibilitychange) and on beforeunload, so you rarely need to intervene.

await vl.flush()      // force a flush now
await vl.shutdown()   // final flush, then stop

Delivery is lossy by design — a full queue drops events and a permanently failing batch is discarded. Telemetry never blocks or crashes your page.

OpenFeature

Ships a synchronous OpenFeature web provider.

import { OpenFeature } from "@openfeature/web-sdk"
import { initVariantLabs } from "@variantlabs/js"
import { VariantLabsWebProvider } from "@variantlabs/js/openfeature"

const vl = initVariantLabs({ apiKey, appKey: "web", environmentKey: "production" })
await OpenFeature.setProviderAndWait(new VariantLabsWebProvider(vl))

const client = OpenFeature.getClient()
const enabled = client.getBooleanValue("new-checkout", false)  // synchronous

@openfeature/web-sdk is an optional peer dependency — install it only if you use the provider.

Caching and first render

Config is cached in localStorage under vl:config_cache:v1:{appKey}:{environmentKey} and read synchronously at startup. That means the first render already has the right variant, with no flash of the default.

A fresh cache short-circuits the network entirely, so init() can resolve without a request.

API

| | | | --- | --- | | initVariantLabs(options) | Create a client | | client.init() | Load config; resolves when ready | | client.get(key, ctx?) | Evaluate → Promise<AssignmentResult> | | client.withAssignment(key, ctx, fn, opts?) | Evaluate, run, auto-track the outcome | | client.trackOutcome(input) | Record an outcome | | client.flush(opts?) / client.shutdown(opts?) | Delivery control | | client.getContext() | Resolved SDK context |

Core types (AssignmentResult, EvaluationContext, TrackOutcomeInput, …) plus fromHeaders and sanitizeAttributes are re-exported, so you only ever import from this package.

Compatibility

Node >= 22 for tooling; any browser with global fetch at runtime. Ships ESM + CJS + type declarations. All storage access is SSR-safe — importing this package in a server render won't touch window.

License

Apache-2.0