UNPKG

@inlang/paraglide-js

Version:

[![NPM Downloads](https://img.shields.io/npm/dw/%40inlang%2Fparaglide-js?logo=npm&logoColor=red&label=npm%20downloads)](https://www.npmjs.com/package/@inlang/paraglide-js) [![GitHub Issues](https://img.shields.io/github/issues-closed/opral/paraglide-js?lo

64 lines 3.06 kB
/** * @typedef {"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"} BuiltInStrategy */ export type BuiltInStrategy = "cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"; export type CustomStrategy = `custom_${string}`; export type Strategy = BuiltInStrategy | CustomStrategy; export type Strategies = Array<Strategy>; export type CustomServerStrategyHandler = { getLocale: (request?: Request) => Promise<string | undefined> | (string | undefined); }; export type CustomClientStrategyHandler = { getLocale: () => Promise<string | undefined> | (string | undefined); setLocale: (locale: string) => Promise<void> | void; }; /** * @typedef {`custom_${string}`} CustomStrategy */ /** * @typedef {BuiltInStrategy | CustomStrategy} Strategy */ /** * @typedef {Array<Strategy>} Strategies */ /** * @typedef {{ getLocale: (request?: Request) => Promise<string | undefined> | (string | undefined) }} CustomServerStrategyHandler */ /** * @typedef {{ getLocale: () => Promise<string|undefined> | (string | undefined), setLocale: (locale: string) => Promise<void> | void }} CustomClientStrategyHandler */ /** @type {Map<string, CustomServerStrategyHandler>} */ export declare const customServerStrategies: Map<string, CustomServerStrategyHandler>; /** @type {Map<string, CustomClientStrategyHandler>} */ export declare const customClientStrategies: Map<string, CustomClientStrategyHandler>; /** * Checks if the given strategy is a custom strategy. * * @param {unknown} strategy The name of the custom strategy to validate. * Must be a string that starts with "custom-" followed by alphanumeric characters, hyphens, or underscores. * @returns {boolean} Returns true if it is a custom strategy, false otherwise. */ export declare function isCustomStrategy(strategy: unknown): boolean; /** * Defines a custom strategy that is executed on the server. * * @see https://paraglidejs.com/strategy#write-your-own-strategy * * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores. * @param {CustomServerStrategyHandler} handler The handler for the custom strategy, which should implement * the method getLocale. * @returns {void} */ export declare function defineCustomServerStrategy(strategy: string, handler: CustomServerStrategyHandler): void; /** * Defines a custom strategy that is executed on the client. * * @see https://paraglidejs.com/strategy#write-your-own-strategy * * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores. * @param {CustomClientStrategyHandler} handler The handler for the custom strategy, which should implement the * methods getLocale and setLocale. * @returns {void} */ export declare function defineCustomClientStrategy(strategy: string, handler: CustomClientStrategyHandler): void; //# sourceMappingURL=strategy.d.ts.map