@gooddata/sdk-ui-kit 11.13.0-alpha.1 → 11.13.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableBulkActions.d.ts.map +1 -1
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableBulkActions.js +2 -2
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableBulkActions.js.map +1 -1
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableCheckbox.js +1 -1
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableCheckbox.js.map +1 -1
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableDropdownItem.d.ts +1 -2
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableDropdownItem.d.ts.map +1 -1
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableDropdownItem.js +3 -3
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableDropdownItem.js.map +1 -1
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableFilter.d.ts.map +1 -1
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableFilter.js +2 -1
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableFilter.js.map +1 -1
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableToolbar.js +2 -2
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableToolbar.js.map +1 -1
- package/esm/@ui/UiAsyncTable/types.d.ts +3 -0
- package/esm/@ui/UiAsyncTable/types.d.ts.map +1 -1
- package/esm/@ui/UiBadge/UiBadge.d.ts +0 -1
- package/esm/@ui/UiBadge/UiBadge.d.ts.map +1 -1
- package/esm/@ui/UiBadge/UiBadge.js +0 -1
- package/esm/@ui/UiBadge/UiBadge.js.map +1 -1
- package/esm/@ui/UiButton/UiButton.d.ts.map +1 -1
- package/esm/@ui/UiButton/UiButton.js +1 -1
- package/esm/@ui/UiButton/UiButton.js.map +1 -1
- package/esm/@ui/UiCheckbox/UiCheckbox.d.ts.map +1 -1
- package/esm/@ui/UiCheckbox/UiCheckbox.js +9 -1
- package/esm/@ui/UiCheckbox/UiCheckbox.js.map +1 -1
- package/esm/@ui/UiPaginationButton/UiPaginationButton.d.ts +85 -0
- package/esm/@ui/UiPaginationButton/UiPaginationButton.d.ts.map +1 -0
- package/esm/@ui/UiPaginationButton/UiPaginationButton.js +28 -0
- package/esm/@ui/UiPaginationButton/UiPaginationButton.js.map +1 -0
- package/esm/ChartSorting/ChartSorting.d.ts +0 -4
- package/esm/ChartSorting/ChartSorting.d.ts.map +1 -1
- package/esm/ChartSorting/ChartSorting.js +1 -4
- package/esm/ChartSorting/ChartSorting.js.map +1 -1
- package/esm/ColorPicker/ColorPicker.d.ts +1 -4
- package/esm/ColorPicker/ColorPicker.d.ts.map +1 -1
- package/esm/ColorPicker/ColorPicker.js +6 -7
- package/esm/ColorPicker/ColorPicker.js.map +1 -1
- package/esm/DocumentHeader/DocumentHeader.d.ts +1 -1
- package/esm/DocumentHeader/DocumentHeader.d.ts.map +1 -1
- package/esm/DocumentHeader/DocumentHeader.js +1 -1
- package/esm/DocumentHeader/DocumentHeader.js.map +1 -1
- package/esm/DocumentHeader/index.d.ts +1 -1
- package/esm/DocumentHeader/index.d.ts.map +1 -1
- package/esm/DocumentHeader/index.js +2 -1
- package/esm/DocumentHeader/index.js.map +1 -1
- package/esm/Dropdown/DropdownButton.js +1 -1
- package/esm/Dropdown/DropdownButton.js.map +1 -1
- package/esm/FilterLabel/FilterLabel.d.ts +1 -4
- package/esm/FilterLabel/FilterLabel.d.ts.map +1 -1
- package/esm/FilterLabel/FilterLabel.js +7 -7
- package/esm/FilterLabel/FilterLabel.js.map +1 -1
- package/esm/Form/InputWithNumberFormat.d.ts +2 -39
- package/esm/Form/InputWithNumberFormat.d.ts.map +1 -1
- package/esm/Form/InputWithNumberFormat.js +33 -50
- package/esm/Form/InputWithNumberFormat.js.map +1 -1
- package/esm/Header/Header.d.ts +1 -2
- package/esm/Header/Header.d.ts.map +1 -1
- package/esm/Header/Header.js +7 -7
- package/esm/Header/Header.js.map +1 -1
- package/esm/Header/HeaderDataMenu.d.ts +0 -1
- package/esm/Header/HeaderDataMenu.d.ts.map +1 -1
- package/esm/Header/HeaderDataMenu.js +1 -1
- package/esm/Header/HeaderDataMenu.js.map +1 -1
- package/esm/Header/HeaderHelp.d.ts +0 -1
- package/esm/Header/HeaderHelp.d.ts.map +1 -1
- package/esm/Header/HeaderHelp.js +1 -1
- package/esm/Header/HeaderHelp.js.map +1 -1
- package/esm/Header/HeaderMenu.d.ts +1 -2
- package/esm/Header/HeaderMenu.d.ts.map +1 -1
- package/esm/Header/HeaderMenu.js +4 -4
- package/esm/Header/HeaderMenu.js.map +1 -1
- package/esm/Header/HeaderWorkspacePicker.d.ts +0 -1
- package/esm/Header/HeaderWorkspacePicker.d.ts.map +1 -1
- package/esm/Header/HeaderWorkspacePicker.js +1 -1
- package/esm/Header/HeaderWorkspacePicker.js.map +1 -1
- package/esm/Header/HeaderWorkspacePickerItem.d.ts +0 -1
- package/esm/Header/HeaderWorkspacePickerItem.d.ts.map +1 -1
- package/esm/Header/HeaderWorkspacePickerItem.js +1 -1
- package/esm/Header/HeaderWorkspacePickerItem.js.map +1 -1
- package/esm/List/InsightListItem.d.ts +1 -4
- package/esm/List/InsightListItem.d.ts.map +1 -1
- package/esm/List/InsightListItem.js +3 -6
- package/esm/List/InsightListItem.js.map +1 -1
- package/esm/List/LegacyInvertableList.d.ts +0 -1
- package/esm/List/LegacyInvertableList.d.ts.map +1 -1
- package/esm/List/LegacyInvertableList.js +3 -4
- package/esm/List/LegacyInvertableList.js.map +1 -1
- package/esm/List/LegacyMultiSelectList.d.ts +1 -2
- package/esm/List/LegacyMultiSelectList.d.ts.map +1 -1
- package/esm/List/LegacyMultiSelectList.js +7 -12
- package/esm/List/LegacyMultiSelectList.js.map +1 -1
- package/esm/List/LegacyMultiSelectListItem.d.ts +0 -6
- package/esm/List/LegacyMultiSelectListItem.d.ts.map +1 -1
- package/esm/List/LegacyMultiSelectListItem.js +1 -2
- package/esm/List/LegacyMultiSelectListItem.js.map +1 -1
- package/esm/List/MultiSelectList.d.ts +1 -5
- package/esm/List/MultiSelectList.d.ts.map +1 -1
- package/esm/List/MultiSelectList.js +6 -6
- package/esm/List/MultiSelectList.js.map +1 -1
- package/esm/List/index.d.ts +2 -2
- package/esm/List/index.d.ts.map +1 -1
- package/esm/List/index.js +2 -2
- package/esm/List/index.js.map +1 -1
- package/esm/Overlay/ErrorOverlay.d.ts.map +1 -1
- package/esm/Overlay/ErrorOverlay.js +4 -4
- package/esm/Overlay/ErrorOverlay.js.map +1 -1
- package/esm/SettingWidget/StylingSettingWidget/StylingSettingWidget.d.ts +2 -2
- package/esm/SettingWidget/StylingSettingWidget/StylingSettingWidget.d.ts.map +1 -1
- package/esm/SettingWidget/StylingSettingWidget/StylingSettingWidget.js +2 -6
- package/esm/SettingWidget/StylingSettingWidget/StylingSettingWidget.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/measureNumberFormat/MeasureNumberFormat.d.ts +1 -2
- package/esm/measureNumberFormat/MeasureNumberFormat.d.ts.map +1 -1
- package/esm/measureNumberFormat/MeasureNumberFormat.js +6 -6
- package/esm/measureNumberFormat/MeasureNumberFormat.js.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/CustomFormatDialog.js +4 -4
- package/esm/measureNumberFormat/customFormatDialog/CustomFormatDialog.js.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/DocumentationLink.d.ts +3 -7
- package/esm/measureNumberFormat/customFormatDialog/DocumentationLink.d.ts.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/DocumentationLink.js +2 -3
- package/esm/measureNumberFormat/customFormatDialog/DocumentationLink.js.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/FormatInput.d.ts +3 -7
- package/esm/measureNumberFormat/customFormatDialog/FormatInput.d.ts.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/FormatInput.js +4 -5
- package/esm/measureNumberFormat/customFormatDialog/FormatInput.js.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/formatTemplatesDropdown/DropdownItem.d.ts +2 -2
- package/esm/measureNumberFormat/customFormatDialog/formatTemplatesDropdown/DropdownItem.d.ts.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/formatTemplatesDropdown/DropdownItem.js +2 -3
- package/esm/measureNumberFormat/customFormatDialog/formatTemplatesDropdown/DropdownItem.js.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/formatTemplatesDropdown/DropdownToggleButton.d.ts +2 -2
- package/esm/measureNumberFormat/customFormatDialog/formatTemplatesDropdown/DropdownToggleButton.d.ts.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/formatTemplatesDropdown/DropdownToggleButton.js +1 -2
- package/esm/measureNumberFormat/customFormatDialog/formatTemplatesDropdown/DropdownToggleButton.js.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/formatTemplatesDropdown/FormatTemplatesDropdown.js +2 -2
- package/esm/measureNumberFormat/customFormatDialog/formatTemplatesDropdown/FormatTemplatesDropdown.js.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/previewSection/ExtendedPreview.js +1 -1
- package/esm/measureNumberFormat/customFormatDialog/previewSection/ExtendedPreview.js.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/previewSection/Preview.d.ts +2 -7
- package/esm/measureNumberFormat/customFormatDialog/previewSection/Preview.d.ts.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/previewSection/Preview.js +3 -3
- package/esm/measureNumberFormat/customFormatDialog/previewSection/Preview.js.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/shared/PreviewRows.d.ts +1 -2
- package/esm/measureNumberFormat/customFormatDialog/shared/PreviewRows.d.ts.map +1 -1
- package/esm/measureNumberFormat/customFormatDialog/shared/PreviewRows.js +1 -2
- package/esm/measureNumberFormat/customFormatDialog/shared/PreviewRows.js.map +1 -1
- package/esm/measureNumberFormat/hooks/useCurrencyFormatDefaults.d.ts +21 -0
- package/esm/measureNumberFormat/hooks/useCurrencyFormatDefaults.d.ts.map +1 -0
- package/esm/measureNumberFormat/hooks/useCurrencyFormatDefaults.js +49 -0
- package/esm/measureNumberFormat/hooks/useCurrencyFormatDefaults.js.map +1 -0
- package/esm/measureNumberFormat/hooks/useMetricTypePresets.d.ts +115 -0
- package/esm/measureNumberFormat/hooks/useMetricTypePresets.d.ts.map +1 -0
- package/esm/measureNumberFormat/hooks/useMetricTypePresets.js +113 -0
- package/esm/measureNumberFormat/hooks/useMetricTypePresets.js.map +1 -0
- package/esm/measureNumberFormat/index.d.ts +7 -0
- package/esm/measureNumberFormat/index.d.ts.map +1 -1
- package/esm/measureNumberFormat/index.js +7 -1
- package/esm/measureNumberFormat/index.js.map +1 -1
- package/esm/measureNumberFormat/presets/currencyPresets.d.ts +34 -0
- package/esm/measureNumberFormat/presets/currencyPresets.d.ts.map +1 -0
- package/esm/measureNumberFormat/presets/currencyPresets.js +53 -0
- package/esm/measureNumberFormat/presets/currencyPresets.js.map +1 -0
- package/esm/measureNumberFormat/presets/standardPresets.d.ts +34 -0
- package/esm/measureNumberFormat/presets/standardPresets.d.ts.map +1 -0
- package/esm/measureNumberFormat/presets/standardPresets.js +71 -0
- package/esm/measureNumberFormat/presets/standardPresets.js.map +1 -0
- package/esm/measureNumberFormat/presets/templates.d.ts +60 -0
- package/esm/measureNumberFormat/presets/templates.d.ts.map +1 -0
- package/esm/measureNumberFormat/presets/templates.js +183 -0
- package/esm/measureNumberFormat/presets/templates.js.map +1 -0
- package/esm/measureNumberFormat/validation/currencyFormatValidator.d.ts +55 -0
- package/esm/measureNumberFormat/validation/currencyFormatValidator.d.ts.map +1 -0
- package/esm/measureNumberFormat/validation/currencyFormatValidator.js +118 -0
- package/esm/measureNumberFormat/validation/currencyFormatValidator.js.map +1 -0
- package/esm/sdk-ui-kit.d.ts +437 -59
- package/package.json +9 -9
- package/src/@ui/UiPaginationButton/UiPaginationButton.scss +56 -0
- package/src/@ui/index.scss +1 -0
- package/styles/css/main.css +40 -0
- package/styles/css/main.css.map +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// (C) 2025 GoodData Corporation
|
|
2
|
+
/**
|
|
3
|
+
* Standard numeric preset definitions.
|
|
4
|
+
* These are the raw preset data that can be used to create localized presets.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export const STANDARD_PRESET_DEFINITIONS = [
|
|
8
|
+
{
|
|
9
|
+
localIdentifier: "rounded",
|
|
10
|
+
format: "#,##0",
|
|
11
|
+
previewNumber: 1000.12,
|
|
12
|
+
messageId: "metricComponent.numberFormat.preset.rounded",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
localIdentifier: "decimal-1",
|
|
16
|
+
format: "#,##0.0",
|
|
17
|
+
previewNumber: 1000.12,
|
|
18
|
+
messageId: "metricComponent.numberFormat.preset.decimal1",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
localIdentifier: "decimal-2",
|
|
22
|
+
format: "#,##0.00",
|
|
23
|
+
previewNumber: 1000.12,
|
|
24
|
+
messageId: "metricComponent.numberFormat.preset.decimal2",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
localIdentifier: "percent-rounded",
|
|
28
|
+
format: "#,##0%",
|
|
29
|
+
previewNumber: 0.1,
|
|
30
|
+
messageId: "metricComponent.numberFormat.preset.percentRounded",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
localIdentifier: "percent-1",
|
|
34
|
+
format: "#,##0.0%",
|
|
35
|
+
previewNumber: 0.101,
|
|
36
|
+
messageId: "metricComponent.numberFormat.preset.percent1",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
localIdentifier: "percent-2",
|
|
40
|
+
format: "#,##0.00%",
|
|
41
|
+
previewNumber: 0.1012,
|
|
42
|
+
messageId: "metricComponent.numberFormat.preset.percent2",
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
/**
|
|
46
|
+
* Default message ID prefix for standard preset definitions.
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export const DEFAULT_STANDARD_PRESET_PREFIX = "metricComponent.numberFormat.preset";
|
|
50
|
+
/**
|
|
51
|
+
* Creates localized standard format presets.
|
|
52
|
+
*
|
|
53
|
+
* @param formatMessage - Function to format localized messages (e.g., from react-intl)
|
|
54
|
+
* @param messageIdPrefix - Optional prefix for message IDs (default: "metricComponent.numberFormat.preset")
|
|
55
|
+
* @returns Array of standard format presets with localized names
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export function createStandardPresets(formatMessage, messageIdPrefix = DEFAULT_STANDARD_PRESET_PREFIX) {
|
|
59
|
+
return STANDARD_PRESET_DEFINITIONS.map((definition) => {
|
|
60
|
+
// Extract the key part from the default message ID (e.g., "rounded" from "metricComponent.numberFormat.preset.rounded")
|
|
61
|
+
const keyPart = definition.messageId.replace(`${DEFAULT_STANDARD_PRESET_PREFIX}.`, "");
|
|
62
|
+
const messageId = `${messageIdPrefix}.${keyPart}`;
|
|
63
|
+
return {
|
|
64
|
+
name: formatMessage({ id: messageId }),
|
|
65
|
+
localIdentifier: definition.localIdentifier,
|
|
66
|
+
format: definition.format,
|
|
67
|
+
previewNumber: definition.previewNumber,
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=standardPresets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standardPresets.js","sourceRoot":"","sources":["../../../src/measureNumberFormat/presets/standardPresets.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAehC;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BA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zB,aAAa,EAAE,UAAU,CAAC,aAAa;SAC1C,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type IFormatTemplate } from "../typings.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base template definition without localized name.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export interface ITemplateDefinition {
|
|
7
|
+
localIdentifier: string;
|
|
8
|
+
format: string;
|
|
9
|
+
messageId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Standard format template definitions (basic numeric formats).
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare const STANDARD_TEMPLATE_DEFINITIONS: readonly ITemplateDefinition[];
|
|
16
|
+
/**
|
|
17
|
+
* Currency format template definitions.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare const CURRENCY_TEMPLATE_DEFINITIONS: readonly ITemplateDefinition[];
|
|
21
|
+
/**
|
|
22
|
+
* Advanced format template definitions (complex conditional formats).
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare const ADVANCED_TEMPLATE_DEFINITIONS: readonly ITemplateDefinition[];
|
|
26
|
+
/**
|
|
27
|
+
* Local identifiers of templates that are currency-specific.
|
|
28
|
+
* Used to filter templates when metric type is CURRENCY.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export declare const CURRENCY_TEMPLATE_IDS: string[];
|
|
32
|
+
/**
|
|
33
|
+
* Default message ID prefix for template definitions.
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export declare const DEFAULT_TEMPLATE_PREFIX = "metricComponent.numberFormat.template";
|
|
37
|
+
/**
|
|
38
|
+
* Creates localized format templates.
|
|
39
|
+
*
|
|
40
|
+
* @param formatMessage - Function to format localized messages (e.g., from react-intl)
|
|
41
|
+
* @param definitions - Template definitions to localize
|
|
42
|
+
* @param messageIdPrefix - Optional prefix for message IDs (default: "metricComponent.numberFormat.template")
|
|
43
|
+
* @returns Array of format templates with localized names
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export declare function createTemplates(formatMessage: (descriptor: {
|
|
47
|
+
id: string;
|
|
48
|
+
}) => string, definitions: readonly ITemplateDefinition[], messageIdPrefix?: string): IFormatTemplate[];
|
|
49
|
+
/**
|
|
50
|
+
* Creates all localized format templates (standard + currency + advanced).
|
|
51
|
+
*
|
|
52
|
+
* @param formatMessage - Function to format localized messages (e.g., from react-intl)
|
|
53
|
+
* @param messageIdPrefix - Optional prefix for message IDs (default: "metricComponent.numberFormat.template")
|
|
54
|
+
* @returns Array of all format templates with localized names
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export declare function createAllTemplates(formatMessage: (descriptor: {
|
|
58
|
+
id: string;
|
|
59
|
+
}) => string, messageIdPrefix?: string): IFormatTemplate[];
|
|
60
|
+
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/measureNumberFormat/presets/templates.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,eAAO,MAAM,6BAA6B,EAAE,SAAS,mBAAmB,EA+B9D,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,6BAA6B,EAAE,SAAS,mBAAmB,EAqB9D,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,6BAA6B,EAAE,SAAS,mBAAmB,EAuE9D,CAAC;AAEX;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,UAA8D,CAAC;AAEjG;;;GAGG;AACH,eAAO,MAAM,uBAAuB,0CAA0C,CAAC;AAE/E;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC3B,aAAa,EAAE,CAAC,UAAU,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,KAAK,MAAM,EACrD,WAAW,EAAE,SAAS,mBAAmB,EAAE,EAC3C,eAAe,GAAE,MAAgC,GAClD,eAAe,EAAE,CAWnB;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAC9B,aAAa,EAAE,CAAC,UAAU,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,KAAK,MAAM,EACrD,eAAe,GAAE,MAAgC,GAClD,eAAe,EAAE,CAMnB"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// (C) 2025 GoodData Corporation
|
|
2
|
+
/**
|
|
3
|
+
* Standard format template definitions (basic numeric formats).
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export const STANDARD_TEMPLATE_DEFINITIONS = [
|
|
7
|
+
{
|
|
8
|
+
localIdentifier: "rounded",
|
|
9
|
+
format: "#,##0",
|
|
10
|
+
messageId: "metricComponent.numberFormat.template.rounded",
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
localIdentifier: "decimal-1",
|
|
14
|
+
format: "#,##0.0",
|
|
15
|
+
messageId: "metricComponent.numberFormat.template.decimal1",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
localIdentifier: "decimal-2",
|
|
19
|
+
format: "#,##0.00",
|
|
20
|
+
messageId: "metricComponent.numberFormat.template.decimal2",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
localIdentifier: "percent-rounded",
|
|
24
|
+
format: "#,##0%",
|
|
25
|
+
messageId: "metricComponent.numberFormat.template.percentRounded",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
localIdentifier: "percent-1",
|
|
29
|
+
format: "#,##0.0%",
|
|
30
|
+
messageId: "metricComponent.numberFormat.template.percent1",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
localIdentifier: "percent-2",
|
|
34
|
+
format: "#,##0.00%",
|
|
35
|
+
messageId: "metricComponent.numberFormat.template.percent2",
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
/**
|
|
39
|
+
* Currency format template definitions.
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
export const CURRENCY_TEMPLATE_DEFINITIONS = [
|
|
43
|
+
{
|
|
44
|
+
localIdentifier: "currency",
|
|
45
|
+
format: "$#,##0.00",
|
|
46
|
+
messageId: "metricComponent.numberFormat.template.currency",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
localIdentifier: "currency-shortened",
|
|
50
|
+
format: "[>=1000000000000]$#,,,,.0 T;\n" +
|
|
51
|
+
"[>=1000000000]$#,,,.0 B;\n" +
|
|
52
|
+
"[>=1000000]$#,,.0 M;\n" +
|
|
53
|
+
"[>=1000]$#,.0 K;\n" +
|
|
54
|
+
"[>=0]$#,##0;\n" +
|
|
55
|
+
"[<=-1000000000000]-$#,,,,.0 T;\n" +
|
|
56
|
+
"[<=-1000000000]-$#,,,.0 B;\n" +
|
|
57
|
+
"[<=-1000000]-$#,,.0 M;\n" +
|
|
58
|
+
"[<=-1000]-$#,.0 K;\n" +
|
|
59
|
+
"[<0]-$#,##0",
|
|
60
|
+
messageId: "metricComponent.numberFormat.template.currencyShortened",
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
/**
|
|
64
|
+
* Advanced format template definitions (complex conditional formats).
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export const ADVANCED_TEMPLATE_DEFINITIONS = [
|
|
68
|
+
{
|
|
69
|
+
localIdentifier: "large-numbers-shortened",
|
|
70
|
+
format: "[>=1000000000000]#,,,,.0 T;\n" +
|
|
71
|
+
"[>=1000000000]#,,,.0 B;\n" +
|
|
72
|
+
"[>=1000000]#,,.0 M;\n" +
|
|
73
|
+
"[>=1000]#,.0 K;\n" +
|
|
74
|
+
"[>=0]#,##0;\n" +
|
|
75
|
+
"[<=-1000000000000]-#,,,,.0 T;\n" +
|
|
76
|
+
"[<=-1000000000]-#,,,.0 B;\n" +
|
|
77
|
+
"[<=-1000000]-#,,.0 M;\n" +
|
|
78
|
+
"[<=-1000]-#,.0 K;\n" +
|
|
79
|
+
"[<0]-#,##0",
|
|
80
|
+
messageId: "metricComponent.numberFormat.template.largeNumbersShortened",
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
localIdentifier: "large-numbers-shortened-with-colors",
|
|
84
|
+
format: "[>=1000000000000][green]#,,,,.0 T;\n" +
|
|
85
|
+
"[>=1000000000][green]#,,,.0 B;\n" +
|
|
86
|
+
"[>=1000000][green]#,,.0 M;\n" +
|
|
87
|
+
"[>=1000][black]#,.0 K;\n" +
|
|
88
|
+
"[>=0][black]#,##0;\n" +
|
|
89
|
+
"[<=-1000000000000][red]-#,,,,.0 T;\n" +
|
|
90
|
+
"[<=-1000000000][red]-#,,,.0 B;\n" +
|
|
91
|
+
"[<=-1000000][red]-#,,.0 M;\n" +
|
|
92
|
+
"[<=-1000][red]-#,.0 K;\n" +
|
|
93
|
+
"[<0][black]-#,##0",
|
|
94
|
+
messageId: "metricComponent.numberFormat.template.largeNumbersShortenedWithColors",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
localIdentifier: "negative-numbers-red",
|
|
98
|
+
format: "[<0][red]-#,##0.0;\n[black]#,##0.0",
|
|
99
|
+
messageId: "metricComponent.numberFormat.template.negativeNumbersRed",
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
localIdentifier: "financial",
|
|
103
|
+
format: "[<0](#,##0.0);\n#,##0.0",
|
|
104
|
+
messageId: "metricComponent.numberFormat.template.financial",
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
localIdentifier: "decimal-without-thousands-separator",
|
|
108
|
+
format: "0.00",
|
|
109
|
+
messageId: "metricComponent.numberFormat.template.decimalWithoutThousandsSeparator",
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
localIdentifier: "conditional-colors",
|
|
113
|
+
format: "[<0][red]#,#.##;\n[<1000][black]#,0.##;\n[>=1000][green]#,#.##",
|
|
114
|
+
messageId: "metricComponent.numberFormat.template.conditionalColors",
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
localIdentifier: "trend-symbols",
|
|
118
|
+
format: "[<0][green]▲ #,##0.0%;\n[=0][black]#,##0.0%;\n[>0][red]▼ #,##0.0%",
|
|
119
|
+
messageId: "metricComponent.numberFormat.template.trendSymbols",
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
localIdentifier: "time-from-seconds",
|
|
123
|
+
format: "[>=86400]{{{86400||0d}}} {{{3600|24|00}}}h;\n" +
|
|
124
|
+
"[>=3600]{{{3600|24|00}}}h {{{60|60|00}}}m;\n" +
|
|
125
|
+
"[>=60]{{{60|60|00}}}m {{{|60.|00}}}s;\n" +
|
|
126
|
+
"[>0]{{{|60.|00.0}}}s;\n" +
|
|
127
|
+
"[=0]{{{|60.|0}}}",
|
|
128
|
+
messageId: "metricComponent.numberFormat.template.timeFromSeconds",
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
localIdentifier: "zero-instead-of-null",
|
|
132
|
+
format: "[=null]0.00;\n[>=0]#,#0.00;\n[<0]-#,#0.00",
|
|
133
|
+
messageId: "metricComponent.numberFormat.template.zeroInsteadOfNull",
|
|
134
|
+
},
|
|
135
|
+
];
|
|
136
|
+
/**
|
|
137
|
+
* Local identifiers of templates that are currency-specific.
|
|
138
|
+
* Used to filter templates when metric type is CURRENCY.
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
export const CURRENCY_TEMPLATE_IDS = CURRENCY_TEMPLATE_DEFINITIONS.map((t) => t.localIdentifier);
|
|
142
|
+
/**
|
|
143
|
+
* Default message ID prefix for template definitions.
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
export const DEFAULT_TEMPLATE_PREFIX = "metricComponent.numberFormat.template";
|
|
147
|
+
/**
|
|
148
|
+
* Creates localized format templates.
|
|
149
|
+
*
|
|
150
|
+
* @param formatMessage - Function to format localized messages (e.g., from react-intl)
|
|
151
|
+
* @param definitions - Template definitions to localize
|
|
152
|
+
* @param messageIdPrefix - Optional prefix for message IDs (default: "metricComponent.numberFormat.template")
|
|
153
|
+
* @returns Array of format templates with localized names
|
|
154
|
+
* @internal
|
|
155
|
+
*/
|
|
156
|
+
export function createTemplates(formatMessage, definitions, messageIdPrefix = DEFAULT_TEMPLATE_PREFIX) {
|
|
157
|
+
return definitions.map((definition) => {
|
|
158
|
+
// Extract the key part from the default message ID (e.g., "rounded" from "metricComponent.numberFormat.template.rounded")
|
|
159
|
+
const keyPart = definition.messageId.replace(`${DEFAULT_TEMPLATE_PREFIX}.`, "");
|
|
160
|
+
const messageId = `${messageIdPrefix}.${keyPart}`;
|
|
161
|
+
return {
|
|
162
|
+
name: formatMessage({ id: messageId }),
|
|
163
|
+
localIdentifier: definition.localIdentifier,
|
|
164
|
+
format: definition.format,
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Creates all localized format templates (standard + currency + advanced).
|
|
170
|
+
*
|
|
171
|
+
* @param formatMessage - Function to format localized messages (e.g., from react-intl)
|
|
172
|
+
* @param messageIdPrefix - Optional prefix for message IDs (default: "metricComponent.numberFormat.template")
|
|
173
|
+
* @returns Array of all format templates with localized names
|
|
174
|
+
* @internal
|
|
175
|
+
*/
|
|
176
|
+
export function createAllTemplates(formatMessage, messageIdPrefix = DEFAULT_TEMPLATE_PREFIX) {
|
|
177
|
+
return [
|
|
178
|
+
...createTemplates(formatMessage, STANDARD_TEMPLATE_DEFINITIONS, messageIdPrefix),
|
|
179
|
+
...createTemplates(formatMessage, CURRENCY_TEMPLATE_DEFINITIONS, messageIdPrefix),
|
|
180
|
+
...createTemplates(formatMessage, ADVANCED_TEMPLATE_DEFINITIONS, messageIdPrefix),
|
|
181
|
+
];
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/measureNumberFormat/presets/templates.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAchC;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAmC;IACzE;QACI,eAAe,EAAE,SAAS;QAC1B,MAAM,EAAE,OAAO;QACf,SAAS,EAAE,+CAA+C;KAC7D;IACD;QACI,eAAe,EAAE,WAAW;QAC5B,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,gDAAgD;KAC9D;IACD;QACI,eAAe,EAAE,WAAW;QAC5B,MAAM,EAAE,UAAU;QAClB,SAAS,EAAE,gDAAgD;KAC9D;IACD;QACI,eAAe,EAAE,iBAAiB;QAClC,MAAM,EAAE,QAAQ;QAChB,SAAS,EAAE,sDAAsD;KACpE;IACD;QACI,eAAe,EAAE,WAAW;QAC5B,MAAM,EAAE,UAAU;QAClB,SAAS,EAAE,gDAAgD;KAC9D;IACD;QACI,eAAe,EAAE,WAAW;QAC5B,MAAM,EAAE,WAAW;QACnB,SAAS,EAAE,gDAAgD;KAC9D;CACK,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAmC;IACzE;QACI,eAAe,EAAE,UAAU;QAC3B,MAAM,EAAE,WAAW;QACnB,SAAS,EAAE,gDAAgD;KAC9D;IACD;QACI,eAAe,EAAE,oBAAoB;QACrC,MAAM,EACF,gCAAgC;YAChC,4BAA4B;YAC5B,wBAAwB;YACxB,oBAAoB;YACpB,gBAAgB;YAChB,kCAAkC;YAClC,8BAA8B;YAC9B,0BAA0B;YAC1B,sBAAsB;YACtB,aAAa;QACjB,SAAS,EAAE,yDAAyD;KACvE;CACK,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAmC;IACzE;QACI,eAAe,EAAE,yBAAyB;Q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CAAC;AAEjG;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,uCAAuC,CAAC;AAE/E;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC3B,aAAqD,EACrD,WAA2C,EAC3C,kBAA0B,uBAAuB;IAEjD,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QAClC,0HAA0H;QAC1H,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,uBAAuB,GAAG,EAAE,EAAE,CAAC,CAAC;QAChF,MAAM,SAAS,GAAG,GAAG,eAAe,IAAI,OAAO,EAAE,CAAC;QAClD,OAAO;YACH,IAAI,EAAE,aAAa,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC;YACtC,eAAe,EAAE,UAAU,CAAC,eAAe;YAC3C,MAAM,EAAE,UAAU,CAAC,MAAM;SAC5B,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAC9B,aAAqD,EACrD,kBAA0B,uBAAuB;IAEjD,OAAO;QACH,GAAG,eAAe,CAAC,aAAa,EAAE,6BAA6B,EAAE,eAAe,CAAC;QACjF,GAAG,eAAe,CAAC,aAAa,EAAE,6BAA6B,EAAE,eAAe,CAAC;QACjF,GAAG,eAAe,CAAC,aAAa,EAAE,6BAA6B,EAAE,eAAe,CAAC;KACpF,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type ISeparators } from "@gooddata/number-formatter";
|
|
2
|
+
/**
|
|
3
|
+
* @alpha
|
|
4
|
+
*/
|
|
5
|
+
export type CurrencyFormatValidationErrorCode = "empty" | "invalidFormat" | "missingCurrencySymbol" | "missingDecimalPlaces";
|
|
6
|
+
/**
|
|
7
|
+
* @alpha
|
|
8
|
+
*/
|
|
9
|
+
export interface ICurrencyFormatValidationError {
|
|
10
|
+
code: CurrencyFormatValidationErrorCode;
|
|
11
|
+
/**
|
|
12
|
+
* Indexes of sections (0-based) that failed validation.
|
|
13
|
+
* The value is only present for section-driven validations.
|
|
14
|
+
*/
|
|
15
|
+
sectionIndexes?: number[];
|
|
16
|
+
message: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @alpha
|
|
20
|
+
*/
|
|
21
|
+
export interface ICurrencyFormatValidationResult {
|
|
22
|
+
isValid: boolean;
|
|
23
|
+
errors: ICurrencyFormatValidationError[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @alpha
|
|
27
|
+
*/
|
|
28
|
+
export interface ICurrencyFormatValidationOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Sample value used to verify the formatter does not throw.
|
|
31
|
+
* Defaults to 12345.67 to cover both thousands and decimals.
|
|
32
|
+
*/
|
|
33
|
+
sampleValue?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Number of mandatory decimal places each section must contain.
|
|
36
|
+
* Set to 0 (or a negative value) to skip the decimal check.
|
|
37
|
+
* Defaults to 2.
|
|
38
|
+
*/
|
|
39
|
+
requiredDecimalPlaces?: number;
|
|
40
|
+
separators?: ISeparators;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validates a number format string that is expected to represent a currency amount.
|
|
44
|
+
*
|
|
45
|
+
* @alpha
|
|
46
|
+
*/
|
|
47
|
+
export declare function validateCurrencyFormat(format: string | undefined | null, options?: ICurrencyFormatValidationOptions): ICurrencyFormatValidationResult;
|
|
48
|
+
/**
|
|
49
|
+
* Checks if a format string represents a currency format.
|
|
50
|
+
* A currency format is one where at least one numeric section contains a currency symbol.
|
|
51
|
+
*
|
|
52
|
+
* @alpha
|
|
53
|
+
*/
|
|
54
|
+
export declare function isCurrencyFormat(format: string | undefined | null): boolean;
|
|
55
|
+
//# sourceMappingURL=currencyFormatValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currencyFormatValidator.d.ts","sourceRoot":"","sources":["../../../src/measureNumberFormat/validation/currencyFormatValidator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAyB,KAAK,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAWrF;;GAEG;AACH,MAAM,MAAM,iCAAiC,GACvC,OAAO,GACP,eAAe,GACf,uBAAuB,GACvB,sBAAsB,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC3C,IAAI,EAAE,iCAAiC,CAAC;IACxC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC5C,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,8BAA8B,EAAE,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC7C;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,UAAU,CAAC,EAAE,WAAW,CAAC;CAC5B;AASD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAClC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EACjC,OAAO,GAAE,gCAAqC,GAC/C,+BAA+B,CAsDjC;AAgED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAc3E"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// (C) 2025 GoodData Corporation
|
|
2
|
+
import { ClientFormatterFacade } from "@gooddata/number-formatter";
|
|
3
|
+
const DEFAULT_SAMPLE_VALUE = 12345.67;
|
|
4
|
+
const DEFAULT_REQUIRED_DECIMALS = 2;
|
|
5
|
+
const SECTION_SEPARATOR = ";";
|
|
6
|
+
const NUMBER_PLACEHOLDER_PATTERN = /[0#?]/;
|
|
7
|
+
const DECIMAL_TOKEN_PATTERN = /\.(0+)/;
|
|
8
|
+
const CURRENCY_SYMBOL_PATTERN = /\p{Sc}/u;
|
|
9
|
+
const CURRENCY_BRACKET_PATTERN = /\[\$[^\]]+\]/;
|
|
10
|
+
const QUOTED_CURRENCY_PATTERN = /(["'])[ \t]*[A-Za-z]{2,6}[ \t]*\1/;
|
|
11
|
+
const DEFAULT_ERROR_MESSAGES = {
|
|
12
|
+
empty: "Format is required.",
|
|
13
|
+
invalidFormat: "Format contains invalid tokens.",
|
|
14
|
+
missingCurrencySymbol: "Currency symbol is missing.",
|
|
15
|
+
missingDecimalPlaces: "Format must include the required decimal places.",
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Validates a number format string that is expected to represent a currency amount.
|
|
19
|
+
*
|
|
20
|
+
* @alpha
|
|
21
|
+
*/
|
|
22
|
+
export function validateCurrencyFormat(format, options = {}) {
|
|
23
|
+
const sanitizedFormat = format?.trim() ?? "";
|
|
24
|
+
const errors = [];
|
|
25
|
+
if (!sanitizedFormat) {
|
|
26
|
+
errors.push(buildError("empty"));
|
|
27
|
+
return { isValid: false, errors };
|
|
28
|
+
}
|
|
29
|
+
const sampleValue = options.sampleValue ?? DEFAULT_SAMPLE_VALUE;
|
|
30
|
+
const separators = options.separators;
|
|
31
|
+
if (!isParsableFormat(sanitizedFormat, sampleValue, separators)) {
|
|
32
|
+
errors.push(buildError("invalidFormat"));
|
|
33
|
+
return { isValid: false, errors };
|
|
34
|
+
}
|
|
35
|
+
const sections = getFormatSections(sanitizedFormat);
|
|
36
|
+
const sectionsWithNumbers = sections.filter(hasNumericPlaceholder);
|
|
37
|
+
if (sectionsWithNumbers.length === 0) {
|
|
38
|
+
errors.push(buildError("invalidFormat"));
|
|
39
|
+
return { isValid: false, errors };
|
|
40
|
+
}
|
|
41
|
+
if (!sectionsWithNumbers.every(hasCurrencyToken)) {
|
|
42
|
+
errors.push(buildError("missingCurrencySymbol", collectInvalidSections(sectionsWithNumbers, hasCurrencyToken)));
|
|
43
|
+
}
|
|
44
|
+
const requiredDecimals = options.requiredDecimalPlaces ?? DEFAULT_REQUIRED_DECIMALS;
|
|
45
|
+
if (requiredDecimals > 0 &&
|
|
46
|
+
!sectionsWithNumbers.every((section) => hasRequiredDecimals(section, requiredDecimals))) {
|
|
47
|
+
errors.push(buildError("missingDecimalPlaces", collectInvalidSections(sectionsWithNumbers, (section) => hasRequiredDecimals(section, requiredDecimals))));
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
isValid: errors.length === 0,
|
|
51
|
+
errors,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function buildError(code, sectionIndexes) {
|
|
55
|
+
return {
|
|
56
|
+
code,
|
|
57
|
+
sectionIndexes,
|
|
58
|
+
message: DEFAULT_ERROR_MESSAGES[code],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function getFormatSections(format) {
|
|
62
|
+
return format
|
|
63
|
+
.split(SECTION_SEPARATOR)
|
|
64
|
+
.map((section) => section.trim())
|
|
65
|
+
.filter((section) => section.length > 0);
|
|
66
|
+
}
|
|
67
|
+
function hasNumericPlaceholder(section) {
|
|
68
|
+
return NUMBER_PLACEHOLDER_PATTERN.test(section);
|
|
69
|
+
}
|
|
70
|
+
function hasCurrencyToken(section) {
|
|
71
|
+
return (CURRENCY_BRACKET_PATTERN.test(section) ||
|
|
72
|
+
CURRENCY_SYMBOL_PATTERN.test(section) ||
|
|
73
|
+
QUOTED_CURRENCY_PATTERN.test(section));
|
|
74
|
+
}
|
|
75
|
+
function hasRequiredDecimals(section, requiredDecimalPlaces) {
|
|
76
|
+
const match = section.match(DECIMAL_TOKEN_PATTERN);
|
|
77
|
+
if (!match) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return match[1].length >= requiredDecimalPlaces;
|
|
81
|
+
}
|
|
82
|
+
function collectInvalidSections(sections, predicate) {
|
|
83
|
+
const invalidIndexes = sections.reduce((result, section, index) => {
|
|
84
|
+
if (!predicate(section)) {
|
|
85
|
+
result.push(index);
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}, []);
|
|
89
|
+
return invalidIndexes.length > 0 ? invalidIndexes : undefined;
|
|
90
|
+
}
|
|
91
|
+
function isParsableFormat(format, sampleValue, separators) {
|
|
92
|
+
try {
|
|
93
|
+
ClientFormatterFacade.formatValue(sampleValue, format, separators);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Checks if a format string represents a currency format.
|
|
102
|
+
* A currency format is one where at least one numeric section contains a currency symbol.
|
|
103
|
+
*
|
|
104
|
+
* @alpha
|
|
105
|
+
*/
|
|
106
|
+
export function isCurrencyFormat(format) {
|
|
107
|
+
const sanitizedFormat = format?.trim();
|
|
108
|
+
if (!sanitizedFormat) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
const sections = getFormatSections(sanitizedFormat);
|
|
112
|
+
const sectionsWithNumbers = sections.filter(hasNumericPlaceholder);
|
|
113
|
+
if (sectionsWithNumbers.length === 0) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
return sectionsWithNumbers.some(hasCurrencyToken);
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=currencyFormatValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currencyFormatValidator.js","sourceRoot":"","sources":["../../../src/measureNumberFormat/validation/currencyFormatValidator.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAEhC,OAAO,EAAE,qBAAqB,EAAoB,MAAM,4BAA4B,CAAC;AAErF,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AACtC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AACpC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,0BAA0B,GAAG,OAAO,CAAC;AAC3C,MAAM,qBAAqB,GAAG,QAAQ,CAAC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