DefinitelyTyped/types/express-simple-locale/index.d.ts
Piotr Błażejewicz (Peter Blazejewicz) 3e769c3a18
feat(express-simple-locale): new definition (#46833)
Definition types for Express middleware:
- definition file
- tests

https://www.npmjs.com/package/express-simple-locale
https://github.com/n26/express-simple-locale#options

Thanks!
2020-08-27 19:40:32 -04:00

57 lines
1.5 KiB
TypeScript

// Type definitions for express-simple-locale 0.3
// Project: https://github.com/n26/express-simple-locale#readme
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import express = require('express');
import { RequestHandler } from 'express';
declare module 'express-serve-static-core' {
interface Request {
userLocale: locale.ShortLocale;
}
}
/**
* A simple Express middleware to guess the short-locale of a user.
* It then saves the found locale on the request for further usage.
*/
declare function locale(options?: locale.Options): RequestHandler;
declare namespace locale {
/**
* @see {@link https://github.com/n26/express-simple-locale#options}
*/
interface Options {
/**
* the key to save locale to on the request
* @default 'locale'
*/
key?: string;
/**
* available locales for the app
* @default []
*/
supportedLocales?: string[];
/**
* locale to fallback to
* @default 'en'
*/
defaultLocale?: string;
/**
* cookie to try getting the locale from
* @default 'locale'
*/
cookieName?: string;
/**
* the query parameter(s) to look the locale from
* @default ['locale']
*/
queryParams?: string | string[];
}
/** The short-locale of a user */
type ShortLocale = string;
}
export = locale;