/** * Pattern model. * * A rule describes one entity type (PESEL, IBAN, …) through one or more * scored variants. Confidence, not a hand-curated on/off list, decides whether * a match is masked: each variant carries a base score, a passing checksum * raises it, and a nearby context word ("PESEL:", "NIP") raises it further. * * This is what lets a loose pattern coexist with a strict one — bare eleven * digits stay low-confidence until the checksum or the surrounding words say * otherwise, instead of forcing a choice between recall and precision. */ /** Sensitivity level: how much confidence a match needs before it is masked. */ export type EngineLevel = 'balanced' | 'strict' | 'paranoid'; export type SupportedLocale = 'pl' | 'en' | 'de' | 'it' | 'es' | 'fr' | 'nl' | 'cz' | 'sk' | 'se' | 'fi' | 'uk'; /** * Every locale some rule covers. Kept in step with `allPatterns` by a test * rather than by discipline — a new pack that is not listed here would never * be loaded by the default selection, which is the failure this list exists * to prevent. */ export declare const SUPPORTED_LOCALES: SupportedLocale[]; /** * Sentinel `lang` value meaning "load every locale pack". * * It is the default because selecting a single pack fails open: a Polish * document processed with the English pack loses its PESEL, NIP and phone * number silently, and the server still reports success. Recognizing an * identifier that turns out to be an order number costs an unnecessary token; * missing a national ID costs an incident. */ export declare const ALL_LOCALES = "all"; /** Which locale packs a given configuration turns on, and what that leaves off. */ export interface LocaleSelection { /** Packs that will run. */ active: SupportedLocale[]; /** Packs that will not run — empty when every pack is active. */ disabled: SupportedLocale[]; /** Requested values naming no known pack. Ignored, but worth reporting. */ unknown: string[]; /** True when every pack is active. */ all: boolean; } /** * Turn a configured `lang` (plus any `extraLocales`) into the set of packs to * run. Anything that does not resolve to at least one known pack — the `all` * sentinel, a typo, an empty string — turns every pack on. Narrowing coverage * is only ever the result of naming a locale that exists. */ export declare function resolveLocales(lang: string, extraLocales?: string[]): LocaleSelection; /** Minimum score a candidate needs at each sensitivity level. */ export declare const ENGINE_THRESHOLDS: Record; /** How much a nearby context word adds to a candidate's score. */ export declare const CONTEXT_BOOST = 0.35; /** * Floor applied once a context word was found, however weak the base score. * Set at the balanced threshold on purpose: if the document itself says * "Passport no" right before a number, that is enough to mask it by default. */ export declare const MIN_SCORE_WITH_CONTEXT = 0.5; /** Floor applied when a checksum validates — a verified identifier is not a guess. */ export declare const CHECKSUM_VALID_SCORE = 0.85; /** * How far around a match to look for context words, counted in words and * deliberately lopsided: documents label a value before printing it * ("data urodzenia 1944-05-14", "NIP: 526-000-00-05"), so looking far ahead * mostly finds the next field's label and masks the wrong value. */ export declare const CONTEXT_WORDS_BEFORE = 8; export declare const CONTEXT_WORDS_AFTER = 4; export declare const MAX_SCORE = 1; export interface PatternVariant { /** Human-readable variant name, e.g. 'PESEL (checksum)' — used in diagnostics. */ name: string; /** Regex with the 'g' flag. */ regex: RegExp; /** Base confidence in [0, 1] before checksum and context adjustments. */ score: number; } export interface PatternRule { /** Unique identifier, e.g. 'global.email' or 'pl.pesel' */ id: string; /** Token tag used in replacement, e.g. 'EMAIL', 'PESEL' */ entityType: string; /** One or more scored variants, strongest first by convention. */ patterns: PatternVariant[]; /** null = applies to all locales (global); otherwise locale-specific */ locales: SupportedLocale[] | null; /** * Words that, found near a match, raise its confidence. Matched * case-insensitively on word boundaries, so "PESEL" hits "nr PESEL:". */ context?: string[]; description: string; /** * Optional checksum. Receives the match with whitespace stripped. * Passing always raises the score to at least CHECKSUM_VALID_SCORE. */ validate?: (match: string) => boolean; /** * What a *failing* checksum means: * * - 'filter' (default) — not this entity at all, so drop the candidate when * strict validation is on. Right for formats where the checksum is part of * the shape: a card number failing Luhn is not a card number. * - 'boost' — the checksum only adds confidence, never removes a candidate. * Right where a false negative leaks data: a mistyped or fictitious PESEL * is still eleven digits that must not reach the cloud. * - 'gate' — drop on failure but do not promote on success. Right for * plausibility rules rather than checksums: US SSN area numbers rule out * impossible values without making a possible one any more likely. */ checksumMode?: 'filter' | 'boost' | 'gate'; } /** Highest base score a rule can produce, i.e. its strongest variant. */ export declare function maxScore(rule: PatternRule): number; /** * Rules that apply to a set of locales: the locale-specific ones first, then * the global ones. Order does not affect matching (every candidate is scored), * but keeping the specific rules first makes diagnostics and lookups predictable. */ export declare function rulesForLocales(rules: PatternRule[], locales: string[]): PatternRule[]; /** Rules that apply to one locale, plus any extras. */ export declare function rulesForLocale(rules: PatternRule[], locale: string, extraLocales?: string[]): PatternRule[]; /** Rules strong enough to fire at the given sensitivity level. */ export declare function rulesForLevel(rules: PatternRule[], level: EngineLevel): PatternRule[]; //# sourceMappingURL=types.d.ts.map