Skip to content

Detectors

reference
1 min readUpdated

Kind: Type

Source: src/middleware/language/language.ts

Part of: Middleware

Type-safe detector map

Detectors defines the type-safe map of language detector entries used by the language middleware. It keeps detector registration aligned with the detector contract expected by the middleware.

Definition

ts
Record<keyof typeof detectors, DetectorFunction>

Diagram

mermaid
graph LR
  Middleware[Language middleware] --> Detectors[Detectors map]
  Detectors --> Detector[Detector entry]
  Detector --> Result[Detected language result]

Usage

ts
import type { Detectors } from './middleware/language/language';

const detectors: Detectors = {
  // Add detector entries that match the detector contract.
};

export function getDetectors(): Detectors {
  return detectors;
}

AI Coding Instructions

  • Keep detector map entries compatible with the detector type defined in language.ts.
  • Import Detectors with import type when it is only used for type checking.
  • Add new detector registrations through the typed map instead of bypassing type checks with casts.
  • Update middleware configuration when changing the detector map or detector registration flow.

Was this page helpful?

Download as PDF
Detectors — Hono (narrator proof)