@splitlab/core
v0.8.0
Published
Shared evaluation engine for SplitLab SDKs — hashing, targeting, bucketing
Downloads
244
Readme
@splitlab/core
Shared evaluation engine for SplitLab SDKs. Pure functions, zero dependencies.
What's in here
localEvaluate()— evaluate all experiments and flags for a user in < 1msevaluateRules()— targeting rule engine (supportsis,contains,gt,in, segments, etc.)- Deterministic hashing — consistent experiment bucketing and flag rollout
parseUserAgent()— lightweight UA parser (browser, OS, device type)- Types — shared TypeScript types used across all SDKs (
ExperimentConfig,FlagConfig,ServerConfig,EvalResult, etc.)
Installation
npm install @splitlab/coreUsage
import { localEvaluate } from '@splitlab/core';
import type { ServerConfig, EvalResult } from '@splitlab/core';
// Evaluate all experiments and flags locally
const config: ServerConfig = await fetchConfigFromServer();
const result: EvalResult = localEvaluate(config, 'user-123', { country: 'US' });
console.log(result.experiments); // { 'checkout-btn': 'variant_a' }
console.log(result.flags); // { 'dark-mode': true }Targeting Rules
The rule engine supports nested conditions with all/any matching:
import { evaluateRules } from '@splitlab/core';
const rules = {
match: 'all',
groups: [{
conditions: [
{ attribute: 'country', operator: 'is', value: 'US' },
{ attribute: 'plan', operator: 'in', value: ['pro', 'enterprise'] },
],
}],
};
evaluateRules(rules, { country: 'US', plan: 'pro' }, []);
// → trueOperators: is, is_not, contains, not_contains, gt, lt, gte, lte, in, not_in.
Building
npm run build # ESM + CJS + types → dist/
npm run dev # Watch modeAll evaluation logic lives here so that browser, server, and React SDKs produce identical results.
