@@ -6,23 +6,23 @@ type InternalState = {
66 adapters : Record < string , ( raw : string , code ?: string ) => Trace | null > ;
77} ;
88
9- const S : InternalState = { adapters : { } } ;
9+ const state : InternalState = { adapters : { } } ;
1010
11- export const loadCopydeck = ( deck : CopyDeck ) => ( S . copy = deck ) ;
11+ export const loadCopydeck = ( deck : CopyDeck ) => ( state . copy = deck ) ;
1212
1313const getUiString = ( key : keyof NonNullable < CopyDeck [ "ui" ] > , fallback : string ) : string => {
14- return S . copy ?. ui ?. [ key ] || fallback ;
14+ return state . copy ?. ui ?. [ key ] || fallback ;
1515} ;
1616
1717export const registerAdapter = ( name : string , fn : ( raw : string , code ?: string ) => Trace | null ) =>
18- ( S . adapters [ name ] = fn ) ;
18+ ( state . adapters [ name ] = fn ) ;
1919
2020const coerceTrace = ( input : string | Error | Trace , code ?: string ) : Trace => {
2121 if ( ( input as Trace ) . raw !== undefined ) return input as Trace ;
2222 const raw = typeof input === "string" ? input : String ( ( input as Error ) . stack || ( input as Error ) . message || input ) ;
2323 // try adapters in registration order
24- for ( const key of Object . keys ( S . adapters ) ) {
25- const t = S . adapters [ key ] ( raw , code ) ;
24+ for ( const key of Object . keys ( state . adapters ) ) {
25+ const t = state . adapters [ key ] ( raw , code ) ;
2626 if ( t ) return t ;
2727 }
2828 // generic fallback
@@ -42,7 +42,7 @@ const coerceTrace = (input: string | Error | Trace, code?: string): Trace => {
4242} ;
4343
4444const pickVariant = ( trace : Trace , code : string | undefined , audience : string ) => {
45- const deck = S . copy ;
45+ const deck = state . copy ;
4646 const kind = trace . type && deck ?. errors [ trace . type ] ? trace . type : "Other" ;
4747 const entry = deck ?. errors [ kind ] ;
4848 if ( ! entry ) return null ;
@@ -78,7 +78,7 @@ const pickVariant = (trace: Trace, code: string | undefined, audience: string) =
7878 const v = entry . variants [ i ] ;
7979 if ( ! matches ( v ) ) continue ;
8080
81- const glob = S . copy ?. glossary ?. [ audience ] || undefined ;
81+ const glob = state . copy ?. glossary ?. [ audience ] || undefined ;
8282 const title = applyGlossary ( tmpl ( v . title , vars ) , glob ) ;
8383 const summary = applyGlossary ( tmpl ( v . summary , vars ) , glob ) ;
8484 const why = v . why ? applyGlossary ( tmpl ( v . why , vars ) , glob ) : undefined ;
@@ -122,7 +122,7 @@ const pickVariant = (trace: Trace, code: string | undefined, audience: string) =
122122} ;
123123
124124export const friendlyExplain = ( opts : ExplainOptions ) : ExplainResult => {
125- if ( ! S . copy ) throw new Error ( "Copydeck not loaded" ) ;
125+ if ( ! state . copy ) throw new Error ( "Copydeck not loaded" ) ;
126126 const audience = opts . audience || "beginner" ;
127127 const verbosity = opts . verbosity || "standard" ;
128128 const code = opts . code ;
0 commit comments