Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ matchigo émet un `console.warn` **une seule fois** quand il détecte un mésusa
- Reconstruire `rules` à chaque appel de `match(value, rules)` (l'anti-pattern « cold-path inline »).
- Créer des milliers d'instances distinctes de `matcher()` (typiquement, le builder est dans une boucle chaude).

Les avertissements sont pilotés par `NODE_ENV` (`production`/`prod` les désactive) ou par l'override explicite `MATCHIGO_DEV=0` / `MATCHIGO_DEV=1`. La vérification se fait une fois au chargement du module, donc **production a un coût nul** — pas de lecture d'env, pas de compteur, pas de formatage de string.
Les avertissements sont pilotés par `NODE_ENV` (`production`/`prod` les désactive). La vérification se fait une fois au chargement du module, donc **production a un coût nul** — pas de lecture d'env, pas de compteur, pas de formatage de string.

```ts
import { silenceWarnings } from "matchigo";
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ matchigo emits a `console.warn` **once** when it detects misuse that defeats cac
- Reconstructing `rules` on every `match(value, rules)` call (the "cold-path inline" anti-pattern).
- Creating thousands of distinct `matcher()` instances (usually means the builder is inside a hot loop).

Warnings are controlled by `NODE_ENV` (`production`/`prod` disables them) or the explicit `MATCHIGO_DEV=0` / `MATCHIGO_DEV=1` override. The check happens once at module load, so **production has zero cost** — no env reads, no counters, no string formatting.
Warnings are controlled by `NODE_ENV` (`production`/`prod` disables them). The check happens once at module load, so **production has zero cost** — no env reads, no counters, no string formatting.

```ts
import { silenceWarnings } from "matchigo";
Expand Down
21 changes: 14 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@
"keywords": [
"pattern-matching",
"match",
"rust",
"dispatch",
"compile",
"rule-engine",
"rules",
"typescript",
"type-safe",
"exhaustive",
"fast"
"narrowing",
"discriminated-union",
"switch",
"data-driven",
"fast",
"zero-dependency",
"rust-like",
"bun",
"node"
],
"license": "MIT",
"author": "SUP2Ak",
Expand All @@ -24,13 +36,8 @@
},
"files": [
"dist",
"src",
"README.md",
"README.fr.md",
"FAQ.md",
"FAQ.fr.md",
"CONTRIBUTING.md",
"CONTRIBUTING.fr.md",
"LICENSE"
],
"sideEffects": false,
Expand Down
12 changes: 4 additions & 8 deletions src/dev.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Dev-only cold-path instrumentation.
// Resolution policy (evaluated ONCE at module load → zero runtime cost):
//
// 1. MATCHIGO_DEV env var wins — accepts "0"|"false" (off) or "1"|"true" (on).
// 2. Else NODE_ENV — matches "production", "prod" (case-insensitive) → off.
// 3. Else default → on (verbose dev).
// 1. NODE_ENV — matches "production", "prod" (case-insensitive) → off.
// 2. Else default → on (verbose dev).
//
// Programmatic override: silenceWarnings() at startup mutes everything.
// No NODE_ENV at all? Dev mode is ON. The counters still cost only a few `++`
Expand All @@ -12,9 +11,6 @@
const DEV: boolean = (() => {
try {
if (typeof process === "undefined" || !process?.env) return true;
const explicit = process.env.MATCHIGO_DEV;
if (explicit === "0" || explicit === "false") return false;
if (explicit === "1" || explicit === "true") return true;
const node = (process.env.NODE_ENV ?? "").toLowerCase();
if (node === "production" || node === "prod") return false;
return true;
Expand Down Expand Up @@ -48,7 +44,7 @@ export function trackMatch(cacheHit: boolean): void {
` • Or compile once with compile():\n` +
` const dispatch = compile([...]);\n` +
` dispatch(value);\n` +
` Silence: silenceWarnings() — or set MATCHIGO_DEV=0.`,
` Silence: silenceWarnings() — or set NODE_ENV=production.`,
);
warnedMatch = true;
}
Expand All @@ -65,7 +61,7 @@ export function trackMatcher(): void {
` .with(...)\n` +
` .otherwise(...); // builds + compiles once\n` +
` classify(value); // reused hot path\n` +
` Silence: silenceWarnings() — or set MATCHIGO_DEV=0.`,
` Silence: silenceWarnings() — or set NODE_ENV=production.`,
);
warnedMatcher = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export const P = {
*
* @example
* ```ts
* { with: P.union("GET", "POST", "PUT"), then: () => "http-verb" }
* { with: P.union("GET", "POST", "PUT"), then: () => "method" }
* ```
*/
union: <const Values extends readonly unknown[]>(...values: Values): PUnion<Values> => ({
Expand Down
Loading