@nr1e/commons 0.4.8 → 0.4.9

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.
Files changed (49) hide show
  1. package/dist/paraglide/messages/_index.d.ts +5 -0
  2. package/dist/paraglide/messages/_index.d.ts.map +1 -0
  3. package/dist/paraglide/messages/_index.js +6 -0
  4. package/dist/paraglide/messages/_index.js.map +1 -0
  5. package/dist/paraglide/messages/v_atleast1.d.ts +20 -0
  6. package/dist/paraglide/messages/v_atleast1.d.ts.map +1 -0
  7. package/dist/paraglide/messages/v_atleast1.js +72 -0
  8. package/dist/paraglide/messages/v_atleast1.js.map +1 -0
  9. package/dist/paraglide/messages/v_atmost1.d.ts +20 -0
  10. package/dist/paraglide/messages/v_atmost1.d.ts.map +1 -0
  11. package/dist/paraglide/messages/v_atmost1.js +72 -0
  12. package/dist/paraglide/messages/v_atmost1.js.map +1 -0
  13. package/dist/paraglide/messages/v_nan2.d.ts +18 -0
  14. package/dist/paraglide/messages/v_nan2.d.ts.map +1 -0
  15. package/dist/paraglide/messages/v_nan2.js +72 -0
  16. package/dist/paraglide/messages/v_nan2.js.map +1 -0
  17. package/dist/paraglide/messages.d.ts +3 -0
  18. package/dist/paraglide/messages.d.ts.map +1 -0
  19. package/dist/paraglide/messages.js +5 -0
  20. package/dist/paraglide/messages.js.map +1 -0
  21. package/dist/paraglide/registry.d.ts +22 -0
  22. package/dist/paraglide/registry.d.ts.map +1 -0
  23. package/dist/paraglide/registry.js +32 -0
  24. package/dist/paraglide/registry.js.map +1 -0
  25. package/dist/paraglide/runtime.d.ts +731 -0
  26. package/dist/paraglide/runtime.d.ts.map +1 -0
  27. package/dist/paraglide/runtime.js +1782 -0
  28. package/dist/paraglide/runtime.js.map +1 -0
  29. package/dist/paraglide/server.d.ts +93 -0
  30. package/dist/paraglide/server.d.ts.map +1 -0
  31. package/dist/paraglide/server.js +239 -0
  32. package/dist/paraglide/server.js.map +1 -0
  33. package/dist/valibot/index.d.ts +1 -0
  34. package/dist/valibot/index.d.ts.map +1 -1
  35. package/dist/valibot/index.js +1 -0
  36. package/dist/valibot/index.js.map +1 -1
  37. package/dist/valibot/locale.d.ts +4 -0
  38. package/dist/valibot/locale.d.ts.map +1 -0
  39. package/dist/valibot/locale.js +3 -0
  40. package/dist/valibot/locale.js.map +1 -0
  41. package/dist/valibot/string-number.d.ts +37 -16
  42. package/dist/valibot/string-number.d.ts.map +1 -1
  43. package/dist/valibot/string-number.js +53 -32
  44. package/dist/valibot/string-number.js.map +1 -1
  45. package/dist/valibot/string-number.test.d.ts +2 -0
  46. package/dist/valibot/string-number.test.d.ts.map +1 -0
  47. package/dist/valibot/string-number.test.js +39 -0
  48. package/dist/valibot/string-number.test.js.map +1 -0
  49. package/package.json +7 -4
