Kind: Function
Source: src/middleware/language/language.ts
Part of: Middleware
Validate detector options
validateOptions validates detector options before they are used by the language middleware. It checks that the supplied configuration matches the detector's expected option structure. Call it during middleware setup to reject invalid configuration early.
Signature
tsfunction validateOptions(options: DetectorOptions): void
Parameters
| Name | Type |
|---|---|
options | DetectorOptions |
Returns: void
Diagram
mermaidgraph LR A[Detector options] --> B[validateOptions] B --> C[Valid options] B --> D[Invalid option error] C --> E[Language middleware]
Usage
tsimport { validateOptions } from './src/middleware/language/language';
const detectorOptions = {
supportedLanguages: ['en', 'fr'],
fallbackLanguage: 'en',
};
validateOptions(detectorOptions);
// Pass validated options to language middleware setup.
AI Coding Instructions
- Validate detector configuration before creating or invoking the language middleware.
- Keep option names and value types aligned with the language detector configuration contract.
- Do not bypass validation when options come from environment variables or external configuration files.
- Update validation rules when adding detector options so invalid values fail at setup time.
Was this page helpful?