@hmcts/opal-frontend-common 0.0.70 → 0.0.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Returns a validator function that rejects negative numeric values.
3
+ * Empty and non-numeric values are treated as valid.
4
+ *
5
+ * @returns A ValidatorFn that returns `{ negativeValue: true }` when the parsed value is negative, otherwise null.
6
+ */
7
+ function nonNegativeValueValidator() {
8
+ return (control) => {
9
+ if (control.value === null || control.value === undefined || control.value === '') {
10
+ return null;
11
+ }
12
+ const value = typeof control.value === 'string' ? control.value.trim() : control.value;
13
+ if (value === '') {
14
+ return null;
15
+ }
16
+ const numericValue = Number(value);
17
+ if (Number.isNaN(numericValue)) {
18
+ return null;
19
+ }
20
+ return numericValue < 0 ? { negativeValue: true } : null;
21
+ };
22
+ }
23
+
24
+ /**
25
+ * Generated bundle index. Do not edit.
26
+ */
27
+
28
+ export { nonNegativeValueValidator };
29
+ //# sourceMappingURL=hmcts-opal-frontend-common-validators-non-negative-value.mjs.map
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Returns a validator function that rejects numeric zero values.
3
+ * Empty and non-numeric values are treated as valid.
4
+ *
5
+ * @returns A ValidatorFn that returns `{ zeroValue: true }` when the parsed value is zero, otherwise null.
6
+ */
7
+ function nonZeroValueValidator() {
8
+ return (control) => {
9
+ if (control.value === null || control.value === undefined || control.value === '') {
10
+ return null;
11
+ }
12
+ const value = typeof control.value === 'string' ? control.value.trim() : control.value;
13
+ if (value === '') {
14
+ return null;
15
+ }
16
+ const numericValue = Number(value);
17
+ if (Number.isNaN(numericValue)) {
18
+ return null;
19
+ }
20
+ return numericValue === 0 ? { zeroValue: true } : null;
21
+ };
22
+ }
23
+
24
+ /**
25
+ * Generated bundle index. Do not edit.
26
+ */
27
+
28
+ export { nonZeroValueValidator };
29
+ //# sourceMappingURL=hmcts-opal-frontend-common-validators-non-zero-value.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hmcts/opal-frontend-common",
3
- "version": "0.0.70",
3
+ "version": "0.0.71",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -889,6 +889,11 @@
889
889
  "types": "./types/hmcts-opal-frontend-common-validators-national-insurance-number.d.ts",
890
890
  "default": "./fesm2022/hmcts-opal-frontend-common-validators-national-insurance-number.mjs"
891
891
  },
892
+ "./validators/non-negative-value": {
893
+ "import": "./fesm2022/hmcts-opal-frontend-common-validators-non-negative-value.mjs",
894
+ "types": "./types/hmcts-opal-frontend-common-validators-non-negative-value.d.ts",
895
+ "default": "./fesm2022/hmcts-opal-frontend-common-validators-non-negative-value.mjs"
896
+ },
892
897
  "./validators/optional-max-length": {
893
898
  "import": "./fesm2022/hmcts-opal-frontend-common-validators-optional-max-length.mjs",
894
899
  "types": "./types/hmcts-opal-frontend-common-validators-optional-max-length.d.ts",
@@ -924,6 +929,11 @@
924
929
  "types": "./types/hmcts-opal-frontend-common-validators-valid-value.d.ts",
925
930
  "default": "./fesm2022/hmcts-opal-frontend-common-validators-valid-value.mjs"
926
931
  },
932
+ "./validators/non-zero-value": {
933
+ "import": "./fesm2022/hmcts-opal-frontend-common-validators-non-zero-value.mjs",
934
+ "types": "./types/hmcts-opal-frontend-common-validators-non-zero-value.d.ts",
935
+ "default": "./fesm2022/hmcts-opal-frontend-common-validators-non-zero-value.mjs"
936
+ },
927
937
  "./styles": {
928
938
  "sass": "./styles/styles.scss",
929
939
  "default": "./styles/styles.scss"
@@ -0,0 +1,11 @@
1
+ import { ValidatorFn } from '@angular/forms';
2
+
3
+ /**
4
+ * Returns a validator function that rejects negative numeric values.
5
+ * Empty and non-numeric values are treated as valid.
6
+ *
7
+ * @returns A ValidatorFn that returns `{ negativeValue: true }` when the parsed value is negative, otherwise null.
8
+ */
9
+ declare function nonNegativeValueValidator(): ValidatorFn;
10
+
11
+ export { nonNegativeValueValidator };
@@ -0,0 +1,11 @@
1
+ import { ValidatorFn } from '@angular/forms';
2
+
3
+ /**
4
+ * Returns a validator function that rejects numeric zero values.
5
+ * Empty and non-numeric values are treated as valid.
6
+ *
7
+ * @returns A ValidatorFn that returns `{ zeroValue: true }` when the parsed value is zero, otherwise null.
8
+ */
9
+ declare function nonZeroValueValidator(): ValidatorFn;
10
+
11
+ export { nonZeroValueValidator };