Skip to content

validateOptions

reference
1 min readUpdated

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

ts
function validateOptions(options: DetectorOptions): void

Parameters

NameType
optionsDetectorOptions

Returns: void

Diagram

mermaid
graph LR
  A[Detector options] --> B[validateOptions]
  B --> C[Valid options]
  B --> D[Invalid option error]
  C --> E[Language middleware]

Usage

ts
import { 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?

Download as PDF
validateOptions — Hono (narrator proof)