GitShow/antfu/whenexpr
antfu

whenexpr

Tiny when-clause expression evaluator with full type-safty

by antfu
Star on GitHubForkWebsitenpm

TypeScript

33 stars0 forks1 contributorQuiet · 2mo agoSince 2026v0.1.2MIT

Meet the team

See all 1 on GitHub →
antfu
antfu7 contributions

Commit activity

Last 12 weeks · 7 commits

Full graph →

Community health

5 of 6 standards met

Community profile →
85
✓README✓License✓Contributing✓Code of Conduct○Issue Template✓PR Template

Recent fixes

View closed PRs →
antfu
feat: statically validate when-clause expressions against context typeMergedPR

Summary Parses the expression string inside the TypeScript type system, so unknown context keys and syntax errors surface at the call site instead of waiting for runtime. Inspired by prior art like codemix/ts-sql and ronami/HypeScript, adapted for whenexpr's VS Code-style grammar (including the RHS identifier-as-literal rule). Validation is layered — you pay only for what you need: Also exports so libraries can carry the static check into their own typed helpers (e.g. ). Changes New — type-level tokenizer, precedence-climbing parser, , , New — (flat + / nested) signature now validates via README "Type Safety" section + levels-of-checking table Type tests in (vitest typecheck mode enabled) Widened ctx in existing where unknown-key runtime behaviour is tested Test plan [x] — clean [x] — 150 tests, 0 type errors [x] — no issues [ ] Consumer smoke test: drop into a project, confirm tooltip errors for unknown keys 🤖 Generated with Claude Code

antfu · 2mo ago
antfu
feat: initial when-clause expression evaluatorMergedPR

Summary Implements — a tiny, zero-dependency evaluator for when-clause expressions, inspired by VS Code's when clause contexts. The pipeline is , with as a convenience wrapper that composes the two. The grammar is a JS-expression subset: literals (boolean/number/string), identifiers (namespaced with or ), unary / / , logical / , equality ( / VS Code-style stringy RHS, / JS strict on full expressions), relational (`>=+-*/%evaluateWhen{ strict: true }pnpm testparseevaluateevaluateWhenresolveContextValuepnpm typecheckpnpm lintpnpm buildevaluateWhen('(((a b) && c) + foo) === 1', { a: false, b: true, c: true, foo: 0 })true` 🤖 Generated with Claude Code

antfu · 2mo ago
Structured data for AI agents

Repository: antfu/whenexpr. Description: Tiny when-clause expression evaluator with full type-safty Stars: 33, Forks: 0. Primary language: TypeScript. License: MIT. Homepage: https://npmx.dev/package/whenexpr Latest release: v0.1.2 (2mo ago). Open PRs: 0, open issues: 0. Last activity: 2mo ago. Community health: 85%. Top contributors: antfu.

·@ofershap

Replace github.com with gitshow.dev