gt-node 0.6.1 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -24,4 +24,31 @@ declare function initializeGT(params: InitializeGTParams): void;
24
24
  */
25
25
  declare function withGT<T>(locale: string, fn: () => T): T;
26
26
 
27
- export { initializeGT, withGT };
27
+ /**
28
+ * A request object like interface
29
+ * @interface RequestLike
30
+ * @property {Record<string, string | string[] | undefined>} headers - The request headers
31
+ */
32
+ interface RequestLike {
33
+ headers: Record<string, string | string[] | undefined>;
34
+ }
35
+ /**
36
+ * Resolve the preferred locale from the request Accept-Language header, fallback to the default locale if no match is found
37
+ * @param request - The request object
38
+ * @returns The preferred locale
39
+ *
40
+ * @example
41
+ * const locale = getRequestLocale({ headers: { 'accept-language': 'fr-FR,fr;q=0.9,en;q=0.8' } });
42
+ * console.log(locale); // 'fr'
43
+ *
44
+ * @example
45
+ * app.get('/', (req, res) => {
46
+ * const locale = getRequestLocale(req);
47
+ * withGT(locale, () => {
48
+ * res.send(`Locale: ${locale}`);
49
+ * });
50
+ * });
51
+ */
52
+ declare function getRequestLocale(request: RequestLike): string;
53
+
54
+ export { getRequestLocale, initializeGT, withGT };