Skip to main content

Helpers

The pieces createIndicators is built from, exported for tests and tooling.

None of them read the environment.

Negotiation

parseAcceptLanguage(header): { tag: string; quality: number }[]
negotiateLocale(header, locales, defaultLocale): string

parseAcceptLanguage returns the ranges best first, in the header's order for equal weights, dropping malformed entries and q=0. negotiateLocale is negotiate for any list of locales.

Paths

localizePath(config, pathname, locale): string
localizeHref(config, href, locale): Href
mountHref(href, mount): Href

config is indicators.config. mountHref moves a path under a mount by the rule prefixHref in @fairgarden/monolith/link uses: only paths rooted at /, never twice, and /identity is not under /id.

Routes

indicatorsRewrites(config, options?): Rewrite[]
indicatorsRedirects(config, options?): Redirect[]
stylesheetHeaders(config): Header[]
stylesheetPreloadHeaders(config, options?): Header[]
clientHintHeaders(config, hardFlags?, options?): Header[]

And from @fairgarden/indicators/withFairGardenIndicators:

detectExclusions(root, underSegment = true): { exclude: string[]; excludeStems: string[] }

underSegment is whether the routes sit under an indicator segment; the plugin passes false for a tree with segments: [], whose top-level directories are the routes rather than paths outside the tree.

What withFairGardenIndicators puts into the config, as data: the chain, the redirects, the cache policy and preload of each stylesheet, the Accept-CH (and, with options.critical, Critical-CH) for the client hints the indicators and hard flags read, and what a look at an app directory adds to options.exclude and options.excludeStems. Useful for asserting on the exact routes, or for feeding them to Next's checkCustomRoutes in a test.

Constants

ALWAYS_EXCLUDED is ['_next', 'api', '.well-known'], and EMPTY_SEGMENT is '-'.