@lukso/core 0.1.0-dev.a8c9315 → 0.1.0-dev.c785f65
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/{chunk-25O35V5J.js → chunk-6QJEVD4O.js} +2 -2
- package/dist/{chunk-BAVNEYR7.js → chunk-SOMU2QZE.js} +33 -4
- package/dist/chunk-SOMU2QZE.js.map +1 -0
- package/dist/{chunk-75FLRXXN.cjs → chunk-WZIEEMOM.cjs} +7 -7
- package/dist/{chunk-75FLRXXN.cjs.map → chunk-WZIEEMOM.cjs.map} +1 -1
- package/dist/{chunk-UOLYOGEV.cjs → chunk-XOL2VVVB.cjs} +34 -5
- package/dist/chunk-XOL2VVVB.cjs.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.js +2 -2
- package/dist/mixins/index.cjs +3 -3
- package/dist/mixins/index.js +2 -2
- package/dist/mixins/intl.cjs +3 -3
- package/dist/mixins/intl.js +2 -2
- package/dist/services/index.cjs +2 -2
- package/dist/services/index.js +1 -1
- package/dist/services/intl.cjs +2 -2
- package/dist/services/intl.d.cts +19 -3
- package/dist/services/intl.d.ts +19 -3
- package/dist/services/intl.js +1 -1
- package/package.json +1 -1
- package/src/services/__tests__/intl.spec.ts +8 -0
- package/src/services/intl.ts +56 -5
- package/dist/chunk-BAVNEYR7.js.map +0 -1
- package/dist/chunk-UOLYOGEV.cjs.map +0 -1
- /package/dist/{chunk-25O35V5J.js.map → chunk-6QJEVD4O.js.map} +0 -0
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
defaultConfig,
|
|
4
4
|
getIntlService,
|
|
5
5
|
setIntlService
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-SOMU2QZE.js";
|
|
7
7
|
|
|
8
8
|
// src/mixins/intl.ts
|
|
9
9
|
import { effect } from "@preact/signals-core";
|
|
@@ -84,4 +84,4 @@ function withIntlService(Base) {
|
|
|
84
84
|
export {
|
|
85
85
|
withIntlService
|
|
86
86
|
};
|
|
87
|
-
//# sourceMappingURL=chunk-
|
|
87
|
+
//# sourceMappingURL=chunk-6QJEVD4O.js.map
|
|
@@ -8,11 +8,30 @@ var formatNumberDefaultOptions = {
|
|
|
8
8
|
};
|
|
9
9
|
var defaultConfig = {
|
|
10
10
|
locale: "en-US",
|
|
11
|
-
messages: {}
|
|
11
|
+
messages: {},
|
|
12
|
+
formats: {
|
|
13
|
+
date: {
|
|
14
|
+
shortDateTime: {
|
|
15
|
+
weekday: "short",
|
|
16
|
+
// Wed
|
|
17
|
+
month: "short",
|
|
18
|
+
// Dec
|
|
19
|
+
day: "numeric",
|
|
20
|
+
// 3
|
|
21
|
+
year: "numeric",
|
|
22
|
+
// 2025
|
|
23
|
+
hour: "2-digit",
|
|
24
|
+
// 16
|
|
25
|
+
minute: "2-digit",
|
|
26
|
+
// 07
|
|
27
|
+
hour12: false
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
12
31
|
};
|
|
13
32
|
var intlService = null;
|
|
14
33
|
function createIntlService(config = defaultConfig) {
|
|
15
|
-
let currentConfig = config;
|
|
34
|
+
let currentConfig = { ...defaultConfig, ...config };
|
|
16
35
|
let intl = createIntl({ ...currentConfig, defaultLocale: "en-US" });
|
|
17
36
|
const localeChanged = signal(0);
|
|
18
37
|
let fallbackMessages = {};
|
|
@@ -51,7 +70,17 @@ function createIntlService(config = defaultConfig) {
|
|
|
51
70
|
formatTimestamp: (timestamp, options) => {
|
|
52
71
|
if (!timestamp) return "";
|
|
53
72
|
const time = typeof timestamp === "string" ? Number(timestamp) : timestamp;
|
|
54
|
-
const date = new Date(time * 1e3);
|
|
73
|
+
const date = time < 1e10 ? new Date(time * 1e3) : new Date(time);
|
|
74
|
+
if (typeof options === "string") {
|
|
75
|
+
const dateTimeOptions = currentConfig.formats?.date?.[options];
|
|
76
|
+
if (dateTimeOptions) {
|
|
77
|
+
return new Intl.DateTimeFormat(
|
|
78
|
+
currentConfig.locale,
|
|
79
|
+
dateTimeOptions
|
|
80
|
+
).format(date);
|
|
81
|
+
}
|
|
82
|
+
return intl.formatDate(date) || "";
|
|
83
|
+
}
|
|
55
84
|
return intl.formatDate(date, options) || "";
|
|
56
85
|
},
|
|
57
86
|
setLocale: (locale, messages) => {
|
|
@@ -92,4 +121,4 @@ export {
|
|
|
92
121
|
getIntlService,
|
|
93
122
|
clearIntlService
|
|
94
123
|
};
|
|
95
|
-
//# sourceMappingURL=chunk-
|
|
124
|
+
//# sourceMappingURL=chunk-SOMU2QZE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/intl.ts"],"sourcesContent":["/**\n * Internationalization Service\n *\n * Provides locale-aware formatting for messages, numbers, dates, and times.\n */\n\nimport {\n createIntl,\n type FormatNumberOptions,\n type IntlConfig,\n} from '@formatjs/intl'\nimport { signal } from '@preact/signals-core'\n\nexport type TimestampFormat = 'shortDateTime'\n\n/**\n * Default format number options\n * @see https://github.com/formatjs/formatjs/blob/main/packages/ecma402-abstract/types/number.ts\n */\nconst formatNumberDefaultOptions = {\n maximumFractionDigits: 18,\n}\n\n/**\n * Intl service interface\n */\nexport interface IntlService {\n /**\n * Translate a string based on the key\n *\n * @param key - translation key\n * @param options - optional options for formatMessage (for variable interpolation)\n * @returns - translated string\n */\n formatMessage: (key: string, options?: Record<string, string>) => string\n\n /**\n * Number formatting based on the locale\n *\n * @param value - number to format\n * @param options - options for formatNumber\n * @returns - formatted number\n */\n formatNumber: (\n value: number | string | bigint,\n options?: FormatNumberOptions\n ) => string\n\n /**\n * Date formatting based on the locale\n *\n * @param date - date to format\n * @returns - formatted date\n */\n formatDate: (date?: string | number | Date) => string | undefined\n\n /**\n * Time formatting based on the locale\n *\n * @param date - date to format\n * @returns - formatted time\n */\n formatTime: (date?: string | number | Date) => string | undefined\n\n /**\n * Timestamp formatting based on the locale\n *\n * @param timestamp - UNIX timestamp in seconds or milliseconds\n * @param options - formatting options (predefined format name or custom Intl.DateTimeFormat options)\n * @returns - formatted date & time string\n *\n * @example\n * ```typescript\n * const intl = getIntlService();\n *\n * // Use predefined shortDateTime format\n * intl.formatTimestamp(1733251200, 'shortDateTime'); // \"Wed, Dec 3, 2025, 16:07\"\n *\n * // Use custom format options\n * intl.formatTimestamp(1733251200, { year: '2-digit', month: '2-digit', day: '2-digit' });\n * // \"12/03/25\"\n *\n * // No options (basic format)\n * intl.formatTimestamp(1733251200);\n * ```\n */\n formatTimestamp: (\n timestamp?: number | string,\n options?: TimestampFormat | Intl.DateTimeFormatOptions\n ) => string\n\n /**\n * Change the locale and optionally update messages\n *\n * @param locale - new locale code (e.g., 'en-US', 'de-DE')\n * @param messages - optional new messages object for the locale\n */\n setLocale: (locale: string, messages?: Record<string, string>) => void\n\n /**\n * Get the current locale\n *\n * @returns - current locale code (e.g., 'en-US', 'de-DE')\n */\n getLocale: () => string\n\n /**\n * Set fallback translations to use when a translation key is missing\n * Useful when the host app's intl service doesn't have all translations\n *\n * @param fallbackMessages - translations to use as fallback\n *\n * @example\n * ```typescript\n * // After intl service is initialized by host app\n * intl.setFallbackTranslations(defaultMessages);\n * ```\n */\n setFallbackTranslations: (fallbackMessages: Record<string, string>) => void\n\n /**\n * Signal that tracks locale changes\n * Use this signal to reactively update UI when locale changes\n */\n localeChanged: { value: number }\n}\n\n/**\n * Default configuration for intl\n */\nexport const defaultConfig: IntlConfig = {\n locale: 'en-US',\n messages: {},\n formats: {\n date: {\n shortDateTime: {\n weekday: 'short', // Wed\n month: 'short', // Dec\n day: 'numeric', // 3\n year: 'numeric', // 2025\n hour: '2-digit', // 16\n minute: '2-digit', // 07\n hour12: false,\n },\n },\n },\n}\n\n/**\n * Global intl service instance\n */\nlet intlService: IntlService | null = null\n\n/**\n * Create a new intl service instance\n *\n * @param config - intl configuration with locale and messages\n * @returns IntlService instance with formatting methods\n *\n * @example\n * ```typescript\n * import { createIntlService } from '@lukso/core/services/intl';\n *\n * const intl = createIntlService({\n * locale: 'en-US',\n * messages: customMessages,\n * });\n *\n * const translated = intl.formatMessage('app.title');\n * const formatted = intl.formatNumber(1234.56);\n * const currentLocale = intl.getLocale(); // 'en-US'\n *\n * // Change locale\n * intl.setLocale('de-DE', germanMessages);\n * console.log(intl.getLocale()); // 'de-DE'\n * ```\n */\nexport function createIntlService(\n config: IntlConfig = defaultConfig\n): IntlService {\n let currentConfig = { ...defaultConfig, ...config }\n let intl = createIntl({ ...currentConfig, defaultLocale: 'en-US' })\n const localeChanged = signal(0)\n let fallbackMessages: Record<string, string> = {}\n\n return {\n formatMessage: (key: string, options?: Record<string, string>): string => {\n try {\n const result = intl.formatMessage({ id: key }, options)\n\n if (result && result !== key) {\n return result\n }\n\n // If no translation found, check fallback\n if (fallbackMessages[key]) {\n return fallbackMessages[key]\n }\n\n return key\n } catch {\n // On error, try fallback\n return fallbackMessages[key] || key\n }\n },\n\n formatNumber: (\n value: number | string | bigint,\n options: FormatNumberOptions = {}\n ): string => {\n if (value === null || value === undefined) {\n return '0'\n }\n\n const _value =\n typeof value === 'string' ? Number.parseFloat(value) : value\n\n const mergedOptions = {\n ...formatNumberDefaultOptions,\n ...options,\n }\n\n return intl.formatNumber(_value as number, mergedOptions) || ''\n },\n\n formatDate: (date?: string | number | Date): string => {\n return intl.formatDate(date)\n },\n\n formatTime: (date?: string | number | Date): string => {\n return intl.formatTime(date)\n },\n\n formatTimestamp: (\n timestamp?: number | string,\n options?: TimestampFormat | Intl.DateTimeFormatOptions\n ): string => {\n if (!timestamp) return ''\n\n const time = typeof timestamp === 'string' ? Number(timestamp) : timestamp\n const date =\n time < 10_000_000_000\n ? new Date(time * 1000) // seconds\n : new Date(time) // milliseconds\n\n // Handle predefined format\n if (typeof options === 'string') {\n const dateTimeOptions = currentConfig.formats?.date?.[\n options as TimestampFormat\n ] as Intl.DateTimeFormatOptions\n\n if (dateTimeOptions) {\n return new Intl.DateTimeFormat(\n currentConfig.locale,\n dateTimeOptions\n ).format(date)\n }\n\n // Fallback to default format if predefined format not found\n return intl.formatDate(date) || ''\n }\n\n // For normal @formatjs/intl options\n return intl.formatDate(date, options) || ''\n },\n\n setLocale: (locale: string, messages?: Record<string, string>): void => {\n currentConfig = {\n ...currentConfig,\n locale,\n messages: messages || currentConfig.messages,\n }\n intl = createIntl({\n ...currentConfig,\n defaultLocale: 'en-US',\n })\n localeChanged.value += 1\n },\n\n getLocale: (): string => {\n return currentConfig.locale\n },\n\n setFallbackTranslations: (\n fallbackMessagesInput: Record<string, string>\n ): void => {\n fallbackMessages = fallbackMessagesInput\n },\n\n localeChanged,\n }\n}\n\n/**\n * Set the global intl service\n * Call this once from your app initialization\n *\n * @param service - IntlService instance\n *\n * @example\n * ```typescript\n * import { setIntlService, createIntlService } from '@lukso/core/services/intl';\n *\n * const intl = createIntlService(config);\n * setIntlService(intl);\n * ```\n */\nexport function setIntlService(service: IntlService): void {\n intlService = service\n}\n\n/**\n * Get the current global intl service\n * Returns null if no service has been set\n *\n * @example\n * ```typescript\n * import { getIntlService } from '@lukso/core/services/intl';\n *\n * const intl = getIntlService();\n * if (intl) {\n * console.log(intl.getLocale());\n * }\n * ```\n */\nexport function getIntlService(): IntlService | null {\n return intlService\n}\n\n/**\n * Clear the global intl service\n * Useful for testing or cleanup\n */\nexport function clearIntlService(): void {\n intlService = null\n}\n"],"mappings":";AAMA;AAAA,EACE;AAAA,OAGK;AACP,SAAS,cAAc;AAQvB,IAAM,6BAA6B;AAAA,EACjC,uBAAuB;AACzB;AA6GO,IAAM,gBAA4B;AAAA,EACvC,QAAQ;AAAA,EACR,UAAU,CAAC;AAAA,EACX,SAAS;AAAA,IACP,MAAM;AAAA,MACJ,eAAe;AAAA,QACb,SAAS;AAAA;AAAA,QACT,OAAO;AAAA;AAAA,QACP,KAAK;AAAA;AAAA,QACL,MAAM;AAAA;AAAA,QACN,MAAM;AAAA;AAAA,QACN,QAAQ;AAAA;AAAA,QACR,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;AAKA,IAAI,cAAkC;AA0B/B,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OAC7C,OACF;AAEA,YAAI,iBAAiB;AACnB,iBAAO,IAAI,KAAK;AAAA,YACd,cAAc;AAAA,YACd;AAAA,UACF,EAAE,OAAO,IAAI;AAAA,QACf;AAGA,eAAO,KAAK,WAAW,IAAI,KAAK;AAAA,MAClC;AAGA,aAAO,KAAK,WAAW,MAAM,OAAO,KAAK;AAAA,IAC3C;AAAA,IAEA,WAAW,CAAC,QAAgB,aAA4C;AACtE,sBAAgB;AAAA,QACd,GAAG;AAAA,QACH;AAAA,QACA,UAAU,YAAY,cAAc;AAAA,MACtC;AACA,aAAO,WAAW;AAAA,QAChB,GAAG;AAAA,QACH,eAAe;AAAA,MACjB,CAAC;AACD,oBAAc,SAAS;AAAA,IACzB;AAAA,IAEA,WAAW,MAAc;AACvB,aAAO,cAAc;AAAA,IACvB;AAAA,IAEA,yBAAyB,CACvB,0BACS;AACT,yBAAmB;AAAA,IACrB;AAAA,IAEA;AAAA,EACF;AACF;AAgBO,SAAS,eAAe,SAA4B;AACzD,gBAAc;AAChB;AAgBO,SAAS,iBAAqC;AACnD,SAAO;AACT;AAMO,SAAS,mBAAyB;AACvC,gBAAc;AAChB;","names":[]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkXOL2VVVBcjs = require('./chunk-XOL2VVVB.cjs');
|
|
7
7
|
|
|
8
8
|
// src/mixins/intl.ts
|
|
9
9
|
var _signalscore = require('@preact/signals-core');
|
|
@@ -35,7 +35,7 @@ function withIntlService(Base) {
|
|
|
35
35
|
}
|
|
36
36
|
connectedCallback() {
|
|
37
37
|
super.connectedCallback();
|
|
38
|
-
let intl =
|
|
38
|
+
let intl = _chunkXOL2VVVBcjs.getIntlService.call(void 0, );
|
|
39
39
|
if (!intl) {
|
|
40
40
|
intl = _nullishCoalesce(this.setupLocalIntl(), () => ( null));
|
|
41
41
|
}
|
|
@@ -58,12 +58,12 @@ function withIntlService(Base) {
|
|
|
58
58
|
* Subclasses can override this to customize initialization
|
|
59
59
|
*/
|
|
60
60
|
setupLocalIntl() {
|
|
61
|
-
const intlService =
|
|
62
|
-
Object.assign(
|
|
61
|
+
const intlService = _chunkXOL2VVVBcjs.createIntlService.call(void 0,
|
|
62
|
+
Object.assign(_chunkXOL2VVVBcjs.defaultConfig, {
|
|
63
63
|
messages: en_US_default
|
|
64
64
|
})
|
|
65
65
|
);
|
|
66
|
-
|
|
66
|
+
_chunkXOL2VVVBcjs.setIntlService.call(void 0, intlService);
|
|
67
67
|
return intlService;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
@@ -74,7 +74,7 @@ function withIntlService(Base) {
|
|
|
74
74
|
console.warn("No translation key provided to formatMessage");
|
|
75
75
|
return "";
|
|
76
76
|
}
|
|
77
|
-
const intl =
|
|
77
|
+
const intl = _chunkXOL2VVVBcjs.getIntlService.call(void 0, );
|
|
78
78
|
return _nullishCoalesce(_optionalChain([intl, 'optionalAccess', _3 => _3.formatMessage, 'call', _4 => _4(key, options)]), () => ( key));
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -84,4 +84,4 @@ function withIntlService(Base) {
|
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
exports.withIntlService = withIntlService;
|
|
87
|
-
//# sourceMappingURL=chunk-
|
|
87
|
+
//# sourceMappingURL=chunk-WZIEEMOM.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/service-auth-simple/service-auth-simple/packages/core/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/service-auth-simple/service-auth-simple/packages/core/dist/chunk-WZIEEMOM.cjs","../src/mixins/intl.ts","../../translations/en_US.json"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACDA,mDAAuB;ADGvB;AACA;AEVA,IAAA,cAAA,EAAA;AAAA,EACE,uBAAA,EAA2B,WAAA;AAAA,EAC3B,mBAAA,EAAuB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BAAA,CAAqB,CAAA;AAG3B,MAAA,GAAA,CAAI,OAAO,IAAA,CAAK,gBAAA,IAAoB,UAAA,EAAY;AAC9C,QAAA,IAAA,CAAK,eAAA,CAAgB,CAAA;AAAA,MACvB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA,IAMU,cAAA,CAAA,EAA0C;AAClD,MAAA,MAAM,YAAA,EAAc,iDAAA;AAAA,QAClB,MAAA,CAAO,MAAA,CAAO,+BAAA,EAAe;AAAA,UAC3B,QAAA,EAAU;AAAA,QACZ,CAAC;AAAA,MACH,CAAA;AACA,MAAA,8CAAA,WAA0B,CAAA;AAC1B,MAAA,OAAO,WAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,aAAA,CAAc,GAAA,EAAc,OAAA,EAA0C;AACpE,MAAA,GAAA,CAAI,CAAC,GAAA,EAAK;AACR,QAAA,OAAA,CAAQ,IAAA,CAAK,8CAA8C,CAAA;AAC3D,QAAA,OAAO,EAAA;AAAA,MACT;AAEA,MAAA,MAAM,KAAA,EAAO,8CAAA,CAAe;AAC5B,MAAA,wCAAO,IAAA,6BAAM,aAAA,mBAAc,GAAA,EAAK,OAAO,GAAA,UAAK,KAAA;AAAA,IAC9C;AAAA,EACF;AAGA,EAAA,OAAO,KAAA;AACT;AD7BA;AACA;AACE;AACF,0CAAC","file":"/home/runner/work/service-auth-simple/service-auth-simple/packages/core/dist/chunk-WZIEEMOM.cjs","sourcesContent":[null,"/**\n * Internationalization Mixin\n *\n * Mixin to add internationalization service to a Lit component\n */\n\nimport { effect } from '@preact/signals-core'\nimport { LitElement } from 'lit'\nimport englishTranslations from '../../../translations/en_US.json'\nimport {\n createIntlService,\n defaultConfig,\n getIntlService,\n type IntlService,\n setIntlService,\n} from '../services/intl.js'\n\n/**\n * Mixin to add internationalization service to a Lit component\n *\n * Provides access to the global intl service with reactive locale changes.\n * Automatically subscribes to locale changes and triggers re-renders.\n *\n * The component will use the global intl service if available, or create a local one.\n * This follows the singleton pattern for the global service while allowing flexibility.\n *\n * @typeParam T - The Lit component class being extended\n * @returns Extended class with intl service capabilities\n *\n * @example\n * ```typescript\n * import { LitElement, html } from 'lit';\n * import { customElement } from 'lit/decorators.js';\n * import { withIntlService } from '@lukso/core/mixins';\n *\n * @customElement('my-component')\n * export class MyComponent extends withIntlService(LitElement) {\n * render() {\n * return html\\`<p>\\${this.formatMessage('app.welcome')}</p>\\`;\n * }\n * }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withIntlService<T extends typeof LitElement>(Base: T): any {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n class Mixin extends (Base as any) {\n protected unsubscribeIntl: (() => void) | undefined = undefined\n\n connectedCallback(): void {\n super.connectedCallback()\n\n // Subscribe to intl changes via signal\n let intl: IntlService | null = getIntlService()\n\n // When no intl is provided by host app we initialize our own\n if (!intl) {\n intl = this.setupLocalIntl() ?? null\n }\n\n if (intl) {\n this.unsubscribeIntl = effect(() => {\n // Access the signal to track changes\n intl!.localeChanged.value\n this.requestUpdate()\n })\n }\n\n // Set fallback for missing translations\n intl?.setFallbackTranslations(englishTranslations)\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback()\n\n // Unsubscribe from intl changes\n if (typeof this.unsubscribeIntl === 'function') {\n this.unsubscribeIntl()\n }\n }\n\n /**\n * Setup a local intl service with default configuration\n * Subclasses can override this to customize initialization\n */\n protected setupLocalIntl(): IntlService | undefined {\n const intlService = createIntlService(\n Object.assign(defaultConfig, {\n messages: englishTranslations,\n })\n )\n setIntlService(intlService)\n return intlService\n }\n\n /**\n * Format message using the intl service\n */\n formatMessage(key?: string, options?: Record<string, string>): string {\n if (!key) {\n console.warn('No translation key provided to formatMessage')\n return ''\n }\n\n const intl = getIntlService()\n return intl?.formatMessage(key, options) ?? key\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return Mixin as any\n}\n","{\n \"connect_modal_try_again\": \"Try again\",\n \"connect_modal_title\": \"Let’s log you in\",\n \"connect_modal_qr_code_title\": \"Scan to log in\",\n \"connect_modal_qr_code_description\": \"Scan the below QR code with the Universal Profile mobile app to log in\",\n \"connect_modal_other_connectors\": \"Connect Wallet\",\n \"connect_modal_or_info\": \"Log in with a different wallet\",\n \"connect_modal_or\": \"Or\",\n \"connect_modal_installed\": \"INSTALLED\",\n \"connect_modal_failed_to_load\": \"Failed to load...\",\n \"connect_modal_eoa_title\": \"Connect your Wallet\",\n \"connect_modal_description\": \"Log in with your Universal Profile\",\n \"connect_modal_connectors_up_mobile\": \"Mobile Application\",\n \"connect_modal_connectors_up_browser_extension\": \"Browser Extension\",\n \"connect_modal_connectors_passkey_wallet\": \"Passkey Wallet\"\n}"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/services/intl.ts
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
var _intl = require('@formatjs/intl');
|
|
@@ -8,11 +8,30 @@ var formatNumberDefaultOptions = {
|
|
|
8
8
|
};
|
|
9
9
|
var defaultConfig = {
|
|
10
10
|
locale: "en-US",
|
|
11
|
-
messages: {}
|
|
11
|
+
messages: {},
|
|
12
|
+
formats: {
|
|
13
|
+
date: {
|
|
14
|
+
shortDateTime: {
|
|
15
|
+
weekday: "short",
|
|
16
|
+
// Wed
|
|
17
|
+
month: "short",
|
|
18
|
+
// Dec
|
|
19
|
+
day: "numeric",
|
|
20
|
+
// 3
|
|
21
|
+
year: "numeric",
|
|
22
|
+
// 2025
|
|
23
|
+
hour: "2-digit",
|
|
24
|
+
// 16
|
|
25
|
+
minute: "2-digit",
|
|
26
|
+
// 07
|
|
27
|
+
hour12: false
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
12
31
|
};
|
|
13
32
|
var intlService = null;
|
|
14
33
|
function createIntlService(config = defaultConfig) {
|
|
15
|
-
let currentConfig = config;
|
|
34
|
+
let currentConfig = { ...defaultConfig, ...config };
|
|
16
35
|
let intl = _intl.createIntl.call(void 0, { ...currentConfig, defaultLocale: "en-US" });
|
|
17
36
|
const localeChanged = _signalscore.signal.call(void 0, 0);
|
|
18
37
|
let fallbackMessages = {};
|
|
@@ -51,7 +70,17 @@ function createIntlService(config = defaultConfig) {
|
|
|
51
70
|
formatTimestamp: (timestamp, options) => {
|
|
52
71
|
if (!timestamp) return "";
|
|
53
72
|
const time = typeof timestamp === "string" ? Number(timestamp) : timestamp;
|
|
54
|
-
const date = new Date(time * 1e3);
|
|
73
|
+
const date = time < 1e10 ? new Date(time * 1e3) : new Date(time);
|
|
74
|
+
if (typeof options === "string") {
|
|
75
|
+
const dateTimeOptions = _optionalChain([currentConfig, 'access', _ => _.formats, 'optionalAccess', _2 => _2.date, 'optionalAccess', _3 => _3[options]]);
|
|
76
|
+
if (dateTimeOptions) {
|
|
77
|
+
return new Intl.DateTimeFormat(
|
|
78
|
+
currentConfig.locale,
|
|
79
|
+
dateTimeOptions
|
|
80
|
+
).format(date);
|
|
81
|
+
}
|
|
82
|
+
return intl.formatDate(date) || "";
|
|
83
|
+
}
|
|
55
84
|
return intl.formatDate(date, options) || "";
|
|
56
85
|
},
|
|
57
86
|
setLocale: (locale, messages) => {
|
|
@@ -92,4 +121,4 @@ function clearIntlService() {
|
|
|
92
121
|
|
|
93
122
|
|
|
94
123
|
exports.defaultConfig = defaultConfig; exports.createIntlService = createIntlService; exports.setIntlService = setIntlService; exports.getIntlService = getIntlService; exports.clearIntlService = clearIntlService;
|
|
95
|
-
//# sourceMappingURL=chunk-
|
|
124
|
+
//# sourceMappingURL=chunk-XOL2VVVB.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/service-auth-simple/service-auth-simple/packages/core/dist/chunk-XOL2VVVB.cjs","../src/services/intl.ts"],"names":[],"mappings":"AAAA;ACMA;AACE;AAAA,sCAGK;AACP,mDAAuB;AAQvB,IAAM,2BAAA,EAA6B;AAAA,EACjC,qBAAA,EAAuB;AACzB,CAAA;AA6GO,IAAM,cAAA,EAA4B;AAAA,EACvC,MAAA,EAAQ,OAAA;AAAA,EACR,QAAA,EAAU,CAAC,CAAA;AAAA,EACX,OAAA,EAAS;AAAA,IACP,IAAA,EAAM;AAAA,MACJ,aAAA,EAAe;AAAA,QACb,OAAA,EAAS,OAAA;AAAA;AAAA,QACT,KAAA,EAAO,OAAA;AAAA;AAAA,QACP,GAAA,EAAK,SAAA;AAAA;AAAA,QACL,IAAA,EAAM,SAAA;AAAA;AAAA,QACN,IAAA,EAAM,SAAA;AAAA;AAAA,QACN,MAAA,EAAQ,SAAA;AAAA;AAAA,QACR,MAAA,EAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF,CAAA;AAKA,IAAI,YAAA,EAAkC,IAAA;AA0B/B,SAAS,iBAAA,CACd,OAAA,EAAqB,aAAA,EACR;AACb,EAAA,IAAI,cAAA,EAAgB,EAAE,GAAG,aAAA,EAAe,GAAG,OAAO,CAAA;AAClD,EAAA,IAAI,KAAA,EAAO,8BAAA,EAAa,GAAG,aAAA,EAAe,aAAA,EAAe,QAAQ,CAAC,CAAA;AAClE,EAAA,MAAM,cAAA,EAAgB,iCAAA,CAAQ,CAAA;AAC9B,EAAA,IAAI,iBAAA,EAA2C,CAAC,CAAA;AAEhD,EAAA,OAAO;AAAA,IACL,aAAA,EAAe,CAAC,GAAA,EAAa,OAAA,EAAA,GAA6C;AACxE,MAAA,IAAI;AACF,QAAA,MAAM,OAAA,E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,EAAyB,CACvB,qBAAA,EAAA,GACS;AACT,MAAA,iBAAA,EAAmB,qBAAA;AAAA,IACrB,CAAA;AAAA,IAEA;AAAA,EACF,CAAA;AACF;AAgBO,SAAS,cAAA,CAAe,OAAA,EAA4B;AACzD,EAAA,YAAA,EAAc,OAAA;AAChB;AAgBO,SAAS,cAAA,CAAA,EAAqC;AACnD,EAAA,OAAO,WAAA;AACT;AAMO,SAAS,gBAAA,CAAA,EAAyB;AACvC,EAAA,YAAA,EAAc,IAAA;AAChB;AD5NA;AACA;AACE;AACA;AACA;AACA;AACA;AACF,oNAAC","file":"/home/runner/work/service-auth-simple/service-auth-simple/packages/core/dist/chunk-XOL2VVVB.cjs","sourcesContent":[null,"/**\n * Internationalization Service\n *\n * Provides locale-aware formatting for messages, numbers, dates, and times.\n */\n\nimport {\n createIntl,\n type FormatNumberOptions,\n type IntlConfig,\n} from '@formatjs/intl'\nimport { signal } from '@preact/signals-core'\n\nexport type TimestampFormat = 'shortDateTime'\n\n/**\n * Default format number options\n * @see https://github.com/formatjs/formatjs/blob/main/packages/ecma402-abstract/types/number.ts\n */\nconst formatNumberDefaultOptions = {\n maximumFractionDigits: 18,\n}\n\n/**\n * Intl service interface\n */\nexport interface IntlService {\n /**\n * Translate a string based on the key\n *\n * @param key - translation key\n * @param options - optional options for formatMessage (for variable interpolation)\n * @returns - translated string\n */\n formatMessage: (key: string, options?: Record<string, string>) => string\n\n /**\n * Number formatting based on the locale\n *\n * @param value - number to format\n * @param options - options for formatNumber\n * @returns - formatted number\n */\n formatNumber: (\n value: number | string | bigint,\n options?: FormatNumberOptions\n ) => string\n\n /**\n * Date formatting based on the locale\n *\n * @param date - date to format\n * @returns - formatted date\n */\n formatDate: (date?: string | number | Date) => string | undefined\n\n /**\n * Time formatting based on the locale\n *\n * @param date - date to format\n * @returns - formatted time\n */\n formatTime: (date?: string | number | Date) => string | undefined\n\n /**\n * Timestamp formatting based on the locale\n *\n * @param timestamp - UNIX timestamp in seconds or milliseconds\n * @param options - formatting options (predefined format name or custom Intl.DateTimeFormat options)\n * @returns - formatted date & time string\n *\n * @example\n * ```typescript\n * const intl = getIntlService();\n *\n * // Use predefined shortDateTime format\n * intl.formatTimestamp(1733251200, 'shortDateTime'); // \"Wed, Dec 3, 2025, 16:07\"\n *\n * // Use custom format options\n * intl.formatTimestamp(1733251200, { year: '2-digit', month: '2-digit', day: '2-digit' });\n * // \"12/03/25\"\n *\n * // No options (basic format)\n * intl.formatTimestamp(1733251200);\n * ```\n */\n formatTimestamp: (\n timestamp?: number | string,\n options?: TimestampFormat | Intl.DateTimeFormatOptions\n ) => string\n\n /**\n * Change the locale and optionally update messages\n *\n * @param locale - new locale code (e.g., 'en-US', 'de-DE')\n * @param messages - optional new messages object for the locale\n */\n setLocale: (locale: string, messages?: Record<string, string>) => void\n\n /**\n * Get the current locale\n *\n * @returns - current locale code (e.g., 'en-US', 'de-DE')\n */\n getLocale: () => string\n\n /**\n * Set fallback translations to use when a translation key is missing\n * Useful when the host app's intl service doesn't have all translations\n *\n * @param fallbackMessages - translations to use as fallback\n *\n * @example\n * ```typescript\n * // After intl service is initialized by host app\n * intl.setFallbackTranslations(defaultMessages);\n * ```\n */\n setFallbackTranslations: (fallbackMessages: Record<string, string>) => void\n\n /**\n * Signal that tracks locale changes\n * Use this signal to reactively update UI when locale changes\n */\n localeChanged: { value: number }\n}\n\n/**\n * Default configuration for intl\n */\nexport const defaultConfig: IntlConfig = {\n locale: 'en-US',\n messages: {},\n formats: {\n date: {\n shortDateTime: {\n weekday: 'short', // Wed\n month: 'short', // Dec\n day: 'numeric', // 3\n year: 'numeric', // 2025\n hour: '2-digit', // 16\n minute: '2-digit', // 07\n hour12: false,\n },\n },\n },\n}\n\n/**\n * Global intl service instance\n */\nlet intlService: IntlService | null = null\n\n/**\n * Create a new intl service instance\n *\n * @param config - intl configuration with locale and messages\n * @returns IntlService instance with formatting methods\n *\n * @example\n * ```typescript\n * import { createIntlService } from '@lukso/core/services/intl';\n *\n * const intl = createIntlService({\n * locale: 'en-US',\n * messages: customMessages,\n * });\n *\n * const translated = intl.formatMessage('app.title');\n * const formatted = intl.formatNumber(1234.56);\n * const currentLocale = intl.getLocale(); // 'en-US'\n *\n * // Change locale\n * intl.setLocale('de-DE', germanMessages);\n * console.log(intl.getLocale()); // 'de-DE'\n * ```\n */\nexport function createIntlService(\n config: IntlConfig = defaultConfig\n): IntlService {\n let currentConfig = { ...defaultConfig, ...config }\n let intl = createIntl({ ...currentConfig, defaultLocale: 'en-US' })\n const localeChanged = signal(0)\n let fallbackMessages: Record<string, string> = {}\n\n return {\n formatMessage: (key: string, options?: Record<string, string>): string => {\n try {\n const result = intl.formatMessage({ id: key }, options)\n\n if (result && result !== key) {\n return result\n }\n\n // If no translation found, check fallback\n if (fallbackMessages[key]) {\n return fallbackMessages[key]\n }\n\n return key\n } catch {\n // On error, try fallback\n return fallbackMessages[key] || key\n }\n },\n\n formatNumber: (\n value: number | string | bigint,\n options: FormatNumberOptions = {}\n ): string => {\n if (value === null || value === undefined) {\n return '0'\n }\n\n const _value =\n typeof value === 'string' ? Number.parseFloat(value) : value\n\n const mergedOptions = {\n ...formatNumberDefaultOptions,\n ...options,\n }\n\n return intl.formatNumber(_value as number, mergedOptions) || ''\n },\n\n formatDate: (date?: string | number | Date): string => {\n return intl.formatDate(date)\n },\n\n formatTime: (date?: string | number | Date): string => {\n return intl.formatTime(date)\n },\n\n formatTimestamp: (\n timestamp?: number | string,\n options?: TimestampFormat | Intl.DateTimeFormatOptions\n ): string => {\n if (!timestamp) return ''\n\n const time = typeof timestamp === 'string' ? Number(timestamp) : timestamp\n const date =\n time < 10_000_000_000\n ? new Date(time * 1000) // seconds\n : new Date(time) // milliseconds\n\n // Handle predefined format\n if (typeof options === 'string') {\n const dateTimeOptions = currentConfig.formats?.date?.[\n options as TimestampFormat\n ] as Intl.DateTimeFormatOptions\n\n if (dateTimeOptions) {\n return new Intl.DateTimeFormat(\n currentConfig.locale,\n dateTimeOptions\n ).format(date)\n }\n\n // Fallback to default format if predefined format not found\n return intl.formatDate(date) || ''\n }\n\n // For normal @formatjs/intl options\n return intl.formatDate(date, options) || ''\n },\n\n setLocale: (locale: string, messages?: Record<string, string>): void => {\n currentConfig = {\n ...currentConfig,\n locale,\n messages: messages || currentConfig.messages,\n }\n intl = createIntl({\n ...currentConfig,\n defaultLocale: 'en-US',\n })\n localeChanged.value += 1\n },\n\n getLocale: (): string => {\n return currentConfig.locale\n },\n\n setFallbackTranslations: (\n fallbackMessagesInput: Record<string, string>\n ): void => {\n fallbackMessages = fallbackMessagesInput\n },\n\n localeChanged,\n }\n}\n\n/**\n * Set the global intl service\n * Call this once from your app initialization\n *\n * @param service - IntlService instance\n *\n * @example\n * ```typescript\n * import { setIntlService, createIntlService } from '@lukso/core/services/intl';\n *\n * const intl = createIntlService(config);\n * setIntlService(intl);\n * ```\n */\nexport function setIntlService(service: IntlService): void {\n intlService = service\n}\n\n/**\n * Get the current global intl service\n * Returns null if no service has been set\n *\n * @example\n * ```typescript\n * import { getIntlService } from '@lukso/core/services/intl';\n *\n * const intl = getIntlService();\n * if (intl) {\n * console.log(intl.getLocale());\n * }\n * ```\n */\nexport function getIntlService(): IntlService | null {\n return intlService\n}\n\n/**\n * Clear the global intl service\n * Useful for testing or cleanup\n */\nexport function clearIntlService(): void {\n intlService = null\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
var _chunkR77UDCWDcjs = require('./chunk-R77UDCWD.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkWZIEEMOMcjs = require('./chunk-WZIEEMOM.cjs');
|
|
8
8
|
require('./chunk-DFMMMF62.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
@@ -15,7 +15,7 @@ var _chunkNJQVWIZLcjs = require('./chunk-NJQVWIZL.cjs');
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _chunkXOL2VVVBcjs = require('./chunk-XOL2VVVB.cjs');
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
@@ -33,5 +33,5 @@ var _chunkFVO474U6cjs = require('./chunk-FVO474U6.cjs');
|
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
exports.EXTENSION_STORE_LINKS = _chunkFVO474U6cjs.EXTENSION_STORE_LINKS; exports.browserInfo = _chunkFVO474U6cjs.browserInfo; exports.clearIntlService =
|
|
36
|
+
exports.EXTENSION_STORE_LINKS = _chunkFVO474U6cjs.EXTENSION_STORE_LINKS; exports.browserInfo = _chunkFVO474U6cjs.browserInfo; exports.clearIntlService = _chunkXOL2VVVBcjs.clearIntlService; exports.createIntlService = _chunkXOL2VVVBcjs.createIntlService; exports.defaultConfig = _chunkXOL2VVVBcjs.defaultConfig; exports.deviceService = _chunkNJQVWIZLcjs.deviceService; exports.getIntlService = _chunkXOL2VVVBcjs.getIntlService; exports.setIntlService = _chunkXOL2VVVBcjs.setIntlService; exports.slug = _chunkFVO474U6cjs.slug; exports.withDeviceService = _chunkR77UDCWDcjs.withDeviceService; exports.withIntlService = _chunkWZIEEMOMcjs.withIntlService;
|
|
37
37
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-7ESVFJO6.js";
|
|
5
5
|
import {
|
|
6
6
|
withIntlService
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-6QJEVD4O.js";
|
|
8
8
|
import "./chunk-LEL6VWU4.js";
|
|
9
9
|
import {
|
|
10
10
|
deviceService
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
defaultConfig,
|
|
16
16
|
getIntlService,
|
|
17
17
|
setIntlService
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-SOMU2QZE.js";
|
|
19
19
|
import {
|
|
20
20
|
EXTENSION_STORE_LINKS,
|
|
21
21
|
browserInfo,
|
package/dist/mixins/index.cjs
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
var _chunkR77UDCWDcjs = require('../chunk-R77UDCWD.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkWZIEEMOMcjs = require('../chunk-WZIEEMOM.cjs');
|
|
8
8
|
require('../chunk-NJQVWIZL.cjs');
|
|
9
|
-
require('../chunk-
|
|
9
|
+
require('../chunk-XOL2VVVB.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
exports.withDeviceService = _chunkR77UDCWDcjs.withDeviceService; exports.withIntlService =
|
|
13
|
+
exports.withDeviceService = _chunkR77UDCWDcjs.withDeviceService; exports.withIntlService = _chunkWZIEEMOMcjs.withIntlService;
|
|
14
14
|
//# sourceMappingURL=index.cjs.map
|
package/dist/mixins/index.js
CHANGED
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
} from "../chunk-7ESVFJO6.js";
|
|
5
5
|
import {
|
|
6
6
|
withIntlService
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-6QJEVD4O.js";
|
|
8
8
|
import "../chunk-X2QNFZU7.js";
|
|
9
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-SOMU2QZE.js";
|
|
10
10
|
export {
|
|
11
11
|
withDeviceService,
|
|
12
12
|
withIntlService
|
package/dist/mixins/intl.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunkWZIEEMOMcjs = require('../chunk-WZIEEMOM.cjs');
|
|
4
|
+
require('../chunk-XOL2VVVB.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
exports.withIntlService =
|
|
7
|
+
exports.withIntlService = _chunkWZIEEMOMcjs.withIntlService;
|
|
8
8
|
//# sourceMappingURL=intl.cjs.map
|
package/dist/mixins/intl.js
CHANGED
package/dist/services/index.cjs
CHANGED
|
@@ -8,7 +8,7 @@ var _chunkNJQVWIZLcjs = require('../chunk-NJQVWIZL.cjs');
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkXOL2VVVBcjs = require('../chunk-XOL2VVVB.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
@@ -16,5 +16,5 @@ var _chunkUOLYOGEVcjs = require('../chunk-UOLYOGEV.cjs');
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
exports.clearIntlService =
|
|
19
|
+
exports.clearIntlService = _chunkXOL2VVVBcjs.clearIntlService; exports.createIntlService = _chunkXOL2VVVBcjs.createIntlService; exports.defaultConfig = _chunkXOL2VVVBcjs.defaultConfig; exports.deviceService = _chunkNJQVWIZLcjs.deviceService; exports.getIntlService = _chunkXOL2VVVBcjs.getIntlService; exports.setIntlService = _chunkXOL2VVVBcjs.setIntlService;
|
|
20
20
|
//# sourceMappingURL=index.cjs.map
|
package/dist/services/index.js
CHANGED
package/dist/services/intl.cjs
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkXOL2VVVBcjs = require('../chunk-XOL2VVVB.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
exports.clearIntlService =
|
|
14
|
+
exports.clearIntlService = _chunkXOL2VVVBcjs.clearIntlService; exports.createIntlService = _chunkXOL2VVVBcjs.createIntlService; exports.defaultConfig = _chunkXOL2VVVBcjs.defaultConfig; exports.getIntlService = _chunkXOL2VVVBcjs.getIntlService; exports.setIntlService = _chunkXOL2VVVBcjs.setIntlService;
|
|
15
15
|
//# sourceMappingURL=intl.cjs.map
|
package/dist/services/intl.d.cts
CHANGED
|
@@ -6,6 +6,7 @@ import { FormatNumberOptions, IntlConfig } from '@formatjs/intl';
|
|
|
6
6
|
* Provides locale-aware formatting for messages, numbers, dates, and times.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
type TimestampFormat = 'shortDateTime';
|
|
9
10
|
/**
|
|
10
11
|
* Intl service interface
|
|
11
12
|
*/
|
|
@@ -44,10 +45,25 @@ interface IntlService {
|
|
|
44
45
|
* Timestamp formatting based on the locale
|
|
45
46
|
*
|
|
46
47
|
* @param timestamp - UNIX timestamp in seconds or milliseconds
|
|
47
|
-
* @param options -
|
|
48
|
+
* @param options - formatting options (predefined format name or custom Intl.DateTimeFormat options)
|
|
48
49
|
* @returns - formatted date & time string
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const intl = getIntlService();
|
|
54
|
+
*
|
|
55
|
+
* // Use predefined shortDateTime format
|
|
56
|
+
* intl.formatTimestamp(1733251200, 'shortDateTime'); // "Wed, Dec 3, 2025, 16:07"
|
|
57
|
+
*
|
|
58
|
+
* // Use custom format options
|
|
59
|
+
* intl.formatTimestamp(1733251200, { year: '2-digit', month: '2-digit', day: '2-digit' });
|
|
60
|
+
* // "12/03/25"
|
|
61
|
+
*
|
|
62
|
+
* // No options (basic format)
|
|
63
|
+
* intl.formatTimestamp(1733251200);
|
|
64
|
+
* ```
|
|
49
65
|
*/
|
|
50
|
-
formatTimestamp: (timestamp?: number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
66
|
+
formatTimestamp: (timestamp?: number | string, options?: TimestampFormat | Intl.DateTimeFormatOptions) => string;
|
|
51
67
|
/**
|
|
52
68
|
* Change the locale and optionally update messages
|
|
53
69
|
*
|
|
@@ -147,4 +163,4 @@ declare function getIntlService(): IntlService | null;
|
|
|
147
163
|
*/
|
|
148
164
|
declare function clearIntlService(): void;
|
|
149
165
|
|
|
150
|
-
export { type IntlService, clearIntlService, createIntlService, defaultConfig, getIntlService, setIntlService };
|
|
166
|
+
export { type IntlService, type TimestampFormat, clearIntlService, createIntlService, defaultConfig, getIntlService, setIntlService };
|
package/dist/services/intl.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { FormatNumberOptions, IntlConfig } from '@formatjs/intl';
|
|
|
6
6
|
* Provides locale-aware formatting for messages, numbers, dates, and times.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
type TimestampFormat = 'shortDateTime';
|
|
9
10
|
/**
|
|
10
11
|
* Intl service interface
|
|
11
12
|
*/
|
|
@@ -44,10 +45,25 @@ interface IntlService {
|
|
|
44
45
|
* Timestamp formatting based on the locale
|
|
45
46
|
*
|
|
46
47
|
* @param timestamp - UNIX timestamp in seconds or milliseconds
|
|
47
|
-
* @param options -
|
|
48
|
+
* @param options - formatting options (predefined format name or custom Intl.DateTimeFormat options)
|
|
48
49
|
* @returns - formatted date & time string
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const intl = getIntlService();
|
|
54
|
+
*
|
|
55
|
+
* // Use predefined shortDateTime format
|
|
56
|
+
* intl.formatTimestamp(1733251200, 'shortDateTime'); // "Wed, Dec 3, 2025, 16:07"
|
|
57
|
+
*
|
|
58
|
+
* // Use custom format options
|
|
59
|
+
* intl.formatTimestamp(1733251200, { year: '2-digit', month: '2-digit', day: '2-digit' });
|
|
60
|
+
* // "12/03/25"
|
|
61
|
+
*
|
|
62
|
+
* // No options (basic format)
|
|
63
|
+
* intl.formatTimestamp(1733251200);
|
|
64
|
+
* ```
|
|
49
65
|
*/
|
|
50
|
-
formatTimestamp: (timestamp?: number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
66
|
+
formatTimestamp: (timestamp?: number | string, options?: TimestampFormat | Intl.DateTimeFormatOptions) => string;
|
|
51
67
|
/**
|
|
52
68
|
* Change the locale and optionally update messages
|
|
53
69
|
*
|
|
@@ -147,4 +163,4 @@ declare function getIntlService(): IntlService | null;
|
|
|
147
163
|
*/
|
|
148
164
|
declare function clearIntlService(): void;
|
|
149
165
|
|
|
150
|
-
export { type IntlService, clearIntlService, createIntlService, defaultConfig, getIntlService, setIntlService };
|
|
166
|
+
export { type IntlService, type TimestampFormat, clearIntlService, createIntlService, defaultConfig, getIntlService, setIntlService };
|
package/dist/services/intl.js
CHANGED
package/package.json
CHANGED
|
@@ -209,6 +209,7 @@ describe('Intl service', () => {
|
|
|
209
209
|
|
|
210
210
|
it('should return empty string for undefined or null', () => {
|
|
211
211
|
const intl = createIntlService({ locale: 'en-US', messages: {} })
|
|
212
|
+
expect(intl.formatTimestamp('')).toBe('')
|
|
212
213
|
expect(intl.formatTimestamp(undefined)).toBe('')
|
|
213
214
|
expect(intl.formatTimestamp(null as any)).toBe('')
|
|
214
215
|
})
|
|
@@ -223,6 +224,13 @@ describe('Intl service', () => {
|
|
|
223
224
|
})
|
|
224
225
|
expect(result).toBe('December 2, 2024')
|
|
225
226
|
})
|
|
227
|
+
|
|
228
|
+
it('should use predefined shortDateTime format when specified', () => {
|
|
229
|
+
const intl = createIntlService({ locale: 'en-US', messages: {} })
|
|
230
|
+
const timestamp = 1733144400 // 2024-12-02T14:00:00Z
|
|
231
|
+
const result = intl.formatTimestamp(timestamp, 'shortDateTime')
|
|
232
|
+
expect(result).toBe('Mon, Dec 2, 2024, 13:00')
|
|
233
|
+
})
|
|
226
234
|
})
|
|
227
235
|
|
|
228
236
|
describe('setLocale', () => {
|
package/src/services/intl.ts
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
} from '@formatjs/intl'
|
|
12
12
|
import { signal } from '@preact/signals-core'
|
|
13
13
|
|
|
14
|
+
export type TimestampFormat = 'shortDateTime'
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* Default format number options
|
|
16
18
|
* @see https://github.com/formatjs/formatjs/blob/main/packages/ecma402-abstract/types/number.ts
|
|
@@ -64,12 +66,27 @@ export interface IntlService {
|
|
|
64
66
|
* Timestamp formatting based on the locale
|
|
65
67
|
*
|
|
66
68
|
* @param timestamp - UNIX timestamp in seconds or milliseconds
|
|
67
|
-
* @param options -
|
|
69
|
+
* @param options - formatting options (predefined format name or custom Intl.DateTimeFormat options)
|
|
68
70
|
* @returns - formatted date & time string
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const intl = getIntlService();
|
|
75
|
+
*
|
|
76
|
+
* // Use predefined shortDateTime format
|
|
77
|
+
* intl.formatTimestamp(1733251200, 'shortDateTime'); // "Wed, Dec 3, 2025, 16:07"
|
|
78
|
+
*
|
|
79
|
+
* // Use custom format options
|
|
80
|
+
* intl.formatTimestamp(1733251200, { year: '2-digit', month: '2-digit', day: '2-digit' });
|
|
81
|
+
* // "12/03/25"
|
|
82
|
+
*
|
|
83
|
+
* // No options (basic format)
|
|
84
|
+
* intl.formatTimestamp(1733251200);
|
|
85
|
+
* ```
|
|
69
86
|
*/
|
|
70
87
|
formatTimestamp: (
|
|
71
88
|
timestamp?: number | string,
|
|
72
|
-
options?: Intl.DateTimeFormatOptions
|
|
89
|
+
options?: TimestampFormat | Intl.DateTimeFormatOptions
|
|
73
90
|
) => string
|
|
74
91
|
|
|
75
92
|
/**
|
|
@@ -114,6 +131,19 @@ export interface IntlService {
|
|
|
114
131
|
export const defaultConfig: IntlConfig = {
|
|
115
132
|
locale: 'en-US',
|
|
116
133
|
messages: {},
|
|
134
|
+
formats: {
|
|
135
|
+
date: {
|
|
136
|
+
shortDateTime: {
|
|
137
|
+
weekday: 'short', // Wed
|
|
138
|
+
month: 'short', // Dec
|
|
139
|
+
day: 'numeric', // 3
|
|
140
|
+
year: 'numeric', // 2025
|
|
141
|
+
hour: '2-digit', // 16
|
|
142
|
+
minute: '2-digit', // 07
|
|
143
|
+
hour12: false,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
117
147
|
}
|
|
118
148
|
|
|
119
149
|
/**
|
|
@@ -148,7 +178,7 @@ let intlService: IntlService | null = null
|
|
|
148
178
|
export function createIntlService(
|
|
149
179
|
config: IntlConfig = defaultConfig
|
|
150
180
|
): IntlService {
|
|
151
|
-
let currentConfig = config
|
|
181
|
+
let currentConfig = { ...defaultConfig, ...config }
|
|
152
182
|
let intl = createIntl({ ...currentConfig, defaultLocale: 'en-US' })
|
|
153
183
|
const localeChanged = signal(0)
|
|
154
184
|
let fallbackMessages: Record<string, string> = {}
|
|
@@ -203,13 +233,34 @@ export function createIntlService(
|
|
|
203
233
|
|
|
204
234
|
formatTimestamp: (
|
|
205
235
|
timestamp?: number | string,
|
|
206
|
-
options?: Intl.DateTimeFormatOptions
|
|
236
|
+
options?: TimestampFormat | Intl.DateTimeFormatOptions
|
|
207
237
|
): string => {
|
|
208
238
|
if (!timestamp) return ''
|
|
209
239
|
|
|
210
240
|
const time = typeof timestamp === 'string' ? Number(timestamp) : timestamp
|
|
211
|
-
const date =
|
|
241
|
+
const date =
|
|
242
|
+
time < 10_000_000_000
|
|
243
|
+
? new Date(time * 1000) // seconds
|
|
244
|
+
: new Date(time) // milliseconds
|
|
245
|
+
|
|
246
|
+
// Handle predefined format
|
|
247
|
+
if (typeof options === 'string') {
|
|
248
|
+
const dateTimeOptions = currentConfig.formats?.date?.[
|
|
249
|
+
options as TimestampFormat
|
|
250
|
+
] as Intl.DateTimeFormatOptions
|
|
251
|
+
|
|
252
|
+
if (dateTimeOptions) {
|
|
253
|
+
return new Intl.DateTimeFormat(
|
|
254
|
+
currentConfig.locale,
|
|
255
|
+
dateTimeOptions
|
|
256
|
+
).format(date)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Fallback to default format if predefined format not found
|
|
260
|
+
return intl.formatDate(date) || ''
|
|
261
|
+
}
|
|
212
262
|
|
|
263
|
+
// For normal @formatjs/intl options
|
|
213
264
|
return intl.formatDate(date, options) || ''
|
|
214
265
|
},
|
|
215
266
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/services/intl.ts"],"sourcesContent":["/**\n * Internationalization Service\n *\n * Provides locale-aware formatting for messages, numbers, dates, and times.\n */\n\nimport {\n createIntl,\n type FormatNumberOptions,\n type IntlConfig,\n} from '@formatjs/intl'\nimport { signal } from '@preact/signals-core'\n\n/**\n * Default format number options\n * @see https://github.com/formatjs/formatjs/blob/main/packages/ecma402-abstract/types/number.ts\n */\nconst formatNumberDefaultOptions = {\n maximumFractionDigits: 18,\n}\n\n/**\n * Intl service interface\n */\nexport interface IntlService {\n /**\n * Translate a string based on the key\n *\n * @param key - translation key\n * @param options - optional options for formatMessage (for variable interpolation)\n * @returns - translated string\n */\n formatMessage: (key: string, options?: Record<string, string>) => string\n\n /**\n * Number formatting based on the locale\n *\n * @param value - number to format\n * @param options - options for formatNumber\n * @returns - formatted number\n */\n formatNumber: (\n value: number | string | bigint,\n options?: FormatNumberOptions\n ) => string\n\n /**\n * Date formatting based on the locale\n *\n * @param date - date to format\n * @returns - formatted date\n */\n formatDate: (date?: string | number | Date) => string | undefined\n\n /**\n * Time formatting based on the locale\n *\n * @param date - date to format\n * @returns - formatted time\n */\n formatTime: (date?: string | number | Date) => string | undefined\n\n /**\n * Timestamp formatting based on the locale\n *\n * @param timestamp - UNIX timestamp in seconds or milliseconds\n * @param options - optional Intl.DateTimeFormat options\n * @returns - formatted date & time string\n */\n formatTimestamp: (\n timestamp?: number | string,\n options?: Intl.DateTimeFormatOptions\n ) => string\n\n /**\n * Change the locale and optionally update messages\n *\n * @param locale - new locale code (e.g., 'en-US', 'de-DE')\n * @param messages - optional new messages object for the locale\n */\n setLocale: (locale: string, messages?: Record<string, string>) => void\n\n /**\n * Get the current locale\n *\n * @returns - current locale code (e.g., 'en-US', 'de-DE')\n */\n getLocale: () => string\n\n /**\n * Set fallback translations to use when a translation key is missing\n * Useful when the host app's intl service doesn't have all translations\n *\n * @param fallbackMessages - translations to use as fallback\n *\n * @example\n * ```typescript\n * // After intl service is initialized by host app\n * intl.setFallbackTranslations(defaultMessages);\n * ```\n */\n setFallbackTranslations: (fallbackMessages: Record<string, string>) => void\n\n /**\n * Signal that tracks locale changes\n * Use this signal to reactively update UI when locale changes\n */\n localeChanged: { value: number }\n}\n\n/**\n * Default configuration for intl\n */\nexport const defaultConfig: IntlConfig = {\n locale: 'en-US',\n messages: {},\n}\n\n/**\n * Global intl service instance\n */\nlet intlService: IntlService | null = null\n\n/**\n * Create a new intl service instance\n *\n * @param config - intl configuration with locale and messages\n * @returns IntlService instance with formatting methods\n *\n * @example\n * ```typescript\n * import { createIntlService } from '@lukso/core/services/intl';\n *\n * const intl = createIntlService({\n * locale: 'en-US',\n * messages: customMessages,\n * });\n *\n * const translated = intl.formatMessage('app.title');\n * const formatted = intl.formatNumber(1234.56);\n * const currentLocale = intl.getLocale(); // 'en-US'\n *\n * // Change locale\n * intl.setLocale('de-DE', germanMessages);\n * console.log(intl.getLocale()); // 'de-DE'\n * ```\n */\nexport function createIntlService(\n config: IntlConfig = defaultConfig\n): IntlService {\n let currentConfig = config\n let intl = createIntl({ ...currentConfig, defaultLocale: 'en-US' })\n const localeChanged = signal(0)\n let fallbackMessages: Record<string, string> = {}\n\n return {\n formatMessage: (key: string, options?: Record<string, string>): string => {\n try {\n const result = intl.formatMessage({ id: key }, options)\n\n if (result && result !== key) {\n return result\n }\n\n // If no translation found, check fallback\n if (fallbackMessages[key]) {\n return fallbackMessages[key]\n }\n\n return key\n } catch {\n // On error, try fallback\n return fallbackMessages[key] || key\n }\n },\n\n formatNumber: (\n value: number | string | bigint,\n options: FormatNumberOptions = {}\n ): string => {\n if (value === null || value === undefined) {\n return '0'\n }\n\n const _value =\n typeof value === 'string' ? Number.parseFloat(value) : value\n\n const mergedOptions = {\n ...formatNumberDefaultOptions,\n ...options,\n }\n\n return intl.formatNumber(_value as number, mergedOptions) || ''\n },\n\n formatDate: (date?: string | number | Date): string => {\n return intl.formatDate(date)\n },\n\n formatTime: (date?: string | number | Date): string => {\n return intl.formatTime(date)\n },\n\n formatTimestamp: (\n timestamp?: number | string,\n options?: Intl.DateTimeFormatOptions\n ): string => {\n if (!timestamp) return ''\n\n const time = typeof timestamp === 'string' ? Number(timestamp) : timestamp\n const date = new Date(time * 1000)\n\n return intl.formatDate(date, options) || ''\n },\n\n setLocale: (locale: string, messages?: Record<string, string>): void => {\n currentConfig = {\n ...currentConfig,\n locale,\n messages: messages || currentConfig.messages,\n }\n intl = createIntl({\n ...currentConfig,\n defaultLocale: 'en-US',\n })\n localeChanged.value += 1\n },\n\n getLocale: (): string => {\n return currentConfig.locale\n },\n\n setFallbackTranslations: (\n fallbackMessagesInput: Record<string, string>\n ): void => {\n fallbackMessages = fallbackMessagesInput\n },\n\n localeChanged,\n }\n}\n\n/**\n * Set the global intl service\n * Call this once from your app initialization\n *\n * @param service - IntlService instance\n *\n * @example\n * ```typescript\n * import { setIntlService, createIntlService } from '@lukso/core/services/intl';\n *\n * const intl = createIntlService(config);\n * setIntlService(intl);\n * ```\n */\nexport function setIntlService(service: IntlService): void {\n intlService = service\n}\n\n/**\n * Get the current global intl service\n * Returns null if no service has been set\n *\n * @example\n * ```typescript\n * import { getIntlService } from '@lukso/core/services/intl';\n *\n * const intl = getIntlService();\n * if (intl) {\n * console.log(intl.getLocale());\n * }\n * ```\n */\nexport function getIntlService(): IntlService | null {\n return intlService\n}\n\n/**\n * Clear the global intl service\n * Useful for testing or cleanup\n */\nexport function clearIntlService(): void {\n intlService = null\n}\n"],"mappings":";AAMA;AAAA,EACE;AAAA,OAGK;AACP,SAAS,cAAc;AAMvB,IAAM,6BAA6B;AAAA,EACjC,uBAAuB;AACzB;AA8FO,IAAM,gBAA4B;AAAA,EACvC,QAAQ;AAAA,EACR,UAAU,CAAC;AACb;AAKA,IAAI,cAAkC;AA0B/B,SAAS,kBACd,SAAqB,eACR;AACb,MAAI,gBAAgB;AACpB,MAAI,OAAO,WAAW,EAAE,GAAG,eAAe,eAAe,QAAQ,CAAC;AAClE,QAAM,gBAAgB,OAAO,CAAC;AAC9B,MAAI,mBAA2C,CAAC;AAEhD,SAAO;AAAA,IACL,eAAe,CAAC,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;AAAA,IAEA,yBAAyB,CACvB,0BACS;AACT,yBAAmB;AAAA,IACrB;AAAA,IAEA;AAAA,EACF;AACF;AAgBO,SAAS,eAAe,SAA4B;AACzD,gBAAc;AAChB;AAgBO,SAAS,iBAAqC;AACnD,SAAO;AACT;AAMO,SAAS,mBAAyB;AACvC,gBAAc;AAChB;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/service-auth-simple/service-auth-simple/packages/core/dist/chunk-UOLYOGEV.cjs","../src/services/intl.ts"],"names":[],"mappings":"AAAA;ACMA;AACE;AAAA,sCAGK;AACP,mDAAuB;AAMvB,IAAM,2BAAA,EAA6B;AAAA,EACjC,qBAAA,EAAuB;AACzB,CAAA;AA8FO,IAAM,cAAA,EAA4B;AAAA,EACvC,MAAA,EAAQ,OAAA;AAAA,EACR,QAAA,EAAU,CAAC;AACb,CAAA;AAKA,IAAI,YAAA,EAAkC,IAAA;AA0B/B,SAAS,iBAAA,CACd,OAAA,EAAqB,aAAA,EACR;AACb,EAAA,IAAI,cAAA,EAAgB,MAAA;AACpB,EAAA,IAAI,KAAA,EAAO,8BAAA,EAAa,GAAG,aAAA,EAAe,aAAA,EAAe,QAAQ,CAAC,CAAA;AAClE,EAAA,MAAM,cAAA,EAAgB,iCAAA,CAAQ,CAAA;AAC9B,EAAA,IAAI,iBAAA,EAA2C,CAAC,CAAA;AAEhD,EAAA,OAAO;AAAA,IACL,aAAA,EAAe,CAAC,GAAA,EAAa,OAAA,EAAA,GAA6C;AACxE,MAAA,IAAI;AACF,QAAA,MAAM,OAAA,EAAS,IAAA,CAAK,aAAA,CAAc,EAAE,EAAA,EAAI,IAAI,CAAA,EAAG,OAAO,CAAA;AAEtD,QAAA,GAAA,CAAI,OAAA,GAAU,OAAA,IAAW,GAAA,EAAK;AAC5B,UAAA,OAAO,MAAA;AAAA,QACT;AAGA,QAAA,GAAA,CAAI,gBAAA,CAAiB,GAAG,CAAA,EAAG;AACzB,UAA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A,CAAW,IAAA,EAAM,OAAO,EAAA,GAAK,EAAA;AAAA,IAC3C,CAAA;AAAA,IAEA,SAAA,EAAW,CAAC,MAAA,EAAgB,QAAA,EAAA,GAA4C;AACtE,MAAA,cAAA,EAAgB;AAAA,QACd,GAAG,aAAA;AAAA,QACH,MAAA;AAAA,QACA,QAAA,EAAU,SAAA,GAAY,aAAA,CAAc;AAAA,MACtC,CAAA;AACA,MAAA,KAAA,EAAO,8BAAA;AAAW,QAChB,GAAG,aAAA;AAAA,QACH,aAAA,EAAe;AAAA,MACjB,CAAC,CAAA;AACD,MAAA,aAAA,CAAc,MAAA,GAAS,CAAA;AAAA,IACzB,CAAA;AAAA,IAEA,SAAA,EAAW,CAAA,EAAA,GAAc;AACvB,MAAA,OAAO,aAAA,CAAc,MAAA;AAAA,IACvB,CAAA;AAAA,IAEA,uBAAA,EAAyB,CACvB,qBAAA,EAAA,GACS;AACT,MAAA,iBAAA,EAAmB,qBAAA;AAAA,IACrB,CAAA;AAAA,IAEA;AAAA,EACF,CAAA;AACF;AAgBO,SAAS,cAAA,CAAe,OAAA,EAA4B;AACzD,EAAA,YAAA,EAAc,OAAA;AAChB;AAgBO,SAAS,cAAA,CAAA,EAAqC;AACnD,EAAA,OAAO,WAAA;AACT;AAMO,SAAS,gBAAA,CAAA,EAAyB;AACvC,EAAA,YAAA,EAAc,IAAA;AAChB;ADtMA;AACA;AACE;AACA;AACA;AACA;AACA;AACF,oNAAC","file":"/home/runner/work/service-auth-simple/service-auth-simple/packages/core/dist/chunk-UOLYOGEV.cjs","sourcesContent":[null,"/**\n * Internationalization Service\n *\n * Provides locale-aware formatting for messages, numbers, dates, and times.\n */\n\nimport {\n createIntl,\n type FormatNumberOptions,\n type IntlConfig,\n} from '@formatjs/intl'\nimport { signal } from '@preact/signals-core'\n\n/**\n * Default format number options\n * @see https://github.com/formatjs/formatjs/blob/main/packages/ecma402-abstract/types/number.ts\n */\nconst formatNumberDefaultOptions = {\n maximumFractionDigits: 18,\n}\n\n/**\n * Intl service interface\n */\nexport interface IntlService {\n /**\n * Translate a string based on the key\n *\n * @param key - translation key\n * @param options - optional options for formatMessage (for variable interpolation)\n * @returns - translated string\n */\n formatMessage: (key: string, options?: Record<string, string>) => string\n\n /**\n * Number formatting based on the locale\n *\n * @param value - number to format\n * @param options - options for formatNumber\n * @returns - formatted number\n */\n formatNumber: (\n value: number | string | bigint,\n options?: FormatNumberOptions\n ) => string\n\n /**\n * Date formatting based on the locale\n *\n * @param date - date to format\n * @returns - formatted date\n */\n formatDate: (date?: string | number | Date) => string | undefined\n\n /**\n * Time formatting based on the locale\n *\n * @param date - date to format\n * @returns - formatted time\n */\n formatTime: (date?: string | number | Date) => string | undefined\n\n /**\n * Timestamp formatting based on the locale\n *\n * @param timestamp - UNIX timestamp in seconds or milliseconds\n * @param options - optional Intl.DateTimeFormat options\n * @returns - formatted date & time string\n */\n formatTimestamp: (\n timestamp?: number | string,\n options?: Intl.DateTimeFormatOptions\n ) => string\n\n /**\n * Change the locale and optionally update messages\n *\n * @param locale - new locale code (e.g., 'en-US', 'de-DE')\n * @param messages - optional new messages object for the locale\n */\n setLocale: (locale: string, messages?: Record<string, string>) => void\n\n /**\n * Get the current locale\n *\n * @returns - current locale code (e.g., 'en-US', 'de-DE')\n */\n getLocale: () => string\n\n /**\n * Set fallback translations to use when a translation key is missing\n * Useful when the host app's intl service doesn't have all translations\n *\n * @param fallbackMessages - translations to use as fallback\n *\n * @example\n * ```typescript\n * // After intl service is initialized by host app\n * intl.setFallbackTranslations(defaultMessages);\n * ```\n */\n setFallbackTranslations: (fallbackMessages: Record<string, string>) => void\n\n /**\n * Signal that tracks locale changes\n * Use this signal to reactively update UI when locale changes\n */\n localeChanged: { value: number }\n}\n\n/**\n * Default configuration for intl\n */\nexport const defaultConfig: IntlConfig = {\n locale: 'en-US',\n messages: {},\n}\n\n/**\n * Global intl service instance\n */\nlet intlService: IntlService | null = null\n\n/**\n * Create a new intl service instance\n *\n * @param config - intl configuration with locale and messages\n * @returns IntlService instance with formatting methods\n *\n * @example\n * ```typescript\n * import { createIntlService } from '@lukso/core/services/intl';\n *\n * const intl = createIntlService({\n * locale: 'en-US',\n * messages: customMessages,\n * });\n *\n * const translated = intl.formatMessage('app.title');\n * const formatted = intl.formatNumber(1234.56);\n * const currentLocale = intl.getLocale(); // 'en-US'\n *\n * // Change locale\n * intl.setLocale('de-DE', germanMessages);\n * console.log(intl.getLocale()); // 'de-DE'\n * ```\n */\nexport function createIntlService(\n config: IntlConfig = defaultConfig\n): IntlService {\n let currentConfig = config\n let intl = createIntl({ ...currentConfig, defaultLocale: 'en-US' })\n const localeChanged = signal(0)\n let fallbackMessages: Record<string, string> = {}\n\n return {\n formatMessage: (key: string, options?: Record<string, string>): string => {\n try {\n const result = intl.formatMessage({ id: key }, options)\n\n if (result && result !== key) {\n return result\n }\n\n // If no translation found, check fallback\n if (fallbackMessages[key]) {\n return fallbackMessages[key]\n }\n\n return key\n } catch {\n // On error, try fallback\n return fallbackMessages[key] || key\n }\n },\n\n formatNumber: (\n value: number | string | bigint,\n options: FormatNumberOptions = {}\n ): string => {\n if (value === null || value === undefined) {\n return '0'\n }\n\n const _value =\n typeof value === 'string' ? Number.parseFloat(value) : value\n\n const mergedOptions = {\n ...formatNumberDefaultOptions,\n ...options,\n }\n\n return intl.formatNumber(_value as number, mergedOptions) || ''\n },\n\n formatDate: (date?: string | number | Date): string => {\n return intl.formatDate(date)\n },\n\n formatTime: (date?: string | number | Date): string => {\n return intl.formatTime(date)\n },\n\n formatTimestamp: (\n timestamp?: number | string,\n options?: Intl.DateTimeFormatOptions\n ): string => {\n if (!timestamp) return ''\n\n const time = typeof timestamp === 'string' ? Number(timestamp) : timestamp\n const date = new Date(time * 1000)\n\n return intl.formatDate(date, options) || ''\n },\n\n setLocale: (locale: string, messages?: Record<string, string>): void => {\n currentConfig = {\n ...currentConfig,\n locale,\n messages: messages || currentConfig.messages,\n }\n intl = createIntl({\n ...currentConfig,\n defaultLocale: 'en-US',\n })\n localeChanged.value += 1\n },\n\n getLocale: (): string => {\n return currentConfig.locale\n },\n\n setFallbackTranslations: (\n fallbackMessagesInput: Record<string, string>\n ): void => {\n fallbackMessages = fallbackMessagesInput\n },\n\n localeChanged,\n }\n}\n\n/**\n * Set the global intl service\n * Call this once from your app initialization\n *\n * @param service - IntlService instance\n *\n * @example\n * ```typescript\n * import { setIntlService, createIntlService } from '@lukso/core/services/intl';\n *\n * const intl = createIntlService(config);\n * setIntlService(intl);\n * ```\n */\nexport function setIntlService(service: IntlService): void {\n intlService = service\n}\n\n/**\n * Get the current global intl service\n * Returns null if no service has been set\n *\n * @example\n * ```typescript\n * import { getIntlService } from '@lukso/core/services/intl';\n *\n * const intl = getIntlService();\n * if (intl) {\n * console.log(intl.getLocale());\n * }\n * ```\n */\nexport function getIntlService(): IntlService | null {\n return intlService\n}\n\n/**\n * Clear the global intl service\n * Useful for testing or cleanup\n */\nexport function clearIntlService(): void {\n intlService = null\n}\n"]}
|
|
File without changes
|