@inlang/paraglide-js
Version:
[](https://inlang.com)
60 lines • 2.54 kB
TypeScript
/**
* Checks if the given strategy is a custom strategy.
*
* @param {any} strategy The name of the custom strategy to validate.
* Must be a string that starts with "custom-" followed by alphanumeric characters.
* @returns {boolean} Returns true if it is a custom strategy, false otherwise.
*/
export function isCustomStrategy(strategy: any): boolean;
/**
* Defines a custom strategy that is executed on the server.
*
* @param {any} strategy The name of the custom strategy to define. Must follow the pattern `custom-<name>` where
* `<name>` contains only alphanumeric characters.
* @param {CustomServerStrategyHandler} handler The handler for the custom strategy, which should implement
* the method `getLocale`.
* @returns {void}
*/
export function defineCustomServerStrategy(strategy: any, handler: CustomServerStrategyHandler): void;
/**
* Defines a custom strategy that is executed on the client.
*
* @param {any} strategy The name of the custom strategy to define. Must follow the pattern `custom-<name>` where
* `<name>` contains only alphanumeric characters.
* @param {CustomClientStrategyHandler} handler The handler for the custom strategy, which should implement the
* methods `getLocale` and `setLocale`.
* @returns {void}
*/
export function defineCustomClientStrategy(strategy: any, handler: CustomClientStrategyHandler): void;
/**
* @typedef {"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"} BuiltInStrategy
*/
/**
* @typedef {`custom_${string}`} CustomStrategy
*/
/**
* @typedef {BuiltInStrategy | CustomStrategy} Strategy
*/
/**
* @typedef {Array<Strategy>} Strategies
*/
/**
* @typedef {{ getLocale: (request?: Request) => string | undefined }} CustomServerStrategyHandler
*/
/**
* @typedef {{ getLocale: () => string | undefined, setLocale: (locale: string) => void }} CustomClientStrategyHandler
*/
export const customServerStrategies: Map<any, any>;
export const customClientStrategies: Map<any, any>;
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) => string | undefined;
};
export type CustomClientStrategyHandler = {
getLocale: () => string | undefined;
setLocale: (locale: string) => void;
};
//# sourceMappingURL=strategy.d.ts.map