@mmstack/translate 19.3.6 → 19.3.8
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/README.md +298 -181
- package/fesm2022/mmstack-translate.mjs +484 -96
- package/fesm2022/mmstack-translate.mjs.map +1 -1
- package/index.d.ts +2 -2
- package/lib/format/date.d.ts +77 -11
- package/lib/format/display-name.d.ts +37 -12
- package/lib/format/index.d.ts +1 -0
- package/lib/format/injection.d.ts +27 -0
- package/lib/format/list.d.ts +36 -9
- package/lib/format/numeric.d.ts +112 -27
- package/lib/format/provide-defaults.d.ts +5 -0
- package/lib/format/relative-time.d.ts +34 -10
- package/lib/path-param.d.ts +4 -0
- package/lib/register-namespace.d.ts +21 -1
- package/lib/{resovler-locale.d.ts → resolver-locale.d.ts} +3 -0
- package/lib/translation-store.d.ts +5 -0
- package/package.json +1 -1
package/lib/format/date.d.ts
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
import { type Signal } from '@angular/core';
|
|
2
|
-
declare const FORMAT_PRESETS:
|
|
2
|
+
declare const FORMAT_PRESETS: {
|
|
3
|
+
short: {
|
|
4
|
+
dateStyle: "short";
|
|
5
|
+
timeStyle: "short";
|
|
6
|
+
};
|
|
7
|
+
medium: {
|
|
8
|
+
dateStyle: "medium";
|
|
9
|
+
timeStyle: "medium";
|
|
10
|
+
};
|
|
11
|
+
long: {
|
|
12
|
+
dateStyle: "long";
|
|
13
|
+
timeStyle: "long";
|
|
14
|
+
};
|
|
15
|
+
full: {
|
|
16
|
+
dateStyle: "full";
|
|
17
|
+
timeStyle: "full";
|
|
18
|
+
};
|
|
19
|
+
shortDate: {
|
|
20
|
+
dateStyle: "short";
|
|
21
|
+
};
|
|
22
|
+
mediumDate: {
|
|
23
|
+
dateStyle: "medium";
|
|
24
|
+
};
|
|
25
|
+
longDate: {
|
|
26
|
+
dateStyle: "long";
|
|
27
|
+
};
|
|
28
|
+
fullDate: {
|
|
29
|
+
dateStyle: "full";
|
|
30
|
+
};
|
|
31
|
+
shortTime: {
|
|
32
|
+
timeStyle: "short";
|
|
33
|
+
};
|
|
34
|
+
mediumTime: {
|
|
35
|
+
timeStyle: "medium";
|
|
36
|
+
};
|
|
37
|
+
longTime: {
|
|
38
|
+
timeStyle: "long";
|
|
39
|
+
};
|
|
40
|
+
fullTime: {
|
|
41
|
+
timeStyle: "full";
|
|
42
|
+
};
|
|
43
|
+
};
|
|
3
44
|
type DateFormat = keyof typeof FORMAT_PRESETS;
|
|
4
45
|
/**
|
|
5
46
|
* Supported date inputs
|
|
@@ -17,19 +58,44 @@ export type FormatDateOptions = {
|
|
|
17
58
|
* Format to use for formatting
|
|
18
59
|
* @default 'medium'
|
|
19
60
|
*/
|
|
20
|
-
format?: DateFormat;
|
|
61
|
+
format?: DateFormat | Intl.DateTimeFormatOptions;
|
|
21
62
|
/**
|
|
22
|
-
* Locale to use for formatting
|
|
63
|
+
* Locale to use for formatting
|
|
23
64
|
*/
|
|
65
|
+
locale: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
69
|
+
*/
|
|
70
|
+
export type UnsafeFormatDateOptions = Omit<FormatDateOptions, 'locale'> & {
|
|
71
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
24
72
|
locale?: string;
|
|
25
73
|
};
|
|
26
74
|
/**
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* @
|
|
32
|
-
|
|
75
|
+
* @example formatDate(this.date, this.locale)
|
|
76
|
+
*/
|
|
77
|
+
export declare function formatDate(date: SupportedDateInput | Signal<SupportedDateInput>, locale: string | Signal<string>): string;
|
|
78
|
+
/**
|
|
79
|
+
* @example formatDate(this.date, { locale: 'sl-SI', format: 'shortDate' })
|
|
80
|
+
*/
|
|
81
|
+
export declare function formatDate(date: SupportedDateInput | Signal<SupportedDateInput>, opt: FormatDateOptions | Signal<FormatDateOptions>): string;
|
|
82
|
+
/**
|
|
83
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
84
|
+
* Use `injectFormatDate()` instead, or pass locale explicitly.
|
|
85
|
+
* @example formatDate(this.date)
|
|
86
|
+
*/
|
|
87
|
+
export declare function formatDate(date: SupportedDateInput | Signal<SupportedDateInput>, opt?: UnsafeFormatDateOptions | Signal<UnsafeFormatDateOptions>): string;
|
|
88
|
+
declare const provideFormatDateDefaults: (valueOrFn: Omit<Partial<FormatDateOptions>, "locale"> | (() => Omit<Partial<FormatDateOptions>, "locale"> | Signal<Omit<Partial<FormatDateOptions>, "locale">>)) => import("@angular/core").Provider;
|
|
89
|
+
/**
|
|
90
|
+
* Provide application-wide defaults for date formatting presets and timezones.
|
|
91
|
+
* @example provideFormatDateDefaults({ format: 'shortDate'})
|
|
92
|
+
*/
|
|
93
|
+
export { provideFormatDateDefaults };
|
|
94
|
+
/**
|
|
95
|
+
* Inject a context-safe date formatting function tied to the current injector.
|
|
96
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
97
|
+
* @example
|
|
98
|
+
* const formatDate = injectFormatDate();
|
|
99
|
+
* readonly displayDate = computed(() => formatDate(this.date()));
|
|
33
100
|
*/
|
|
34
|
-
export declare function
|
|
35
|
-
export {};
|
|
101
|
+
export declare function injectFormatDate(): (date: SupportedDateInput | Signal<SupportedDateInput>, optOrLocale?: Partial<FormatDateOptions> | Signal<Partial<FormatDateOptions>> | string | Signal<string>) => string;
|
|
@@ -1,26 +1,51 @@
|
|
|
1
|
-
import { Signal } from '@angular/core';
|
|
1
|
+
import { type Signal } from '@angular/core';
|
|
2
2
|
/**
|
|
3
3
|
* Options for formatting a display name
|
|
4
4
|
*/
|
|
5
5
|
export type FormatDisplayNameOptions = {
|
|
6
6
|
/**
|
|
7
7
|
* The display style for the result set
|
|
8
|
+
* @default 'long'
|
|
8
9
|
*/
|
|
9
|
-
style
|
|
10
|
+
style?: Intl.RelativeTimeFormatStyle;
|
|
10
11
|
/**
|
|
11
|
-
* Locale to use for formatting
|
|
12
|
+
* Locale to use for formatting
|
|
12
13
|
*/
|
|
14
|
+
locale: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
18
|
+
*/
|
|
19
|
+
export type UnsafeFormatDisplayNameOptions = Omit<FormatDisplayNameOptions, 'locale'> & {
|
|
20
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
13
21
|
locale?: string;
|
|
14
22
|
};
|
|
15
23
|
type SupportedCode = string | null | undefined;
|
|
16
24
|
/**
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* @
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
* @example formatDisplayName(this.value, 'region', this.locale)
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatDisplayName(value: SupportedCode | Signal<SupportedCode>, type: Intl.DisplayNamesType | Signal<Intl.DisplayNamesType>, locale: string | Signal<string>): string;
|
|
28
|
+
/**
|
|
29
|
+
* @example formatDisplayName(this.value, 'region', {locale: 'en-US', style: 'long'})
|
|
30
|
+
*/
|
|
31
|
+
export declare function formatDisplayName(value: SupportedCode | Signal<SupportedCode>, type: Intl.DisplayNamesType | Signal<Intl.DisplayNamesType>, opt: FormatDisplayNameOptions | Signal<FormatDisplayNameOptions>): string;
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
34
|
+
* Use `injectFormatDisplayName()` instead, or pass locale explicitly.
|
|
35
|
+
* @example formatDisplayName(this.value)
|
|
36
|
+
*/
|
|
37
|
+
export declare function formatDisplayName(value: SupportedCode | Signal<SupportedCode>, type: Intl.DisplayNamesType | Signal<Intl.DisplayNamesType>, opt?: UnsafeFormatDisplayNameOptions | Signal<UnsafeFormatDisplayNameOptions>): string;
|
|
38
|
+
declare const provideFormatDisplayNameDefaults: (valueOrFn: Omit<Partial<FormatDisplayNameOptions>, "locale"> | (() => Omit<Partial<FormatDisplayNameOptions>, "locale"> | Signal<Omit<Partial<FormatDisplayNameOptions>, "locale">>)) => import("@angular/core").Provider;
|
|
39
|
+
/**
|
|
40
|
+
* Provide application-wide defaults for display name formatting presets and timezones.
|
|
41
|
+
* @example provideFormatDisplayNameDefaults({ style: 'long'})
|
|
42
|
+
*/
|
|
43
|
+
export { provideFormatDisplayNameDefaults };
|
|
44
|
+
/**
|
|
45
|
+
* Inject a context-safe date formatting function tied to the current injector.
|
|
46
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
47
|
+
* @example
|
|
48
|
+
* const formatDisplayName = injectFormatDisplayName();
|
|
49
|
+
* readonly region = computed(() => formatDisplayName('US', 'region'));
|
|
24
50
|
*/
|
|
25
|
-
export declare function
|
|
26
|
-
export {};
|
|
51
|
+
export declare function injectFormatDisplayName(): (value: SupportedCode | Signal<SupportedCode>, type: Intl.DisplayNamesType | Signal<Intl.DisplayNamesType>, localeOrOpt?: FormatDisplayNameOptions | Signal<FormatDisplayNameOptions> | string | Signal<string>) => string;
|
package/lib/format/index.d.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Provider } from '@angular/core';
|
|
2
|
+
import { provideFormatDateDefaults } from './date';
|
|
3
|
+
import { provideFormatDisplayNameDefaults } from './display-name';
|
|
4
|
+
import { provideFormatListDefaults } from './list';
|
|
5
|
+
import { provideFormatCurrencyDefaults, provideFormatNumberDefaults, provideFormatPercentDefaults } from './numeric';
|
|
6
|
+
import type { inferProvideParameter } from './provide-defaults';
|
|
7
|
+
import { provideFormatRelativeTimeDefaults } from './relative-time';
|
|
8
|
+
type FormatDefaults = {
|
|
9
|
+
date?: inferProvideParameter<typeof provideFormatDateDefaults>;
|
|
10
|
+
displayName?: inferProvideParameter<typeof provideFormatDisplayNameDefaults>;
|
|
11
|
+
list?: inferProvideParameter<typeof provideFormatListDefaults>;
|
|
12
|
+
relativeTime?: inferProvideParameter<typeof provideFormatRelativeTimeDefaults>;
|
|
13
|
+
number?: inferProvideParameter<typeof provideFormatNumberDefaults>;
|
|
14
|
+
percent?: inferProvideParameter<typeof provideFormatPercentDefaults>;
|
|
15
|
+
currency?: inferProvideParameter<typeof provideFormatCurrencyDefaults>;
|
|
16
|
+
};
|
|
17
|
+
export declare function provideFormatDefaults(cfg: FormatDefaults): Provider[];
|
|
18
|
+
export declare function injectFormatters(): {
|
|
19
|
+
date: (date: import("@mmstack/translate").SupportedDateInput | import("@angular/core").Signal<import("@mmstack/translate").SupportedDateInput>, optOrLocale?: Partial<import("@mmstack/translate").FormatDateOptions> | import("@angular/core").Signal<Partial<import("@mmstack/translate").FormatDateOptions>> | string | import("@angular/core").Signal<string>) => string;
|
|
20
|
+
displayName: (value: (string | null | undefined) | import("@angular/core").Signal<string | null | undefined>, type: Intl.DisplayNamesType | import("@angular/core").Signal<Intl.DisplayNamesType>, localeOrOpt?: import("@mmstack/translate").FormatDisplayNameOptions | import("@angular/core").Signal<import("@mmstack/translate").FormatDisplayNameOptions> | string | import("@angular/core").Signal<string>) => string;
|
|
21
|
+
list: (value: import("@mmstack/translate").SupportedListInput | import("@angular/core").Signal<import("@mmstack/translate").SupportedListInput>, optOrLocale?: Partial<import("@mmstack/translate").FormatListOptions> | import("@angular/core").Signal<Partial<import("@mmstack/translate").FormatListOptions>> | string | import("@angular/core").Signal<string>) => string;
|
|
22
|
+
relativeTime: (value: (number | null | undefined) | import("@angular/core").Signal<number | null | undefined>, unit: import("@mmstack/translate").RelativeTimeUnit | import("@angular/core").Signal<import("@mmstack/translate").RelativeTimeUnit>, optOrLocale?: Partial<import("@mmstack/translate").FormatRelativeTimeOptions> | import("@angular/core").Signal<Partial<import("@mmstack/translate").FormatRelativeTimeOptions>> | string | import("@angular/core").Signal<string>) => string;
|
|
23
|
+
number: (value: (number | null | undefined) | import("@angular/core").Signal<number | null | undefined>, optOrLocale?: Partial<import("@mmstack/translate").FormatNumberOptions> | import("@angular/core").Signal<Partial<import("@mmstack/translate").FormatNumberOptions>> | string | import("@angular/core").Signal<string>) => string;
|
|
24
|
+
percent: (value: (number | null | undefined) | import("@angular/core").Signal<number | null | undefined>, optOrLocale?: Partial<import("@mmstack/translate").FormatPercentOptions> | import("@angular/core").Signal<Partial<import("@mmstack/translate").FormatPercentOptions>> | string | import("@angular/core").Signal<string>) => string;
|
|
25
|
+
currency: (value: (number | null | undefined) | import("@angular/core").Signal<number | null | undefined>, currency: string | import("@angular/core").Signal<string>, optOrLocale?: Partial<import("@mmstack/translate").FormatCurrencyOptions> | import("@angular/core").Signal<Partial<import("@mmstack/translate").FormatCurrencyOptions>> | string | import("@angular/core").Signal<string>) => string;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
package/lib/format/list.d.ts
CHANGED
|
@@ -8,24 +8,51 @@ export type SupportedListInput = string[] | null | undefined;
|
|
|
8
8
|
export type FormatListOptions = {
|
|
9
9
|
/**
|
|
10
10
|
* The type of list to format
|
|
11
|
+
* @default 'conjunction'
|
|
11
12
|
*/
|
|
12
13
|
type?: ListType;
|
|
13
14
|
/**
|
|
14
15
|
* The style of list to format
|
|
16
|
+
* @default 'long'
|
|
15
17
|
*/
|
|
16
18
|
style?: ListStyle;
|
|
17
19
|
/**
|
|
18
|
-
* Locale to use for formatting
|
|
20
|
+
* Locale to use for formatting
|
|
19
21
|
*/
|
|
22
|
+
locale: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
26
|
+
*/
|
|
27
|
+
export type UnsafeFormatListOptions = Omit<FormatListOptions, 'locale'> & {
|
|
28
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
20
29
|
locale?: string;
|
|
21
30
|
};
|
|
22
31
|
/**
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* @
|
|
28
|
-
|
|
32
|
+
* @example formatList(this.items, this.locale)
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatList(value: SupportedListInput | Signal<SupportedListInput>, locale: string | Signal<string>): string;
|
|
35
|
+
/**
|
|
36
|
+
* @example formatList(this.items, { locale: 'sl-SI', type: 'disjunction' })
|
|
37
|
+
*/
|
|
38
|
+
export declare function formatList(value: SupportedListInput | Signal<SupportedListInput>, opt: FormatListOptions | Signal<FormatListOptions>): string;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
41
|
+
* Use `injectFormatList()` instead, or pass locale explicitly.
|
|
42
|
+
* @example formatList(this.items)
|
|
43
|
+
*/
|
|
44
|
+
export declare function formatList(value: SupportedListInput | Signal<SupportedListInput>, opt?: UnsafeFormatListOptions | Signal<UnsafeFormatListOptions>): string;
|
|
45
|
+
declare const provideFormatListDefaults: (valueOrFn: Omit<Partial<FormatListOptions>, "locale"> | (() => Omit<Partial<FormatListOptions>, "locale"> | Signal<Omit<Partial<FormatListOptions>, "locale">>)) => import("@angular/core").Provider;
|
|
46
|
+
/**
|
|
47
|
+
* Provide application-wide defaults for list formatting presets.
|
|
48
|
+
* @example provideFormatListDefaults({ type: 'disjunction' })
|
|
49
|
+
*/
|
|
50
|
+
export { provideFormatListDefaults };
|
|
51
|
+
/**
|
|
52
|
+
* Inject a context-safe list formatting function tied to the current injector.
|
|
53
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
54
|
+
* @example
|
|
55
|
+
* const formatList = injectFormatList();
|
|
56
|
+
* readonly displayList = computed(() => formatList(this.items()));
|
|
29
57
|
*/
|
|
30
|
-
export declare function
|
|
31
|
-
export {};
|
|
58
|
+
export declare function injectFormatList(): (value: SupportedListInput | Signal<SupportedListInput>, optOrLocale?: Partial<FormatListOptions> | Signal<Partial<FormatListOptions>> | string | Signal<string>) => string;
|
package/lib/format/numeric.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ type SupportedNumberValue = number | null | undefined;
|
|
|
7
7
|
export type FormatNumberOptions = {
|
|
8
8
|
/**
|
|
9
9
|
* The notation to use for formatting
|
|
10
|
+
* @default 'standard'
|
|
10
11
|
*/
|
|
11
12
|
notation?: NumberNotation;
|
|
12
13
|
/**
|
|
@@ -19,27 +20,54 @@ export type FormatNumberOptions = {
|
|
|
19
20
|
maxFractionDigits?: number;
|
|
20
21
|
/**
|
|
21
22
|
* Whether to use grouping
|
|
23
|
+
* @default true
|
|
22
24
|
*/
|
|
23
25
|
useGrouping?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Locale to use for formatting, opts out to dynamic locale changes
|
|
26
|
-
*/
|
|
27
|
-
locale?: string;
|
|
28
26
|
/**
|
|
29
27
|
* If the number is not a valid number, return formatted 0. By default formatter returns an empty string
|
|
30
28
|
* @default false
|
|
31
29
|
*/
|
|
32
30
|
fallbackToZero?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Locale to use for formatting
|
|
33
|
+
*/
|
|
34
|
+
locale: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
38
|
+
*/
|
|
39
|
+
export type UnsafeFormatNumberOptions = Omit<FormatNumberOptions, 'locale'> & {
|
|
40
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
41
|
+
locale?: string;
|
|
33
42
|
};
|
|
34
43
|
/**
|
|
35
|
-
*
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* @
|
|
40
|
-
* @returns Formatted number string
|
|
44
|
+
* @example formatNumber(this.value, this.locale)
|
|
45
|
+
*/
|
|
46
|
+
export declare function formatNumber(value: SupportedNumberValue | Signal<SupportedNumberValue>, locale: string | Signal<string>): string;
|
|
47
|
+
/**
|
|
48
|
+
* @example formatNumber(this.value, { locale: 'de-DE', notation: 'compact' })
|
|
41
49
|
*/
|
|
42
|
-
export declare function formatNumber(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt
|
|
50
|
+
export declare function formatNumber(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt: FormatNumberOptions | Signal<FormatNumberOptions>): string;
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
53
|
+
* Use `injectFormatNumber()` instead, or pass locale explicitly.
|
|
54
|
+
* @example formatNumber(this.value)
|
|
55
|
+
*/
|
|
56
|
+
export declare function formatNumber(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt?: UnsafeFormatNumberOptions | Signal<UnsafeFormatNumberOptions>): string;
|
|
57
|
+
declare const provideFormatNumberDefaults: (valueOrFn: Omit<Partial<FormatNumberOptions>, "locale"> | (() => Omit<Partial<FormatNumberOptions>, "locale"> | Signal<Omit<Partial<FormatNumberOptions>, "locale">>)) => import("@angular/core").Provider;
|
|
58
|
+
/**
|
|
59
|
+
* Provide application-wide defaults for number formatting presets.
|
|
60
|
+
* @example provideFormatNumberDefaults({ notation: 'compact' })
|
|
61
|
+
*/
|
|
62
|
+
export { provideFormatNumberDefaults };
|
|
63
|
+
/**
|
|
64
|
+
* Inject a context-safe number formatting function tied to the current injector.
|
|
65
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
66
|
+
* @example
|
|
67
|
+
* const formatNumber = injectFormatNumber();
|
|
68
|
+
* readonly display = computed(() => formatNumber(this.value()));
|
|
69
|
+
*/
|
|
70
|
+
export declare function injectFormatNumber(): (value: SupportedNumberValue | Signal<SupportedNumberValue>, optOrLocale?: Partial<FormatNumberOptions> | Signal<Partial<FormatNumberOptions>> | string | Signal<string>) => string;
|
|
43
71
|
/**
|
|
44
72
|
* Options for formatting a percentage value
|
|
45
73
|
*/
|
|
@@ -52,40 +80,97 @@ export type FormatPercentOptions = {
|
|
|
52
80
|
* Maximum number of fraction digits to use
|
|
53
81
|
*/
|
|
54
82
|
maxFractionDigits?: number;
|
|
55
|
-
/**
|
|
56
|
-
* Locale to use for formatting, opts out to dynamic locale changes
|
|
57
|
-
*/
|
|
58
|
-
locale?: string;
|
|
59
83
|
/**
|
|
60
84
|
* If the number is not a valid number, return formatted 0. By default formatter returns an empty string
|
|
61
85
|
* @default false
|
|
62
86
|
*/
|
|
63
87
|
fallbackToZero?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Locale to use for formatting
|
|
90
|
+
*/
|
|
91
|
+
locale: string;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
95
|
+
*/
|
|
96
|
+
export type UnsafeFormatPercentOptions = Omit<FormatPercentOptions, 'locale'> & {
|
|
97
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
98
|
+
locale?: string;
|
|
64
99
|
};
|
|
65
100
|
/**
|
|
66
|
-
*
|
|
67
|
-
* By default it is reactive to the global dynamic locale, works best when wrapped in a computed() if you need to react to locale changes
|
|
68
|
-
*
|
|
69
|
-
* @param number - Number to format
|
|
70
|
-
* @param opt - Options for formatting
|
|
71
|
-
* @returns Formatted percentage string
|
|
101
|
+
* @example formatPercent(this.value, this.locale)
|
|
72
102
|
*/
|
|
73
|
-
export declare function formatPercent(value: SupportedNumberValue | Signal<SupportedNumberValue>,
|
|
103
|
+
export declare function formatPercent(value: SupportedNumberValue | Signal<SupportedNumberValue>, locale: string | Signal<string>): string;
|
|
104
|
+
/**
|
|
105
|
+
* @example formatPercent(this.value, { locale: 'de-DE', maxFractionDigits: 2 })
|
|
106
|
+
*/
|
|
107
|
+
export declare function formatPercent(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt: FormatPercentOptions | Signal<FormatPercentOptions>): string;
|
|
108
|
+
/**
|
|
109
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
110
|
+
* Use `injectFormatPercent()` instead, or pass locale explicitly.
|
|
111
|
+
* @example formatPercent(this.value)
|
|
112
|
+
*/
|
|
113
|
+
export declare function formatPercent(value: SupportedNumberValue | Signal<SupportedNumberValue>, opt?: UnsafeFormatPercentOptions | Signal<UnsafeFormatPercentOptions>): string;
|
|
114
|
+
declare const provideFormatPercentDefaults: (valueOrFn: Omit<Partial<FormatPercentOptions>, "locale"> | (() => Omit<Partial<FormatPercentOptions>, "locale"> | Signal<Omit<Partial<FormatPercentOptions>, "locale">>)) => import("@angular/core").Provider;
|
|
115
|
+
/**
|
|
116
|
+
* Provide application-wide defaults for percent formatting presets.
|
|
117
|
+
* @example provideFormatPercentDefaults({ maxFractionDigits: 1 })
|
|
118
|
+
*/
|
|
119
|
+
export { provideFormatPercentDefaults };
|
|
120
|
+
/**
|
|
121
|
+
* Inject a context-safe percent formatting function tied to the current injector.
|
|
122
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
123
|
+
*/
|
|
124
|
+
export declare function injectFormatPercent(): (value: SupportedNumberValue | Signal<SupportedNumberValue>, optOrLocale?: Partial<FormatPercentOptions> | Signal<Partial<FormatPercentOptions>> | string | Signal<string>) => string;
|
|
74
125
|
type CurrencyDisplay = 'symbol' | 'narrowSymbol' | 'code' | 'name';
|
|
75
126
|
/**
|
|
76
127
|
* Options for formatting a currency
|
|
77
128
|
*/
|
|
78
129
|
export type FormatCurrencyOptions = {
|
|
79
|
-
display?: CurrencyDisplay;
|
|
80
130
|
/**
|
|
81
|
-
*
|
|
131
|
+
* The display type for the currency format
|
|
132
|
+
* @default 'symbol'
|
|
82
133
|
*/
|
|
83
|
-
|
|
134
|
+
display?: CurrencyDisplay;
|
|
84
135
|
/**
|
|
85
136
|
* If the number is not a valid number, return formatted 0. By default formatter returns an empty string
|
|
86
137
|
* @default false
|
|
87
138
|
*/
|
|
88
139
|
fallbackToZero?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Locale to use for formatting
|
|
142
|
+
*/
|
|
143
|
+
locale: string;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
147
|
+
*/
|
|
148
|
+
export type UnsafeFormatCurrencyOptions = Omit<FormatCurrencyOptions, 'locale'> & {
|
|
149
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
150
|
+
locale?: string;
|
|
89
151
|
};
|
|
90
|
-
|
|
91
|
-
|
|
152
|
+
/**
|
|
153
|
+
* @example formatCurrency(this.value, 'USD', this.locale)
|
|
154
|
+
*/
|
|
155
|
+
export declare function formatCurrency(value: SupportedNumberValue | Signal<SupportedNumberValue>, currency: string | Signal<string>, locale: string | Signal<string>): string;
|
|
156
|
+
/**
|
|
157
|
+
* @example formatCurrency(this.value, 'EUR', { locale: 'de-DE', display: 'code' })
|
|
158
|
+
*/
|
|
159
|
+
export declare function formatCurrency(value: SupportedNumberValue | Signal<SupportedNumberValue>, currency: string | Signal<string>, opt: FormatCurrencyOptions | Signal<FormatCurrencyOptions>): string;
|
|
160
|
+
/**
|
|
161
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
162
|
+
* Use `injectFormatCurrency()` instead, or pass locale explicitly.
|
|
163
|
+
* @example formatCurrency(this.value, 'USD')
|
|
164
|
+
*/
|
|
165
|
+
export declare function formatCurrency(value: SupportedNumberValue | Signal<SupportedNumberValue>, currency: string | Signal<string>, opt?: UnsafeFormatCurrencyOptions | Signal<UnsafeFormatCurrencyOptions>): string;
|
|
166
|
+
declare const provideFormatCurrencyDefaults: (valueOrFn: Omit<Partial<FormatCurrencyOptions>, "locale"> | (() => Omit<Partial<FormatCurrencyOptions>, "locale"> | Signal<Omit<Partial<FormatCurrencyOptions>, "locale">>)) => import("@angular/core").Provider;
|
|
167
|
+
/**
|
|
168
|
+
* Provide application-wide defaults for currency formatting presets.
|
|
169
|
+
* @example provideFormatCurrencyDefaults({ display: 'code' })
|
|
170
|
+
*/
|
|
171
|
+
export { provideFormatCurrencyDefaults };
|
|
172
|
+
/**
|
|
173
|
+
* Inject a context-safe currency formatting function tied to the current injector.
|
|
174
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
175
|
+
*/
|
|
176
|
+
export declare function injectFormatCurrency(): (value: SupportedNumberValue | Signal<SupportedNumberValue>, currency: string | Signal<string>, optOrLocale?: Partial<FormatCurrencyOptions> | Signal<Partial<FormatCurrencyOptions>> | string | Signal<string>) => string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Provider, type Signal } from '@angular/core';
|
|
2
|
+
export declare function createFormatterProvider<T extends {
|
|
3
|
+
locale: string;
|
|
4
|
+
}>(formatterName: string, libraryDefaults: Omit<T, 'locale'>, nonLocaleEqual: (a: Omit<T, 'locale'>, b: Omit<T, 'locale'>) => boolean): readonly [(valueOrFn: Omit<Partial<T>, "locale"> | (() => Omit<Partial<T>, "locale"> | Signal<Omit<Partial<T>, "locale">>)) => Provider, () => Signal<T>];
|
|
5
|
+
export type inferProvideParameter<T extends ReturnType<typeof createFormatterProvider>[0]> = Parameters<T>[0];
|
|
@@ -14,20 +14,44 @@ export type FormatRelativeTimeOptions = {
|
|
|
14
14
|
*/
|
|
15
15
|
numeric?: Intl.RelativeTimeFormatNumeric;
|
|
16
16
|
/**
|
|
17
|
-
* Locale to use for formatting
|
|
17
|
+
* Locale to use for formatting
|
|
18
18
|
*/
|
|
19
|
+
locale: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated UNSAFE FOR SSR/EDGE. Omitting the locale property forces a fallback to a process-level global singleton.
|
|
23
|
+
*/
|
|
24
|
+
export type UnsafeFormatRelativeTimeOptions = Omit<FormatRelativeTimeOptions, 'locale'> & {
|
|
25
|
+
/** Optional locale string falling back to the legacy global signal */
|
|
19
26
|
locale?: string;
|
|
20
27
|
};
|
|
21
28
|
export type RelativeTimeUnit = Intl.RelativeTimeFormatUnit;
|
|
22
29
|
type SupportedRelativeTimeInput = number | null | undefined;
|
|
23
30
|
/**
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* @
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
* @example formatRelativeTime(this.value, this.unit, this.locale)
|
|
32
|
+
*/
|
|
33
|
+
export declare function formatRelativeTime(value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, locale: string | Signal<string>): string;
|
|
34
|
+
/**
|
|
35
|
+
* @example formatRelativeTime(this.value, 'day', { locale: 'sl-SI', numeric: 'auto' })
|
|
36
|
+
*/
|
|
37
|
+
export declare function formatRelativeTime(value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, opt: FormatRelativeTimeOptions | Signal<FormatRelativeTimeOptions>): string;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated UNSAFE FOR SSR/EDGE. This signature reads from a process-level global singleton, will be fully removed when Angular 23 drops
|
|
40
|
+
* Use `injectFormatRelativeTime()` instead, or pass locale explicitly.
|
|
41
|
+
* @example formatRelativeTime(this.value, 'day')
|
|
42
|
+
*/
|
|
43
|
+
export declare function formatRelativeTime(value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, opt?: UnsafeFormatRelativeTimeOptions | Signal<UnsafeFormatRelativeTimeOptions>): string;
|
|
44
|
+
declare const provideFormatRelativeTimeDefaults: (valueOrFn: Omit<Partial<FormatRelativeTimeOptions>, "locale"> | (() => Omit<Partial<FormatRelativeTimeOptions>, "locale"> | Signal<Omit<Partial<FormatRelativeTimeOptions>, "locale">>)) => import("@angular/core").Provider;
|
|
45
|
+
/**
|
|
46
|
+
* Provide application-wide defaults for relative time formatting presets.
|
|
47
|
+
* @example provideFormatRelativeTimeDefaults({ numeric: 'auto' })
|
|
48
|
+
*/
|
|
49
|
+
export { provideFormatRelativeTimeDefaults };
|
|
50
|
+
/**
|
|
51
|
+
* Inject a context-safe relative time formatting function tied to the current injector.
|
|
52
|
+
* Uses the libraries locale signal & provided default configuration to react to locale/config changes
|
|
53
|
+
* @example
|
|
54
|
+
* const formatRelativeTime = injectFormatRelativeTime();
|
|
55
|
+
* readonly relativeAge = computed(() => formatRelativeTime(this.delta(), 'day'));
|
|
31
56
|
*/
|
|
32
|
-
export declare function
|
|
33
|
-
export {};
|
|
57
|
+
export declare function injectFormatRelativeTime(): (value: SupportedRelativeTimeInput | Signal<SupportedRelativeTimeInput>, unit: RelativeTimeUnit | Signal<RelativeTimeUnit>, optOrLocale?: Partial<FormatRelativeTimeOptions> | Signal<Partial<FormatRelativeTimeOptions>> | string | Signal<string>) => string;
|
package/lib/path-param.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { type Signal } from '@angular/core';
|
|
2
2
|
import { ActivatedRoute } from '@angular/router';
|
|
3
|
+
/**
|
|
4
|
+
* Dynamic path parameter signal, that allows resolution even when paramsInheritenceStrategy isnt always
|
|
5
|
+
* This helper depends on an internal
|
|
6
|
+
*/
|
|
3
7
|
export declare function pathParam(key: string | (() => string), route?: ActivatedRoute): Signal<string | null>;
|
|
@@ -11,7 +11,27 @@ type TFunctionWithSignalConstructor<TMap extends AnyStringRecord, TFN extends TF
|
|
|
11
11
|
};
|
|
12
12
|
export declare function addSignalFn<TMap extends AnyStringRecord, TFn extends TFunction<TMap>>(fn: TFn, store: TranslationStore, keyMap: Map<string, string>): TFunctionWithSignalConstructor<TMap, TFn>;
|
|
13
13
|
export declare function createT<TMap extends AnyStringRecord>(store: TranslationStore, keyMap?: Map<string, string>): TFunction<TMap>;
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Shape accepted by a namespace loader: a direct `CompiledTranslation`, or an
|
|
16
|
+
* ES-module-style object exposing one as `default` or `translation`. Lets
|
|
17
|
+
* callers write `() => import('./quote.namespace')` instead of the more
|
|
18
|
+
* verbose `() => import('./quote.namespace').then((m) => m.default)`.
|
|
19
|
+
*/
|
|
20
|
+
export type LoadedTranslation<T extends CompiledTranslation<UnknownStringKeyObject, string>> = T | {
|
|
21
|
+
default: T;
|
|
22
|
+
} | {
|
|
23
|
+
translation: T;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* @internal exported for unit testing
|
|
27
|
+
*
|
|
28
|
+
* Unwraps a loader result to a `CompiledTranslation`. Detection order:
|
|
29
|
+
* 1. value is already a `CompiledTranslation` (has `flat` + `namespace`)
|
|
30
|
+
* 2. value has a `default` export holding a `CompiledTranslation` (ESM default)
|
|
31
|
+
* 3. value has a `translation` export holding a `CompiledTranslation` (named export)
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveTranslationModule<T extends CompiledTranslation<UnknownStringKeyObject, string>>(loaded: LoadedTranslation<T>): T;
|
|
34
|
+
export declare function registerNamespace<TDefault extends CompiledTranslation<UnknownStringKeyObject, string>>(defaultTranslation: () => Promise<LoadedTranslation<TDefault>>, other: Record<string, () => Promise<LoadedTranslation<CompiledTranslation<UnknownStringKeyObject, inferCompiledTranslationNamespace<TDefault>, string>>>>): {
|
|
15
35
|
injectNamespaceT: () => TFunctionWithSignalConstructor<inferCompiledTranslationMap<TDefault>, TFunction<inferCompiledTranslationMap<TDefault>>>;
|
|
16
36
|
resolveNamespaceTranslation: ResolveFn<void>;
|
|
17
37
|
};
|
|
@@ -28,6 +28,11 @@ export declare function provideIntlConfig(config: Config): Provider[];
|
|
|
28
28
|
export declare function injectIntlConfig(): Config | undefined;
|
|
29
29
|
export declare function injectDefaultLocale(): string;
|
|
30
30
|
export declare function injectSupportedLocales(): string[];
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
* @deprecated will be removed when ng23 drops
|
|
34
|
+
*/
|
|
35
|
+
export declare function readLocaleUnsafe(): string;
|
|
31
36
|
export declare function injectLocaleInternal(): WritableSignal<string>;
|
|
32
37
|
export declare class TranslationStore {
|
|
33
38
|
private readonly simpleKeyMap;
|