@lacspace/flags
Feature flags & A/B experiments with no SaaS and no infrastructure — deterministic percentage rollouts, targeting segments, weighted variants, kill switches and per-user QA overrides, with an explain() that tells you why each flag resolved. Synchronous, zero-dependency, isomorphic.
npm i @lacspace/flagsUsage
import { Flags } from "@lacspace/flags";
// Config — load from JSON / env / DB, hot-swap with flags.update(...)
export const flags = new Flags({
"new-dashboard": { rollout: 25 }, // 25% of users
"beta": { rules: [{ when: { plan: "pro" }, value: true }] }, // pro users only
"eu-feature": { rules: [{ when: { country: { in: ["DE", "FR"] } }, value: true }] },
"checkout-exp": { // A/B test
type: "variant",
variants: [{ key: "control", weight: 1 }, { key: "one-click", weight: 1 }],
},
});
// Evaluate — synchronous, stable per user
flags.isEnabled("new-dashboard", { key: user.id }); // boolean
flags.isEnabled("beta", { key: user.id, attributes: { plan: user.plan } });
flags.variant("checkout-exp", { key: user.id }); // "control" | "one-click"Exports 5
FlagsbucketisEnabledpercentagevariantKeywords
More in App & Utils Kit
A tiny in-memory cache — LRU/LFU eviction, per-entry TTL, stale-while-revalidate, tag invalidation and hit/miss stats, plus wrap()/getOrSet()/memoize() to cache any async function with single-flight de-duplication. Zero-dependency, isomorphic.
@lacspace/caseConvert strings between cases — camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, Title/Sentence/Header/Capital Case and more, with a unicode-aware word splitter, an opt-in acronym registry, and is<Case> detectors. Zero-dependency, isomorphic.
@lacspace/colorParse, convert, manipulate and check colours — hex/rgb/hsl/hsv/oklch plus 148 CSS names, lighten/darken/mix/invert/complement, tints/shades & colour-wheel harmonies, and WCAG contrast for accessible UIs. Zero-dependency, isomorphic.
@lacspace/envTyped, validated environment variables — declare a schema, validate at boot, get a typed frozen object or one clear aggregated error. Coercers for ports, URLs, durations, byte sizes, lists & enums, ${VAR} expansion, secret-redacted errors and non-throwing safe-parse. A zero-dependency t3-env / envalid alternative.
@lacspace/formEnd-to-end form handling — turn FormData into typed, validated, spam-guarded data on the server (Next.js Server Actions), and manage interactive form state on the client (values/errors/touched/dirty, sync+async validation, nested paths, field arrays). One framework-free, zero-dependency package.
@lacspace/humanizeTurn machine values into human-readable text — bytes, durations, relative time, ordinals, plurals, compact numbers, grammatical lists, number-to-words, Roman numerals and SI units. Zero-dependency, isomorphic — one typed package instead of a pile of tiny formatting libs.