@@ -0,0 +1,731 @@
1
+ /**
2
+ * Returns the strategy to use for a specific URL.
3
+ *
4
+ * If no route strategy matches (or the matching rule is `exclude: true`),
5
+ * the global strategy is returned.
6
+ *
7
+ * @param {string | URL} url
8
+ * @returns {typeof strategy}
9
+ */
10
+ export function getStrategyForUrl(url: string | URL): typeof strategy;
11
+ /**
12
+ * Returns whether the given URL is excluded from middleware i18n processing.
13
+ *
14
+ * @param {string | URL} url
15
+ * @returns {boolean}
16
+ */
17
+ export function isExcludedByRouteStrategy(url: string | URL): boolean;
18
+ /**
19
+ * Sets the server side async local storage.
20
+ *
21
+ * The function is needed because the `runtime.js` file
22
+ * must define the `serverAsyncLocalStorage` variable to
23
+ * avoid a circular import between `runtime.js` and
24
+ * `server.js` files.
25
+ *
26
+ * @param {ParaglideAsyncLocalStorage | undefined} value
27
+ */
28
+ export function overwriteServerAsyncLocalStorage(value: ParaglideAsyncLocalStorage | undefined): void;
29
+ /**
30
+ * Resolve locale for a given URL using route-aware strategies.
31
+ *
32
+ * @param {string | URL} url
33
+ * @returns {Locale}
34
+ */
35
+ export function getLocaleForUrl(url: string | URL): Locale;
36
+ /**
37
+ * Get writing direction for a locale.
38
+ *
39
+ * Uses `Intl.Locale` text info when available and falls back to a
40
+ * language-based RTL check for runtimes without `getTextInfo()`.
41
+ *
42
+ * @example
43
+ * getTextDirection(); // "ltr" or "rtl" for current locale
44
+ * getTextDirection("ar"); // "rtl"
45
+ * getTextDirection("en"); // "ltr"
46
+ *
47
+ * @param {string} [locale] - Target locale. If not provided, uses `getLocale()`
48
+ * @returns {"ltr" | "rtl"}
49
+ */
50
+ export function getTextDirection(locale?: string): "ltr" | "rtl";
51
+ /**
52
+ * Coerces a locale-like string to the canonical locale value used by the runtime.
53
+ *
54
+ * @param {unknown} value
55
+ * @returns {Locale | undefined}
56
+ */
57
+ export function toLocale(value: unknown): Locale | undefined;
58
+ /**
59
+ * Check if something is an available locale with the canonical project casing.
60
+ *
61
+ * @example
62
+ * if (isLocale(params.locale)) {
63
+ * setLocale(params.locale);
64
+ * } else {
65
+ * setLocale('en');
66
+ * }
67
+ *
68
+ * Use `toLocale()` when you want case-insensitive matching and canonicalization.
69
+ *
70
+ * @param {unknown} locale
71
+ * @returns {locale is Locale}
72
+ */
73
+ export function isLocale(locale: unknown): locale is Locale;
74
+ /**
75
+ * Asserts that the input can be normalized to a locale.
76
+ *
77
+ * @param {unknown} input - The input to check.
78
+ * @returns {Locale} The input normalized to a Locale.
79
+ * @throws {Error} If the input is not a locale.
80
+ */
81
+ export function assertIsLocale(input: unknown): Locale;
82
+ /**
83
+ * Extracts a cookie from the document.
84
+ *
85
+ * Will return undefined if the document is not available or if the cookie is not set.
86
+ * The `document` object is not available in server-side rendering, so this function should not be called in that context.
87
+ *
88
+ * @returns {Locale | undefined}
89
+ */
90
+ export function extractLocaleFromCookie(): Locale | undefined;
91
+ /**
92
+ * Extracts a locale from the accept-language header.
93
+ *
94
+ * Use the function on the server to extract the locale
95
+ * from the accept-language header that is sent by the client.
96
+ *
97
+ * @example
98
+ * const locale = extractLocaleFromHeader(request);
99
+ *
100
+ * @param {Request} request - The request object to extract the locale from.
101
+ * @returns {Locale | undefined} The negotiated preferred language.
102
+ */
103
+ export function extractLocaleFromHeader(request: Request): Locale | undefined;
104
+ /**
105
+ * Negotiates a preferred language from navigator.languages.
106
+ *
107
+ * Use the function on the client to extract the locale
108
+ * from the navigator.languages array.
109
+ *
110
+ * @example
111
+ * const locale = extractLocaleFromNavigator();
112
+ *
113
+ * @returns {Locale | undefined}
114
+ */
115
+ export function extractLocaleFromNavigator(): Locale | undefined;
116
+ /**
117
+ * Extracts the locale from a given URL using native URLPattern.
118
+ *
119
+ * The built-in default `/:locale/...` routing is case-insensitive because it
120
+ * canonicalizes the first path segment with `toLocale()`. Custom `urlPatterns`
121
+ * keep URLPattern's normal exact matching semantics for path segments.
122
+ *
123
+ * @param {URL|string} url - The full URL from which to extract the locale.
124
+ * @returns {Locale|undefined} The extracted locale, or undefined if no locale is found.
125
+ */
126
+ export function extractLocaleFromUrl(url: URL | string): Locale | undefined;
127
+ /**
128
+ * Lower-level URL localization function, primarily used in server contexts.
129
+ *
130
+ * This function is designed for server-side usage where you need precise control
131
+ * over URL localization, such as in middleware or request handlers. It works with
132
+ * URL objects and always returns absolute URLs.
133
+ *
134
+ * For client-side UI components, use `localizeHref()` instead, which provides
135
+ * a more convenient API with relative paths and automatic locale detection.
136
+ *
137
+ * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * // Server middleware example
142
+ * app.use((req, res, next) => {
143
+ * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
144
+ * const localized = localizeUrl(url, { locale: "de" });
145
+ *
146
+ * if (localized.href !== url.href) {
147
+ * return res.redirect(localized.href);
148
+ * }
149
+ * next();
150
+ * });
151
+ * ```
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * // Using with URL patterns
156
+ * const url = new URL("https://example.com/about");
157
+ * localizeUrl(url, { locale: "de" });
158
+ * // => URL("https://example.com/de/about")
159
+ *
160
+ * // Using with domain-based localization
161
+ * const url = new URL("https://example.com/store");
162
+ * localizeUrl(url, { locale: "de" });
163
+ * // => URL("https://de.example.com/store")
164
+ * ```
165
+ *
166
+ * @param {string | URL} url - The URL to localize. If string, must be absolute.
167
+ * @param {object} [options] - Options for localization
168
+ * @param {Locale} [options.locale] - Target locale. If not provided, uses getLocale()
169
+ * @returns {URL} The localized URL, always absolute
170
+ */
171
+ export function localizeUrl(url: string | URL, options?: {
172
+ locale?: "en-US" | "ar" | "en" | "af" | "en-GB" | "en-ZA" | "es" | "es-US" | "fr" | "fr-CA" | "fr-FR" | undefined;
173
+ }): URL;
174
+ /**
175
+ * Low-level URL de-localization function, primarily used in server contexts.
176
+ *
177
+ * This function is designed for server-side usage where you need precise control
178
+ * over URL de-localization, such as in middleware or request handlers. It works with
179
+ * URL objects and always returns absolute URLs.
180
+ *
181
+ * For client-side UI components, use `deLocalizeHref()` instead, which provides
182
+ * a more convenient API with relative paths.
183
+ *
184
+ * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * // Server middleware example
189
+ * app.use((req, res, next) => {
190
+ * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
191
+ * const baseUrl = deLocalizeUrl(url);
192
+ *
193
+ * // Store the base URL for later use
194
+ * req.baseUrl = baseUrl;
195
+ * next();
196
+ * });
197
+ * ```
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * // Using with URL patterns
202
+ * const url = new URL("https://example.com/de/about");
203
+ * deLocalizeUrl(url); // => URL("https://example.com/about")
204
+ *
205
+ * // Using with domain-based localization
206
+ * const url = new URL("https://de.example.com/store");
207
+ * deLocalizeUrl(url); // => URL("https://example.com/store")
208
+ * ```
209
+ *
210
+ * @param {string | URL} url - The URL to de-localize. If string, must be absolute.
211
+ * @returns {URL} The de-localized URL, always absolute
212
+ */
213
+ export function deLocalizeUrl(url: string | URL): URL;
214
+ /**
215
+ * Aggregates named groups from various parts of the URLPattern match result.
216
+ *
217
+ *
218
+ * @param {any} match - The URLPattern match result object.
219
+ * @returns {Record<string, string | null | undefined>} An object containing all named groups from the match.
220
+ */
221
+ export function aggregateGroups(match: any): Record<string, string | null | undefined>;
222
+ /**
223
+ * @typedef {object} ShouldRedirectServerInput
224
+ * @property {Request} request
225
+ * @property {string | URL} [url]
226
+ * @property {Locale} [locale]
227
+ *
228
+ * @typedef {object} ShouldRedirectClientInput
229
+ * @property {undefined} [request]
230
+ * @property {string | URL} [url]
231
+ * @property {Locale} [locale]
232
+ *
233
+ * @typedef {ShouldRedirectServerInput | ShouldRedirectClientInput} ShouldRedirectInput
234
+ *
235
+ * @typedef {object} ShouldRedirectResult
236
+ * @property {boolean} shouldRedirect - Indicates whether the consumer should perform a redirect.
237
+ * @property {Locale} locale - Locale resolved using the configured strategies.
238
+ * @property {URL | undefined} redirectUrl - Destination URL when a redirect is required.
239
+ */
240
+ /**
241
+ * Determines whether a redirect is required to align the current URL with the active locale.
242
+ *
243
+ * This helper mirrors the logic that powers `paraglideMiddleware`, but works in both server
244
+ * and client environments. It evaluates the configured strategies in order, computes the
245
+ * canonical localized URL, and reports when the current URL does not match.
246
+ *
247
+ * When called in the browser without arguments, the current `window.location.href` is used.
248
+ *
249
+ * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing#client-side-redirects
250
+ *
251
+ * @example
252
+ * // Client side usage (e.g. TanStack Router beforeLoad hook)
253
+ * async function beforeLoad({ location }) {
254
+ * const decision = await shouldRedirect({ url: location.href });
255
+ *
256
+ * if (decision.shouldRedirect) {
257
+ * throw redirect({ to: decision.redirectUrl.href });
258
+ * }
259
+ * }
260
+ *
261
+ * @example
262
+ * // Server side usage with a Request
263
+ * export async function handle(request) {
264
+ * const decision = await shouldRedirect({ request });
265
+ *
266
+ * if (decision.shouldRedirect) {
267
+ * return Response.redirect(decision.redirectUrl, 307);
268
+ * }
269
+ *
270
+ * return render(request, decision.locale);
271
+ * }
272
+ *
273
+ * @param {ShouldRedirectInput} [input]
274
+ * @returns {Promise<ShouldRedirectResult>}
275
+ */
276
+ export function shouldRedirect(input?: ShouldRedirectInput): Promise<ShouldRedirectResult>;
277
+ /**
278
+ * High-level URL localization function optimized for client-side UI usage.
279
+ *
280
+ * This is a convenience wrapper around `localizeUrl()` that provides features
281
+ * needed in UI:
282
+ *
283
+ * - Accepts relative paths (e.g., "/about")
284
+ * - Returns relative paths when possible
285
+ * - Automatically detects current locale if not specified
286
+ * - Handles string input/output instead of URL objects
287
+ *
288
+ * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * // In a React/Vue/Svelte component
293
+ * const NavLink = ({ href }) => {
294
+ * // Automatically uses current locale, keeps path relative
295
+ * return <a href={localizeHref(href)}>...</a>;
296
+ * };
297
+ *
298
+ * // Examples:
299
+ * localizeHref("/about")
300
+ * // => "/de/about" (if current locale is "de")
301
+ * localizeHref("/store", { locale: "fr" })
302
+ * // => "/fr/store" (explicit locale)
303
+ *
304
+ * // Cross-origin links remain absolute
305
+ * localizeHref("https://other-site.com/about")
306
+ * // => "https://other-site.com/de/about"
307
+ * ```
308
+ *
309
+ * For server-side URL localization (e.g., in middleware), use `localizeUrl()`
310
+ * which provides more precise control over URL handling.
311
+ *
312
+ * @param {string} href - The href to localize (can be relative or absolute)
313
+ * @param {object} [options] - Options for localization
314
+ * @param {Locale} [options.locale] - Target locale. If not provided, uses `getLocale()`
315
+ * @returns {string} The localized href, relative if input was relative
316
+ */
317
+ export function localizeHref(href: string, options?: {
318
+ locale?: "en-US" | "ar" | "en" | "af" | "en-GB" | "en-ZA" | "es" | "es-US" | "fr" | "fr-CA" | "fr-FR" | undefined;
319
+ }): string;
320
+ /**
321
+ * High-level URL de-localization function optimized for client-side UI usage.
322
+ *
323
+ * This is a convenience wrapper around `deLocalizeUrl()` that provides features
324
+ * needed in the UI:
325
+ *
326
+ * - Accepts relative paths (e.g., "/de/about")
327
+ * - Returns relative paths when possible
328
+ * - Handles string input/output instead of URL objects
329
+ *
330
+ * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing
331
+ *
332
+ * @example
333
+ * ```typescript
334
+ * // In a React/Vue/Svelte component
335
+ * const LocaleSwitcher = ({ href }) => {
336
+ * // Remove locale prefix before switching
337
+ * const baseHref = deLocalizeHref(href);
338
+ * return locales.map(locale =>
339
+ * <a href={localizeHref(baseHref, { locale })}>
340
+ * Switch to {locale}
341
+ * </a>
342
+ * );
343
+ * };
344
+ *
345
+ * // Examples:
346
+ * deLocalizeHref("/de/about") // => "/about"
347
+ * deLocalizeHref("/fr/store") // => "/store"
348
+ *
349
+ * // Cross-origin links remain absolute
350
+ * deLocalizeHref("https://example.com/de/about")
351
+ * // => "https://example.com/about"
352
+ * ```
353
+ *
354
+ * For server-side URL de-localization (e.g., in middleware), use `deLocalizeUrl()`
355
+ * which provides more precise control over URL handling.
356
+ *
357
+ * @param {string} href - The href to de-localize (can be relative or absolute)
358
+ * @returns {string} The de-localized href, relative if input was relative
359
+ */
360
+ export function deLocalizeHref(href: string): string;
361
+ /**
362
+ * @param {string} safeModuleId
363
+ * @param {Locale} locale
364
+ */
365
+ export function trackMessageCall(safeModuleId: string, locale: Locale): void;
366
+ /**
367
+ * Generates localized URL variants for all provided URLs based on your configured locales and URL patterns.
368
+ *
369
+ * This function is essential for Static Site Generation (SSG) where you need to tell your framework
370
+ * which pages to pre-render at build time. It's also useful for generating sitemaps and
371
+ * `<link rel="alternate" hreflang>` tags for SEO.
372
+ *
373
+ * The function respects your `urlPatterns` configuration - if you have translated pathnames
374
+ * (e.g., `/about` → `/ueber-uns` for German), it will generate the correct localized paths.
375
+ *
376
+ * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/static-site-generation
377
+ *
378
+ * @example
379
+ * // Basic usage - generate all locale variants for a list of paths
380
+ * const localizedUrls = generateStaticLocalizedUrls([
381
+ * "/",
382
+ * "/about",
383
+ * "/blog/post-1",
384
+ * ]);
385
+ * // Returns URL objects for each locale:
386
+ * // ["/en/", "/de/", "/en/about", "/de/about", "/en/blog/post-1", "/de/blog/post-1"]
387
+ *
388
+ * @example
389
+ * // Use with framework SSG APIs
390
+ * // SvelteKit
391
+ * export function entries() {
392
+ * const paths = ["/", "/about", "/contact"];
393
+ * return generateStaticLocalizedUrls(paths).map(url => ({
394
+ * locale: extractLocaleFromUrl(url)
395
+ * }));
396
+ * }
397
+ *
398
+ * @example
399
+ * // Sitemap generation
400
+ * const allPages = ["/", "/about", "/blog"];
401
+ * const sitemapUrls = generateStaticLocalizedUrls(allPages);
402
+ *
403
+ * @param {(string | URL)[]} urls - List of canonical URLs or paths to generate localized versions for.
404
+ * Can be absolute URLs (`https://example.com/about`) or paths (`/about`).
405
+ * Paths are resolved against `http://localhost` internally.
406
+ * @returns {URL[]} Array of URL objects representing all localized variants.
407
+ * The order follows each input URL with all its locale variants before moving to the next URL.
408
+ */
409
+ export function generateStaticLocalizedUrls(urls: (string | URL)[]): URL[];
410
+ /**
411
+ * Checks if the given strategy is a custom strategy.
412
+ *
413
+ * @param {unknown} strategy The name of the custom strategy to validate.
414
+ * Must be a string that starts with "custom-" followed by alphanumeric characters, hyphens, or underscores.
415
+ * @returns {boolean} Returns true if it is a custom strategy, false otherwise.
416
+ */
417
+ export function isCustomStrategy(strategy: unknown): boolean;
418
+ /**
419
+ * Defines a custom strategy that is executed on the server.
420
+ *
421
+ * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy#write-your-own-strategy
422
+ *
423
+ * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
424
+ * @param {CustomServerStrategyHandler} handler The handler for the custom strategy, which should implement
425
+ * the method getLocale.
426
+ * @returns {void}
427
+ */
428
+ export function defineCustomServerStrategy(strategy: string, handler: CustomServerStrategyHandler): void;
429
+ /**
430
+ * Defines a custom strategy that is executed on the client.
431
+ *
432
+ * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy#write-your-own-strategy
433
+ *
434
+ * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
435
+ * @param {CustomClientStrategyHandler} handler The handler for the custom strategy, which should implement the
436
+ * methods getLocale and setLocale.
437
+ * @returns {void}
438
+ */
439
+ export function defineCustomClientStrategy(strategy: string, handler: CustomClientStrategyHandler): void;
440
+ /**
441
+ * The project's base locale.
442
+ *
443
+ * @example
444
+ * if (locale === baseLocale) {
445
+ * // do something
446
+ * }
447
+ */
448
+ export const baseLocale: "en";
449
+ /**
450
+ * The project's locales that have been specified in the settings.
451
+ *
452
+ * @example
453
+ * if (locales.includes(userSelectedLocale) === false) {
454
+ * throw new Error('Locale is not available');
455
+ * }
456
+ */
457
+ export const locales: readonly ["af", "ar", "en", "en-GB", "en-US", "en-ZA", "es", "es-US", "fr", "fr-CA", "fr-FR"];
458
+ /** @type {string} */
459
+ export const cookieName: string;
460
+ /** @type {number} */
461
+ export const cookieMaxAge: number;
462
+ /** @type {string} */
463
+ export const cookieDomain: string;
464
+ /** @type {string} */
465
+ export const localStorageKey: string;
466
+ /**
467
+ * @type {Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>}
468
+ */
469
+ export const strategy: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
470
+ /**
471
+ * Route-level strategy overrides.
472
+ *
473
+ * `match` uses URLPattern syntax.
474
+ *
475
+ * @type {Array<{
476
+ * match: string;
477
+ * strategy?: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
478
+ * exclude?: boolean;
479
+ * }>}
480
+ */
481
+ export const routeStrategies: Array<{
482
+ match: string;
483
+ strategy?: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
484
+ exclude?: boolean;
485
+ }>;
486
+ /**
487
+ * The used URL patterns.
488
+ *
489
+ * @type {Array<{ pattern: string, localized: Array<[Locale, string]> }>}
490
+ */
491
+ export const urlPatterns: Array<{
492
+ pattern: string;
493
+ localized: Array<[Locale, string]>;
494
+ }>;
495
+ /**
496
+ * @typedef {{
497
+ * getStore(): {
498
+ * locale?: Locale,
499
+ * origin?: string,
500
+ * messageCalls?: Set<string>
501
+ * } | undefined,
502
+ * run: (store: { locale?: Locale, origin?: string, messageCalls?: Set<string>},
503
+ * cb: any) => any
504
+ * }} ParaglideAsyncLocalStorage
505
+ */
506
+ /**
507
+ * Server side async local storage that is set by `serverMiddleware()`.
508
+ *
509
+ * The variable is used to retrieve the locale and origin in a server-side
510
+ * rendering context without effecting other requests.
511
+ *
512
+ * @type {ParaglideAsyncLocalStorage | undefined}
513
+ */
514
+ export let serverAsyncLocalStorage: ParaglideAsyncLocalStorage | undefined;
515
+ export const disableAsyncLocalStorage: false;
516
+ export const experimentalMiddlewareLocaleSplitting: false;
517
+ export const isServer: boolean;
518
+ /** @type {Locale | undefined} */
519
+ export const experimentalStaticLocale: Locale | undefined;
520
+ export function getLocale(): Locale;
521
+ export function overwriteGetLocale(fn: () => Locale): void;
522
+ /**
523
+ * @typedef {(newLocale: Locale, options?: { reload?: boolean }) => void | Promise<void>} SetLocaleFn
524
+ */
525
+ /**
526
+ * Set the locale.
527
+ *
528
+ * Updates the locale using your configured strategies (cookie, localStorage, URL, etc.).
529
+ * By default, this reloads the page on the client to reflect the new locale. Reloading
530
+ * can be disabled by passing `reload: false` as an option, but you'll need to ensure
531
+ * the UI updates to reflect the new locale.
532
+ *
533
+ * If any custom strategy's `setLocale` function is async, then this function
534
+ * will become async as well.
535
+ *
536
+ * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy
537
+ *
538
+ * @example
539
+ * setLocale('en');
540
+ *
541
+ * @example
542
+ * setLocale('en', { reload: false });
543
+ *
544
+ * @type {SetLocaleFn}
545
+ */
546
+ export let setLocale: SetLocaleFn;
547
+ export function overwriteSetLocale(fn: SetLocaleFn): void;
548
+ /**
549
+ * The origin of the current URL.
550
+ *
551
+ * Defaults to "http://y.com" in non-browser environments. If this
552
+ * behavior is not desired, the implementation can be overwritten
553
+ * by `overwriteGetUrlOrigin()`.
554
+ *
555
+ * @type {() => string}
556
+ */
557
+ export let getUrlOrigin: () => string;
558
+ export function overwriteGetUrlOrigin(fn: () => string): void;
559
+ export function extractLocaleFromRequest(request: Request): Locale;
560
+ export function extractLocaleFromRequestWithStrategies(request: Request, strategies: typeof strategy): Locale;
561
+ export function extractLocaleFromRequestAsync(request: Request): Promise<Locale>;
562
+ /**
563
+ * @typedef {"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"} BuiltInStrategy
564
+ */
565
+ /**
566
+ * @typedef {`custom_${string}`} CustomStrategy
567
+ */
568
+ /**
569
+ * @typedef {BuiltInStrategy | CustomStrategy} Strategy
570
+ */
571
+ /**
572
+ * @typedef {Array<Strategy>} Strategies
573
+ */
574
+ /**
575
+ * @typedef {{ getLocale: (request?: Request) => Promise<string | undefined> | (string | undefined) }} CustomServerStrategyHandler
576
+ */
577
+ /**
578
+ * @typedef {{ getLocale: () => Promise<string|undefined> | (string | undefined), setLocale: (locale: string) => Promise<void> | void }} CustomClientStrategyHandler
579
+ */
580
+ /** @type {Map<string, CustomServerStrategyHandler>} */
581
+ export const customServerStrategies: Map<string, CustomServerStrategyHandler>;
582
+ /** @type {Map<string, CustomClientStrategyHandler>} */
583
+ export const customClientStrategies: Map<string, CustomClientStrategyHandler>;
584
+ export type ShouldRedirectServerInput = {
585
+ request: Request;
586
+ url?: string | URL | undefined;
587
+ locale?: "en-US" | "ar" | "en" | "af" | "en-GB" | "en-ZA" | "es" | "es-US" | "fr" | "fr-CA" | "fr-FR" | undefined;
588
+ };
589
+ export type ShouldRedirectClientInput = {
590
+ request?: undefined;
591
+ url?: string | URL | undefined;
592
+ locale?: "en-US" | "ar" | "en" | "af" | "en-GB" | "en-ZA" | "es" | "es-US" | "fr" | "fr-CA" | "fr-FR" | undefined;
593
+ };
594
+ export type ShouldRedirectInput = ShouldRedirectServerInput | ShouldRedirectClientInput;
595
+ export type ShouldRedirectResult = {
596
+ /**
597
+ * - Indicates whether the consumer should perform a redirect.
598
+ */
599
+ shouldRedirect: boolean;
600
+ /**
601
+ * - Locale resolved using the configured strategies.
602
+ */
603
+ locale: Locale;
604
+ /**
605
+ * - Destination URL when a redirect is required.
606
+ */
607
+ redirectUrl: URL | undefined;
608
+ };
609
+ export type ParaglideAsyncLocalStorage = {
610
+ getStore(): {
611
+ locale?: Locale;
612
+ origin?: string;
613
+ messageCalls?: Set<string>;
614
+ } | undefined;
615
+ run: (store: {
616
+ locale?: Locale;
617
+ origin?: string;
618
+ messageCalls?: Set<string>;
619
+ }, cb: any) => any;
620
+ };
621
+ export type SetLocaleFn = (newLocale: Locale, options?: {
622
+ reload?: boolean;
623
+ }) => void | Promise<void>;
624
+ export type BuiltInStrategy = "cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage";
625
+ export type CustomStrategy = `custom_${string}`;
626
+ export type Strategy = BuiltInStrategy | CustomStrategy;
627
+ export type Strategies = Array<Strategy>;
628
+ export type CustomServerStrategyHandler = {
629
+ getLocale: (request?: Request) => Promise<string | undefined> | (string | undefined);
630
+ };
631
+ export type CustomClientStrategyHandler = {
632
+ getLocale: () => Promise<string | undefined> | (string | undefined);
633
+ setLocale: (locale: string) => Promise<void> | void;
634
+ };
635
+ /**
636
+ * A locale that is available in the project.
637
+ */
638
+ export type Locale = (typeof locales)[number];
639
+ /**
640
+ * A branded type representing a localized string.
641
+ *
642
+ * Message functions return this type instead of \`string\`, enabling TypeScript
643
+ * to distinguish translated strings from regular strings at compile time.
644
+ * This allows you to enforce that only properly localized content is used
645
+ * in your UI components.
646
+ *
647
+ * Since \`LocalizedString\` is a branded subtype of \`string\`, it remains fully
648
+ * backward compatible—you can pass it anywhere a \`string\` is expected.
649
+ */
650
+ export type LocalizedString = string & {
651
+ readonly __brand: "LocalizedString";
652
+ };
653
+ /**
654
+ * A single markup option passed to a tag instance.
655
+ */
656
+ export type MessageMarkupOption = {
657
+ name: string;
658
+ value: unknown;
659
+ };
660
+ /**
661
+ * A single static markup attribute attached to a tag instance.
662
+ */
663
+ export type MessageMarkupAttribute = {
664
+ name: string;
665
+ value: string | true;
666
+ };
667
+ /**
668
+ * Record of markup options for a tag instance.
669
+ */
670
+ export type MessageMarkupOptions = Record<string, unknown>;
671
+ /**
672
+ * Record of markup attributes for a tag instance.
673
+ */
674
+ export type MessageMarkupAttributes = Record<string, string | true>;
675
+ /**
676
+ * Type-level schema for a single markup tag.
677
+ */
678
+ export type MessageMarkupTag = {
679
+ options: MessageMarkupOptions;
680
+ attributes: MessageMarkupAttributes;
681
+ children: boolean;
682
+ };
683
+ /**
684
+ * Type-level schema for all markup tags in a message.
685
+ */
686
+ export type MessageMarkupSchema = Record<string, MessageMarkupTag>;
687
+ /**
688
+ * Type-only metadata attached to compiled message functions.
689
+ */
690
+ export type MessageMetadata<Inputs, Options, Markup extends MessageMarkupSchema = MessageMarkupSchema> = {
691
+ readonly __paraglide?: {
692
+ inputs: Inputs;
693
+ options: Options;
694
+ markup: Markup;
695
+ };
696
+ };
697
+ /**
698
+ * A compiled, framework-neutral message part.
699
+ */
700
+ export type MessagePart = {
701
+ type: "text";
702
+ value: string;
703
+ } | {
704
+ type: "markup-start";
705
+ name: string;
706
+ options: MessageMarkupOptions;
707
+ attributes: MessageMarkupAttributes;
708
+ } | {
709
+ type: "markup-end";
710
+ name: string;
711
+ options: MessageMarkupOptions;
712
+ attributes: MessageMarkupAttributes;
713
+ } | {
714
+ type: "markup-standalone";
715
+ name: string;
716
+ options: MessageMarkupOptions;
717
+ attributes: MessageMarkupAttributes;
718
+ };
719
+ /**
720
+ * A message function is a message for a specific locale.
721
+ */
722
+ export type MessageFunction = (inputs?: Record<string, never>) => LocalizedString;
723
+ /**
724
+ * A message bundle function that selects the message to be returned.
725
+ *
726
+ * Uses `getLocale()` under the hood to determine the locale with an option.
727
+ */
728
+ export type MessageBundleFunction<T extends string> = (params: Record<string, never>, options: {
729
+ locale: T;
730
+ }) => LocalizedString;
731
+ //# sourceMappingURL=runtime.d.ts.map