import { de } from './lang/de.js'; import { en } from './lang/en.js'; /** The languages that ship with the package. */ export type BuiltinLanguage = 'en' | 'de'; /** * A language code. The built-ins autocomplete; any other string is accepted, * so BCP-47 tags like `de-AT` or private codes like `internal-slang` work. */ export type Language = BuiltinLanguage | (string & {}); /** A resolved list pair, with any `extends` chain already flattened in. */ export interface LanguageLists { /** Patterns that flag a match. */ readonly profanity: readonly string[]; /** Words that must never be flagged, even when a pattern matches inside them. */ readonly allow: readonly string[]; } /** What you hand to {@link registerLanguage}. */ export interface LanguageDefinition { /** Patterns that flag a match. Regex sources, matched as substrings. */ readonly profanity?: readonly string[]; /** * Words that must never be flagged. Regex sources, matched against the * **whole surrounding word**, so `klass\p{L}*` clears `Klassik`. */ readonly allow?: readonly string[]; /** * Inherit from an already-registered language. The parent's patterns come * first, this definition is added on top. The parent must exist already. */ readonly extends?: Language; } /** * Adds a language, or replaces one that is already registered. * * ```ts * registerLanguage('fr', { * profanity: ['merde', 'connard', 'salope', 'putain'], * allow: ['\\p{L}*connaiss\\p{L}*'], * }); * * // A regional variant inherits instead of duplicating: * registerLanguage('de-AT', { extends: 'de', profanity: ['oasch', 'gschissana'] }); * ``` * * @throws TypeError if the code or a pattern has the wrong shape. * @throws SyntaxError if a pattern is not a valid regular expression. * @throws RangeError if `extends` names an unregistered language or forms a cycle. */ export declare function registerLanguage(code: Language, definition: LanguageDefinition): void; /** * Removes a language. * * @returns `false` if it was not registered to begin with. * @throws RangeError if another registered language extends it. */ export declare function unregisterLanguage(code: Language): boolean; /** Every registered code, in registration order. */ export declare function listLanguages(): Language[]; /** True if the code resolves to a registered language, subtag fallback included. */ export declare function hasLanguage(code: Language): boolean; /** * Resolves a code to a registered one by dropping BCP-47 subtags from the * right: `de-AT-1996` tries `de-at-1996`, then `de-at`, then `de`. */ export declare function resolveKey(code: Language): string | undefined; /** * The lists a code resolves to, with any `extends` chain flattened in and * subtag fallback applied. `undefined` if nothing matches. */ export declare function getLanguage(code: Language): LanguageLists | undefined; /** Drops every registration and restores the built-in `en` and `de`. */ export declare function resetLanguages(): void; export { de, en }; //# sourceMappingURL=registry.d.ts.map