@hmcts/opal-frontend-common 0.0.102 → 0.0.104
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.
|
@@ -87,11 +87,11 @@ class MojSortableTableHeaderComponent {
|
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: MojSortableTableHeaderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
90
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.20", type: MojSortableTableHeaderComponent, isStandalone: true, selector: "opal-lib-moj-sortable-table-header, [opal-lib-moj-sortable-table-header]", inputs: { columnKey: "columnKey", sortDirection: "sortDirection", dataIndex: "dataIndex" }, outputs: { sortChange: "sortChange" }, host: { properties: { "attr.aria-sort": "this.ariaSort", "attr.scope": "this.hostScope", "class": "this.hostClass" } }, ngImport: i0, template: "<button type=\"button\" (click)=\"toggleSort()\" [attr.data-index]=\"dataIndex\">\n <ng-content></ng-content>\n <svg\n [opalLibMojSortableTableHeaderSortIcon]=\"sortDirection\"\n width=\"22\"\n height=\"22\"\n focusable=\"false\"\n aria-hidden=\"true\"\n role=\"img\"\n
|
|
90
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.20", type: MojSortableTableHeaderComponent, isStandalone: true, selector: "opal-lib-moj-sortable-table-header, [opal-lib-moj-sortable-table-header]", inputs: { columnKey: "columnKey", sortDirection: "sortDirection", dataIndex: "dataIndex" }, outputs: { sortChange: "sortChange" }, host: { properties: { "attr.aria-sort": "this.ariaSort", "attr.scope": "this.hostScope", "class": "this.hostClass" } }, ngImport: i0, template: "<button type=\"button\" (click)=\"toggleSort()\" [attr.data-index]=\"dataIndex\">\n <ng-content></ng-content>\n <svg\n [opalLibMojSortableTableHeaderSortIcon]=\"sortDirection\"\n width=\"22\"\n height=\"22\"\n focusable=\"false\"\n aria-hidden=\"true\"\n role=\"img\"\n viewBox=\"0 0 22 22\"\n ></svg>\n</button>\n", dependencies: [{ kind: "directive", type: MojSortableTableHeaderSortIconDirective, selector: "[opalLibMojSortableTableHeaderSortIcon]", inputs: ["opalLibMojSortableTableHeaderSortIcon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
91
91
|
}
|
|
92
92
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: MojSortableTableHeaderComponent, decorators: [{
|
|
93
93
|
type: Component,
|
|
94
|
-
args: [{ selector: 'opal-lib-moj-sortable-table-header, [opal-lib-moj-sortable-table-header]', changeDetection: ChangeDetectionStrategy.OnPush, imports: [MojSortableTableHeaderSortIconDirective], template: "<button type=\"button\" (click)=\"toggleSort()\" [attr.data-index]=\"dataIndex\">\n <ng-content></ng-content>\n <svg\n [opalLibMojSortableTableHeaderSortIcon]=\"sortDirection\"\n width=\"22\"\n height=\"22\"\n focusable=\"false\"\n aria-hidden=\"true\"\n role=\"img\"\n
|
|
94
|
+
args: [{ selector: 'opal-lib-moj-sortable-table-header, [opal-lib-moj-sortable-table-header]', changeDetection: ChangeDetectionStrategy.OnPush, imports: [MojSortableTableHeaderSortIconDirective], template: "<button type=\"button\" (click)=\"toggleSort()\" [attr.data-index]=\"dataIndex\">\n <ng-content></ng-content>\n <svg\n [opalLibMojSortableTableHeaderSortIcon]=\"sortDirection\"\n width=\"22\"\n height=\"22\"\n focusable=\"false\"\n aria-hidden=\"true\"\n role=\"img\"\n viewBox=\"0 0 22 22\"\n ></svg>\n</button>\n" }]
|
|
95
95
|
}], propDecorators: { columnKey: [{
|
|
96
96
|
type: Input
|
|
97
97
|
}], sortDirection: [{
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { DOCUMENT, ViewportScroller } from '@angular/common';
|
|
1
|
+
import { DOCUMENT, ViewportScroller, formatCurrency } from '@angular/common';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
3
|
import { inject, Injectable } from '@angular/core';
|
|
4
4
|
|
|
5
|
+
// Matches decimal strings with an optional leading minus and either no commas or correctly grouped thousands.
|
|
6
|
+
// The optional decimal point may have no fractional digits to preserve accepted values such as "1.".
|
|
7
|
+
const DECIMAL_OR_GROUPED_NUMBER_PATTERN = /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d*)?$/;
|
|
5
8
|
class UtilsService {
|
|
6
9
|
document = inject(DOCUMENT);
|
|
7
10
|
viewportScroller = inject(ViewportScroller);
|
|
@@ -22,20 +25,24 @@ class UtilsService {
|
|
|
22
25
|
return str.toUpperCase();
|
|
23
26
|
}
|
|
24
27
|
/**
|
|
25
|
-
* Converts a number to a monetary string
|
|
26
|
-
*
|
|
27
|
-
* @
|
|
28
|
+
* Converts a finite number or decimal string to a GBP monetary string.
|
|
29
|
+
* String values may use a leading minus, correctly positioned thousands separators, and surrounding whitespace.
|
|
30
|
+
* @param amount - The numeric value to convert.
|
|
31
|
+
* @returns The formatted monetary value, or an empty string when the input is invalid.
|
|
28
32
|
*/
|
|
29
33
|
convertToMonetaryString(amount) {
|
|
30
|
-
let negativeValue = false;
|
|
31
34
|
if (typeof amount === 'string') {
|
|
32
|
-
|
|
35
|
+
const trimmedAmount = amount.trim();
|
|
36
|
+
if (!DECIMAL_OR_GROUPED_NUMBER_PATTERN.test(trimmedAmount)) {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
amount = Number(trimmedAmount.replaceAll(',', ''));
|
|
33
40
|
}
|
|
34
|
-
if (amount
|
|
35
|
-
|
|
36
|
-
amount = Math.abs(amount);
|
|
41
|
+
if (!Number.isFinite(amount)) {
|
|
42
|
+
return '';
|
|
37
43
|
}
|
|
38
|
-
|
|
44
|
+
const normalizedAmount = amount === 0 ? 0 : amount;
|
|
45
|
+
return formatCurrency(normalizedAmount, 'en-GB', '£', 'GBP', '1.2-2');
|
|
39
46
|
}
|
|
40
47
|
/**
|
|
41
48
|
* Formats a 6-digit number or string as a sort code.
|
package/package.json
CHANGED
|
@@ -16,9 +16,10 @@ declare class UtilsService {
|
|
|
16
16
|
*/
|
|
17
17
|
upperCaseAllLetters(str: string): string;
|
|
18
18
|
/**
|
|
19
|
-
* Converts a number to a monetary string
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
19
|
+
* Converts a finite number or decimal string to a GBP monetary string.
|
|
20
|
+
* String values may use a leading minus, correctly positioned thousands separators, and surrounding whitespace.
|
|
21
|
+
* @param amount - The numeric value to convert.
|
|
22
|
+
* @returns The formatted monetary value, or an empty string when the input is invalid.
|
|
22
23
|
*/
|
|
23
24
|
convertToMonetaryString(amount: number | string): string;
|
|
24
25
|
/**
|