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

@lp-labs/experiment-assignment

v0.1.0

Published

Bounded deterministic experiment-assignment utilities with explicit validation and zero runtime dependencies.

Readme

@lp-labs/experiment-assignment

Deterministic versioned experiment buckets, explicit exclusions, bounded allocation and variant weights. Original independent implementation, zero runtime/peer dependencies. Node >=18, version 0.1.0. Assignment does not provide statistical or causal guarantees.

npm install @lp-labs/experiment-assignment

Runnable example

import { createExperimentAssigner, assignmentBucket } from '@lp-labs/experiment-assignment';

const assigner = createExperimentAssigner({
  key: 'checkout',
  version: '1',
  allocation: 10000,
  variants: [
    { key: 'control', weight: 5000 },
    { key: 'treatment', weight: 5000 },
  ],
  excludedSubjects: ['staff'],
});
const assignment = assigner.assign('customer-1');
if (assignment.reason !== 'assigned' || assigner.assign('staff').variant !== null)
  throw new Error('Unexpected assignment');
console.log(assignment, assignmentBucket('customer-1', 'checkout', '1'));

CommonJS: require('@lp-labs/experiment-assignment'). ESM/CommonJS runtime exports are identical, with separate matching declarations.

API and types

  • VariantAllocation: { key: string; weight: number }, positive integer basis points.
  • ExperimentDefinition: key, explicit version, allocation (integer basis points 0–10000), variants (ordered array, weights sum exactly 10000), optional excludedSubjects (string array, duplicate exclusions are harmless).
  • Assignment: experiment, version, bucket (integer 0–9999), variant (variant key or null), reason: 'assigned' | 'excluded' | 'unallocated'.
  • createExperimentAssigner(definition: ExperimentDefinition): ExperimentAssigner: validate/copy a fixed configuration, no retained request or random state.
  • ExperimentAssigner.assign(subject: string): Assignment: excludes configured subjects first, then requires bucket < allocation; variant weights partition the allocated interval in input order. First cumulative weight satisfying bucket * 10000 < cumulativeWeight * allocation wins. Integer arithmetic avoids rounding boundaries; small allocations may leave a variant with zero reachable buckets. Returns a fresh result on each call, regardless of request ordering.
  • assignmentBucket(subject, experiment, version): number: FNV-1a uint32 over UTF-16 code units of length-prefixed ['assignment-v1', experiment, version, subject]; concatenate ${part.length}:${part}, initial 2166136261, multiplier 16777619, modulo 10000. The algorithm marker is fixed independently of your explicit version.

Four named interfaces (VariantAllocation, ExperimentDefinition, Assignment, ExperimentAssigner) are exported types; the factory and hash are runtime exports.

Errors, customization and limits

TypeError: empty/nonstrings/over-128-UTF-16-unit identifiers (including subject/version), duplicate variant keys. RangeError: noninteger/out-of-range allocation or weights, weight sum !=10000, zero or >100 variants, nonarray variants/exclusions, >100000 exclusions. Configuration is validated before any assigner is returned; no partial state or external input mutation. Ordinary trusted config data is required; iterator/getter failures propagate.

Customize version, experiment namespace, variant order/weights, allocation, exclusions, and subject normalization upstream. Increasing allocation preserves admission, but can change variants, since variant intervals scale with allocation. Changing weights, order, version, or key can also reassign subjects. Fixed configuration gives stable assignment; there is no persisted sticky state or cross-experiment mutual exclusion.

Modulo bias and hash collisions exist; hash is not cryptographic and client-chosen subjects are manipulable. No authentication/authorization boundary, privacy protection, exposure logging, statistical significance, power analysis, population balance, causal inference, or experiment-outcome guarantee. Exclusion lists are explicit inputs, not verified eligibility.

Factory cost/storage O(V + X); assignment O(subject length + V), with O(1) exclusion lookup on average. V <=100, X <=100000. Output does not expose exclusion lists. Related design context: virtual-time determinism, performance-budgets honest limitations, incremental-aggregation snapshots, unit-system explicit numeric semantics. No imports shared.

Development

npm run build, npm run typecheck, npm test, npm run format, npm run format:check. TypeScript ^5.9.3 and Prettier ^3.6.2 dev-only; strict ESM/CommonJS declarations. Tests cover seeded independent bucket oracles, integer allocation boundaries, exclusions, reordered requests, mutation races and full interval partition checks.

Support

If this library is useful to you, consider supporting its maintenance with a donation via PayPal.

Author

Created by Libin Prasanth. Connect on LinkedIn for updates and discussion.