Skip to content

feat: export script names and analyzer constants - #14

Merged
chrisdengso merged 1 commit into
mainfrom
feat/export-script-constants
Jul 20, 2026
Merged

feat: export script names and analyzer constants#14
chrisdengso merged 1 commit into
mainfrom
feat/export-script-constants

Conversation

@chrisdengso

Copy link
Copy Markdown
Contributor

Callers writing rules against dominantScript or expectedScripts had no way to discover the actual values — they had to hardcode strings and hope. This exports what the analysis already knows.

New exports

Export What it is
SCRIPT_NAMES Every script the classifier can name — the possible values of dominantScript and words[].scripts
SUPPORTED_SCRIPTS The subset this runtime's Unicode tables support (all of them, on a current engine)
PSEUDO_SCRIPTS Common, Inherited, Unknown — never appear in a finding
FORMAT_CHAR_SCRIPTS Scripts exempt from invisible/zalgo
LEGITIMATE_SCRIPT_COMBINATIONS Mixes that never fire mixed_script
ZALGO_MARK_RUN Marks per base at which zalgo fires
primaryScript(char) Classify a single character
ScriptName, PseudoScript The types behind them

Type narrowing

AnalysisResult.dominantScript, WordFinding.scripts and AnalyzeOptions.expectedScripts move from string to ScriptName. Runtime behavior is unchanged, but TS callers passing a plain string[] to expectedScripts now need ScriptName[] — which is the point: expectedScripts: ['Cyrilic'] no longer compiles silently matching nothing.

Testing

test/exports.test.ts ties each constant back to the behavior it claims to describe — ZALGO_MARK_RUN is asserted as the depth at which the signal flips, FORMAT_CHAR_SCRIPTS against a Persian ZWNJ passing and a Latin one failing — so a constant cannot drift from the analyzer without a red test. The README example runs in test/readme.test.ts per repo convention.

275 tests pass; typecheck, lint and build clean. Changeset included (minor).

🤖 Generated with Claude Code

Callers writing rules against dominantScript or expectedScripts had no way
to know the actual values — they had to hardcode strings and hope. Export
what the analysis already knows: SCRIPT_NAMES (every value a finding can
report), SUPPORTED_SCRIPTS, PSEUDO_SCRIPTS, FORMAT_CHAR_SCRIPTS,
LEGITIMATE_SCRIPT_COMBINATIONS, ZALGO_MARK_RUN and primaryScript().

Script-typed fields move from string to the ScriptName union, so a typo
like expectedScripts: ['Cyrilic'] fails to compile instead of silently
matching nothing. Runtime behavior is unchanged.

Each constant is tested against the behavior it describes, so a constant
cannot drift from the analyzer without a red test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chrisdengso
chrisdengso merged commit 86027a1 into main Jul 20, 2026
1 check passed
@chrisdengso
chrisdengso deleted the feat/export-script-constants branch July 20, 2026 11:06
@github-actions github-actions Bot mentioned this pull request Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant