$ show i18next/i18next-browser-languageDetector
This repository provides the official browser language detection plugin for i18next. It implements a modular strategy pattern where each detector (cookie, querystring, localStorage, sessionStorage, navigator, htmlTag, path, subdomain, hash) is a self-contained module with a consistent interface. The main `Browser` class orchestrates detection by iterating through a configurable order of detectors, filters out XSS vectors, and optionally converts detected language codes. The code is well-structured, tested, and production-grade; the cookie detector in particular includes a robust RFC-compliant serialization function. Everything is browser-native with no heavy dependencies beyond i18next itself.
The LLM identified 2 files worth highlighting for reuse:
Exports a `hasXSS` function that detects common XSS attack patterns in strings (e.g., script tags, event handlers, javascript: URIs). This is a reusable security helper that can be extracted into any web project for input validation. Also provides `defaults` and `extend` utility functions.
Implements a complete cookie read/write/remove module with RFC-compliant serialization. Supports all standard Set-Cookie attributes (maxAge, domain, path, expires, httpOnly, secure, sameSite, Partitioned). The `serializeCookie` function is self-contained and reusable. Also includes XSS detection on detected language. This module could be extracted as a standalone cookie utility library.