@turnipxenon/pineapple 4.5.0-alpha.1 → 4.5.0-alpha.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.
@@ -0,0 +1,3 @@
1
+ # ignore everything because the directory is auto-generated by inlang paraglide-js
2
+ # for more info visit https://inlang.com/m/gerre34r/paraglide-js
3
+ *
@@ -0,0 +1,2 @@
1
+ export * from "./example_message.js";
2
+ export * from "./settings.js";
@@ -0,0 +1,3 @@
1
+ // eslint-disable
2
+ export * from './example_message.js'
3
+ export * from './settings.js'
@@ -0,0 +1,5 @@
1
+ export function example_message(inputs: {
2
+ username: NonNullable<unknown>;
3
+ }, options?: {
4
+ locale?: "en" | "fr" | "tl";
5
+ }): string;
@@ -0,0 +1,39 @@
1
+ // eslint-disable
2
+ import { getLocale, trackMessageCall, experimentalMiddlewareLocaleSplitting, isServer } from '../runtime.js';
3
+
4
+ const en_example_message = /** @type {(inputs: { username: NonNullable<unknown> }) => string} */ (i) => {
5
+ return `Hello world ${i.username}`
6
+ };
7
+
8
+ const fr_example_message = /** @type {(inputs: { username: NonNullable<unknown> }) => string} */ (i) => {
9
+ return `Bonjour ${i.username}`
10
+ };
11
+
12
+ const tl_example_message = /** @type {(inputs: { username: NonNullable<unknown> }) => string} */ (i) => {
13
+ return `Kamusta ${i.username}`
14
+ };
15
+
16
+ /**
17
+ * This function has been compiled by [Paraglide JS](https://inlang.com/m/gerre34r).
18
+ *
19
+ * - Changing this function will be over-written by the next build.
20
+ *
21
+ * - If you want to change the translations, you can either edit the source files e.g. `en.json`, or
22
+ * use another inlang app like [Fink](https://inlang.com/m/tdozzpar) or the [VSCode extension Sherlock](https://inlang.com/m/r7kp499g).
23
+ *
24
+ * @param {{ username: NonNullable<unknown> }} inputs
25
+ * @param {{ locale?: "en" | "fr" | "tl" }} options
26
+ * @returns {string}
27
+ */
28
+ /* @__NO_SIDE_EFFECTS__ */
29
+ export const example_message = (inputs, options = {}) => {
30
+ if (experimentalMiddlewareLocaleSplitting && isServer === false) {
31
+ return /** @type {any} */ (globalThis).__paraglide_ssr.example_message(inputs)
32
+ }
33
+ const locale = options.locale ?? getLocale()
34
+ trackMessageCall("example_message", locale)
35
+ if (locale === "en") return en_example_message(inputs)
36
+ if (locale === "fr") return fr_example_message(inputs)
37
+ if (locale === "tl") return tl_example_message(inputs)
38
+ return "example_message"
39
+ };
@@ -0,0 +1,3 @@
1
+ export function settings(inputs?: {}, options?: {
2
+ locale?: "en" | "fr" | "tl";
3
+ }): string;
@@ -0,0 +1,38 @@
1
+ // eslint-disable
2
+ import { getLocale, trackMessageCall, experimentalMiddlewareLocaleSplitting, isServer } from '../runtime.js';
3
+
4
+ const en_settings = /** @type {(inputs: {}) => string} */ () => {
5
+ return `Settings`
6
+ };
7
+
8
+ const fr_settings = /** @type {(inputs: {}) => string} */ () => {
9
+ return `Paramètres`
10
+ };
11
+
12
+ /** @type {(inputs: {}) => string} */
13
+ const tl_settings = en_settings;
14
+
15
+ /**
16
+ * This function has been compiled by [Paraglide JS](https://inlang.com/m/gerre34r).
17
+ *
18
+ * - Changing this function will be over-written by the next build.
19
+ *
20
+ * - If you want to change the translations, you can either edit the source files e.g. `en.json`, or
21
+ * use another inlang app like [Fink](https://inlang.com/m/tdozzpar) or the [VSCode extension Sherlock](https://inlang.com/m/r7kp499g).
22
+ *
23
+ * @param {{}} inputs
24
+ * @param {{ locale?: "en" | "fr" | "tl" }} options
25
+ * @returns {string}
26
+ */
27
+ /* @__NO_SIDE_EFFECTS__ */
28
+ export const settings = (inputs = {}, options = {}) => {
29
+ if (experimentalMiddlewareLocaleSplitting && isServer === false) {
30
+ return /** @type {any} */ (globalThis).__paraglide_ssr.settings(inputs)
31
+ }
32
+ const locale = options.locale ?? getLocale()
33
+ trackMessageCall("settings", locale)
34
+ if (locale === "en") return en_settings(inputs)
35
+ if (locale === "fr") return fr_settings(inputs)
36
+ if (locale === "tl") return tl_settings(inputs)
37
+ return "settings"
38
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./messages/_index.js";
2
+ export * as m from "./messages/_index.js";
@@ -0,0 +1,4 @@
1
+ // eslint-disable
2
+ export * from './messages/_index.js'
3
+ // enabling auto-import by exposing all messages as m
4
+ export * as m from './messages/_index.js'
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @param {import("./runtime.js").Locale} locale
3
+ * @param {unknown} input
4
+ * @param {Intl.PluralRulesOptions} [options]
5
+ * @returns {string}
6
+ */
7
+ export function plural(locale: import("./runtime.js").Locale, input: unknown, options?: Intl.PluralRulesOptions): string;
8
+ /**
9
+ * @param {import("./runtime.js").Locale} locale
10
+ * @param {unknown} input
11
+ * @param {Intl.NumberFormatOptions} [options]
12
+ * @returns {string}
13
+ */
14
+ export function number(locale: import("./runtime.js").Locale, input: unknown, options?: Intl.NumberFormatOptions): string;
15
+ /**
16
+ * @param {import("./runtime.js").Locale} locale
17
+ * @param {unknown} input
18
+ * @param {Intl.DateTimeFormatOptions} [options]
19
+ * @returns {string}
20
+ */
21
+ export function datetime(locale: import("./runtime.js").Locale, input: unknown, options?: Intl.DateTimeFormatOptions): string;
@@ -0,0 +1,31 @@
1
+ // eslint-disable
2
+
3
+ /**
4
+ * @param {import("./runtime.js").Locale} locale
5
+ * @param {unknown} input
6
+ * @param {Intl.PluralRulesOptions} [options]
7
+ * @returns {string}
8
+ */
9
+ export function plural(locale, input, options) {
10
+ return new Intl.PluralRules(locale, options).select(Number(input))
11
+ };
12
+
13
+ /**
14
+ * @param {import("./runtime.js").Locale} locale
15
+ * @param {unknown} input
16
+ * @param {Intl.NumberFormatOptions} [options]
17
+ * @returns {string}
18
+ */
19
+ export function number(locale, input, options) {
20
+ return new Intl.NumberFormat(locale, options).format(Number(input))
21
+ };
22
+
23
+ /**
24
+ * @param {import("./runtime.js").Locale} locale
25
+ * @param {unknown} input
26
+ * @param {Intl.DateTimeFormatOptions} [options]
27
+ * @returns {string}
28
+ */
29
+ export function datetime(locale, input, options) {
30
+ return new Intl.DateTimeFormat(locale, options).format(new Date(/** @type {string} */ (input)))
31
+ };
@@ -0,0 +1,400 @@
1
+ /**
2
+ * Sets the server side async local storage.
3
+ *
4
+ * The function is needed because the `runtime.js` file
5
+ * must define the `serverAsyncLocalStorage` variable to
6
+ * avoid a circular import between `runtime.js` and
7
+ * `server.js` files.
8
+ *
9
+ * @param {ParaglideAsyncLocalStorage | undefined} value
10
+ */
11
+ export function overwriteServerAsyncLocalStorage(value: ParaglideAsyncLocalStorage | undefined): void;
12
+ /**
13
+ * Check if something is an available locale.
14
+ *
15
+ * @example
16
+ * if (isLocale(params.locale)) {
17
+ * setLocale(params.locale);
18
+ * } else {
19
+ * setLocale('en');
20
+ * }
21
+ *
22
+ * @param {any} locale
23
+ * @returns {locale is Locale}
24
+ */
25
+ export function isLocale(locale: any): locale is Locale;
26
+ /**
27
+ * Asserts that the input is a locale.
28
+ *
29
+ * @param {any} input - The input to check.
30
+ * @returns {Locale} The input if it is a locale.
31
+ * @throws {Error} If the input is not a locale.
32
+ */
33
+ export function assertIsLocale(input: any): Locale;
34
+ /**
35
+ * Extracts a cookie from the document.
36
+ *
37
+ * Will return undefined if the docuement is not available or if the cookie is not set.
38
+ * The `document` object is not available in server-side rendering, so this function should not be called in that context.
39
+ *
40
+ * @returns {string | undefined}
41
+ */
42
+ export function extractLocaleFromCookie(): string | undefined;
43
+ /**
44
+ * Extracts the locale from a given URL using native URLPattern.
45
+ *
46
+ * @param {URL|string} url - The full URL from which to extract the locale.
47
+ * @returns {Locale|undefined} The extracted locale, or undefined if no locale is found.
48
+ */
49
+ export function extractLocaleFromUrl(url: URL | string): Locale | undefined;
50
+ /**
51
+ * Lower-level URL localization function, primarily used in server contexts.
52
+ *
53
+ * This function is designed for server-side usage where you need precise control
54
+ * over URL localization, such as in middleware or request handlers. It works with
55
+ * URL objects and always returns absolute URLs.
56
+ *
57
+ * For client-side UI components, use `localizeHref()` instead, which provides
58
+ * a more convenient API with relative paths and automatic locale detection.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * // Server middleware example
63
+ * app.use((req, res, next) => {
64
+ * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
65
+ * const localized = localizeUrl(url, { locale: "de" });
66
+ *
67
+ * if (localized.href !== url.href) {
68
+ * return res.redirect(localized.href);
69
+ * }
70
+ * next();
71
+ * });
72
+ * ```
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * // Using with URL patterns
77
+ * const url = new URL("https://example.com/about");
78
+ * localizeUrl(url, { locale: "de" });
79
+ * // => URL("https://example.com/de/about")
80
+ *
81
+ * // Using with domain-based localization
82
+ * const url = new URL("https://example.com/store");
83
+ * localizeUrl(url, { locale: "de" });
84
+ * // => URL("https://de.example.com/store")
85
+ * ```
86
+ *
87
+ * @param {string | URL} url - The URL to localize. If string, must be absolute.
88
+ * @param {Object} [options] - Options for localization
89
+ * @param {string} [options.locale] - Target locale. If not provided, uses getLocale()
90
+ * @returns {URL} The localized URL, always absolute
91
+ */
92
+ export function localizeUrl(url: string | URL, options?: {
93
+ locale?: string | undefined;
94
+ }): URL;
95
+ /**
96
+ * Low-level URL de-localization function, primarily used in server contexts.
97
+ *
98
+ * This function is designed for server-side usage where you need precise control
99
+ * over URL de-localization, such as in middleware or request handlers. It works with
100
+ * URL objects and always returns absolute URLs.
101
+ *
102
+ * For client-side UI components, use `deLocalizeHref()` instead, which provides
103
+ * a more convenient API with relative paths.
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * // Server middleware example
108
+ * app.use((req, res, next) => {
109
+ * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
110
+ * const baseUrl = deLocalizeUrl(url);
111
+ *
112
+ * // Store the base URL for later use
113
+ * req.baseUrl = baseUrl;
114
+ * next();
115
+ * });
116
+ * ```
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * // Using with URL patterns
121
+ * const url = new URL("https://example.com/de/about");
122
+ * deLocalizeUrl(url); // => URL("https://example.com/about")
123
+ *
124
+ * // Using with domain-based localization
125
+ * const url = new URL("https://de.example.com/store");
126
+ * deLocalizeUrl(url); // => URL("https://example.com/store")
127
+ * ```
128
+ *
129
+ * @param {string | URL} url - The URL to de-localize. If string, must be absolute.
130
+ * @returns {URL} The de-localized URL, always absolute
131
+ */
132
+ export function deLocalizeUrl(url: string | URL): URL;
133
+ export function aggregateGroups(match: any): Record<string, string | null | undefined>;
134
+ /**
135
+ * High-level URL localization function optimized for client-side UI usage.
136
+ *
137
+ * This is a convenience wrapper around `localizeUrl()` that provides features
138
+ * needed in UI:
139
+ *
140
+ * - Accepts relative paths (e.g., "/about")
141
+ * - Returns relative paths when possible
142
+ * - Automatically detects current locale if not specified
143
+ * - Handles string input/output instead of URL objects
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * // In a React/Vue/Svelte component
148
+ * const NavLink = ({ href }) => {
149
+ * // Automatically uses current locale, keeps path relative
150
+ * return <a href={localizeHref(href)}>...</a>;
151
+ * };
152
+ *
153
+ * // Examples:
154
+ * localizeHref("/about")
155
+ * // => "/de/about" (if current locale is "de")
156
+ * localizeHref("/store", { locale: "fr" })
157
+ * // => "/fr/store" (explicit locale)
158
+ *
159
+ * // Cross-origin links remain absolute
160
+ * localizeHref("https://other-site.com/about")
161
+ * // => "https://other-site.com/de/about"
162
+ * ```
163
+ *
164
+ * For server-side URL localization (e.g., in middleware), use `localizeUrl()`
165
+ * which provides more precise control over URL handling.
166
+ *
167
+ * @param {string} href - The href to localize (can be relative or absolute)
168
+ * @param {Object} [options] - Options for localization
169
+ * @param {string} [options.locale] - Target locale. If not provided, uses `getLocale()`
170
+ * @returns {string} The localized href, relative if input was relative
171
+ */
172
+ export function localizeHref(href: string, options?: {
173
+ locale?: string | undefined;
174
+ }): string;
175
+ /**
176
+ * High-level URL de-localization function optimized for client-side UI usage.
177
+ *
178
+ * This is a convenience wrapper around `deLocalizeUrl()` that provides features
179
+ * needed in the UI:
180
+ *
181
+ * - Accepts relative paths (e.g., "/de/about")
182
+ * - Returns relative paths when possible
183
+ * - Handles string input/output instead of URL objects
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * // In a React/Vue/Svelte component
188
+ * const LocaleSwitcher = ({ href }) => {
189
+ * // Remove locale prefix before switching
190
+ * const baseHref = deLocalizeHref(href);
191
+ * return locales.map(locale =>
192
+ * <a href={localizeHref(baseHref, { locale })}>
193
+ * Switch to {locale}
194
+ * </a>
195
+ * );
196
+ * };
197
+ *
198
+ * // Examples:
199
+ * deLocalizeHref("/de/about") // => "/about"
200
+ * deLocalizeHref("/fr/store") // => "/store"
201
+ *
202
+ * // Cross-origin links remain absolute
203
+ * deLocalizeHref("https://example.com/de/about")
204
+ * // => "https://example.com/about"
205
+ * ```
206
+ *
207
+ * For server-side URL de-localization (e.g., in middleware), use `deLocalizeUrl()`
208
+ * which provides more precise control over URL handling.
209
+ *
210
+ * @param {string} href - The href to de-localize (can be relative or absolute)
211
+ * @returns {string} The de-localized href, relative if input was relative
212
+ * @see deLocalizeUrl - For low-level URL de-localization in server contexts
213
+ */
214
+ export function deLocalizeHref(href: string): string;
215
+ /**
216
+ * @param {string} safeModuleId
217
+ * @param {Locale} locale
218
+ */
219
+ export function trackMessageCall(safeModuleId: string, locale: Locale): void;
220
+ /**
221
+ * Generates a list of localized URLs for all provided URLs.
222
+ *
223
+ * This is useful for SSG (Static Site Generation) and sitemap generation.
224
+ * NextJS and other frameworks use this function for SSG.
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * const urls = generateStaticLocalizedUrls([
229
+ * "https://example.com/about",
230
+ * "https://example.com/blog",
231
+ * ]);
232
+ * urls[0].href // => "https://example.com/about"
233
+ * urls[1].href // => "https://example.com/blog"
234
+ * urls[2].href // => "https://example.com/de/about"
235
+ * urls[3].href // => "https://example.com/de/blog"
236
+ * ...
237
+ * ```
238
+ *
239
+ * @param {(string | URL)[]} urls - List of URLs to generate localized versions for. Can be absolute URLs or paths.
240
+ * @returns {URL[]} List of localized URLs as URL objects
241
+ */
242
+ export function generateStaticLocalizedUrls(urls: (string | URL)[]): URL[];
243
+ /**
244
+ * The project's base locale.
245
+ *
246
+ * @example
247
+ * if (locale === baseLocale) {
248
+ * // do something
249
+ * }
250
+ */
251
+ export const baseLocale: "en";
252
+ /**
253
+ * The project's locales that have been specified in the settings.
254
+ *
255
+ * @example
256
+ * if (locales.includes(userSelectedLocale) === false) {
257
+ * throw new Error('Locale is not available');
258
+ * }
259
+ */
260
+ export const locales: readonly ["en", "fr", "tl"];
261
+ /** @type {string} */
262
+ export const cookieName: string;
263
+ /** @type {string} */
264
+ export const localStorageKey: string;
265
+ /**
266
+ * @type {Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage">}
267
+ */
268
+ export const strategy: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage">;
269
+ /**
270
+ * The used URL patterns.
271
+ *
272
+ * @type {Array<{ pattern: string, localized: Array<[Locale, string]> }> }
273
+ */
274
+ export const urlPatterns: Array<{
275
+ pattern: string;
276
+ localized: Array<[Locale, string]>;
277
+ }>;
278
+ /**
279
+ * @typedef {{
280
+ * getStore(): {
281
+ * locale?: Locale,
282
+ * origin?: string,
283
+ * messageCalls?: Set<string>
284
+ * } | undefined,
285
+ * run: (store: { locale?: Locale, origin?: string, messageCalls?: Set<string>},
286
+ * cb: any) => any
287
+ * }} ParaglideAsyncLocalStorage
288
+ */
289
+ /**
290
+ * Server side async local storage that is set by `serverMiddleware()`.
291
+ *
292
+ * The variable is used to retrieve the locale and origin in a server-side
293
+ * rendering context without effecting other requests.
294
+ *
295
+ * @type {ParaglideAsyncLocalStorage | undefined}
296
+ */
297
+ export let serverAsyncLocalStorage: ParaglideAsyncLocalStorage | undefined;
298
+ export const disableAsyncLocalStorage: false;
299
+ export const experimentalMiddlewareLocaleSplitting: false;
300
+ export const isServer: boolean;
301
+ /**
302
+ * Get the current locale.
303
+ *
304
+ * @example
305
+ * if (getLocale() === 'de') {
306
+ * console.log('Germany 🇩🇪');
307
+ * } else if (getLocale() === 'nl') {
308
+ * console.log('Netherlands 🇳🇱');
309
+ * }
310
+ *
311
+ * @type {() => Locale}
312
+ */
313
+ export let getLocale: () => Locale;
314
+ /**
315
+ * Overwrite the \`getLocale()\` function.
316
+ *
317
+ * Use this function to overwrite how the locale is resolved. For example,
318
+ * you can resolve the locale from the browser's preferred language,
319
+ * a cookie, env variable, or a user's preference.
320
+ *
321
+ * @example
322
+ * overwriteGetLocale(() => {
323
+ * // resolve the locale from a cookie. fallback to the base locale.
324
+ * return Cookies.get('locale') ?? baseLocale
325
+ * }
326
+ *
327
+ * @type {(fn: () => Locale) => void}
328
+ */
329
+ export const overwriteGetLocale: (fn: () => Locale) => void;
330
+ /**
331
+ * Set the locale.
332
+ *
333
+ * Set locale reloads the site by default on the client. Reloading
334
+ * can be disabled by passing \`reload: false\` as an option. If
335
+ * reloading is disbaled, you need to ensure that the UI is updated
336
+ * to reflect the new locale.
337
+ *
338
+ * @example
339
+ * setLocale('en');
340
+ *
341
+ * @example
342
+ * setLocale('en', { reload: false });
343
+ *
344
+ * @type {(newLocale: Locale, options?: { reload?: boolean }) => void}
345
+ */
346
+ export let setLocale: (newLocale: Locale, options?: {
347
+ reload?: boolean;
348
+ }) => void;
349
+ export function overwriteSetLocale(fn: (newLocale: Locale) => void): void;
350
+ /**
351
+ * The origin of the current URL.
352
+ *
353
+ * Defaults to "http://y.com" in non-browser environments. If this
354
+ * behavior is not desired, the implementation can be overwritten
355
+ * by `overwriteGetUrlOrigin()`.
356
+ *
357
+ * @type {() => string}
358
+ */
359
+ export let getUrlOrigin: () => string;
360
+ /**
361
+ * Overwrite the getUrlOrigin function.
362
+ *
363
+ * Use this function in server environments to
364
+ * define how the URL origin is resolved.
365
+ *
366
+ * @type {(fn: () => string) => void}
367
+ */
368
+ export let overwriteGetUrlOrigin: (fn: () => string) => void;
369
+ /**
370
+ * Extracts a locale from a request.
371
+ *
372
+ * Use the function on the server to extract the locale
373
+ * from a request.
374
+ *
375
+ * The function goes through the strategies in the order
376
+ * they are defined. If a strategy returns an invalid locale,
377
+ * it will fall back to the next strategy.
378
+ *
379
+ * @example
380
+ * const locale = extractLocaleFromRequest(request);
381
+ *
382
+ * @type {(request: Request) => Locale}
383
+ */
384
+ export const extractLocaleFromRequest: (request: Request) => Locale;
385
+ export type ParaglideAsyncLocalStorage = {
386
+ getStore(): {
387
+ locale?: Locale;
388
+ origin?: string;
389
+ messageCalls?: Set<string>;
390
+ } | undefined;
391
+ run: (store: {
392
+ locale?: Locale;
393
+ origin?: string;
394
+ messageCalls?: Set<string>;
395
+ }, cb: any) => any;
396
+ };
397
+ /**
398
+ * A locale that is available in the project.
399
+ */
400
+ export type Locale = (typeof locales)[number];