@linzjs/step-ag-grid 14.6.0 → 14.7.0
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/src/utils/textValidator.d.ts +1 -0
- package/dist/step-ag-grid.esm.js +19 -6
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/textValidator.test.ts +7 -0
- package/src/utils/textValidator.ts +8 -4
- package/src/utils/util.test.ts +12 -1
- package/src/utils/util.ts +11 -2
package/package.json
CHANGED
|
@@ -13,6 +13,7 @@ export interface TextInputValidatorProps<RowType extends GridBaseRow> {
|
|
|
13
13
|
geMin?: number;
|
|
14
14
|
ltMax?: number;
|
|
15
15
|
leMax?: number;
|
|
16
|
+
notZero?: boolean;
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -44,17 +45,20 @@ export const TextInputValidator = <RowType extends GridBaseRow>(
|
|
|
44
45
|
}
|
|
45
46
|
if (value != "") {
|
|
46
47
|
const number = parseFloat(value);
|
|
48
|
+
if (nf.notZero && number === 0) {
|
|
49
|
+
return `Must not be 0`;
|
|
50
|
+
}
|
|
47
51
|
if (nf.gtMin != null && number <= nf.gtMin) {
|
|
48
|
-
return `Must be greater than ${nf.gtMin}`;
|
|
52
|
+
return `Must be greater than ${nf.gtMin.toLocaleString()}`;
|
|
49
53
|
}
|
|
50
54
|
if (nf.geMin != null && number < nf.geMin) {
|
|
51
|
-
return `Must not be less than ${nf.geMin}`;
|
|
55
|
+
return `Must not be less than ${nf.geMin.toLocaleString()}`;
|
|
52
56
|
}
|
|
53
57
|
if (nf.ltMax != null && number >= nf.ltMax) {
|
|
54
|
-
return `Must be less than ${nf.ltMax}`;
|
|
58
|
+
return `Must be less than ${nf.ltMax.toLocaleString()}`;
|
|
55
59
|
}
|
|
56
60
|
if (nf.leMax != null && number > nf.leMax) {
|
|
57
|
-
return `Must not be greater than ${nf.leMax}`;
|
|
61
|
+
return `Must not be greater than ${nf.leMax.toLocaleString()}`;
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
if (nf.precision != null && value != "") {
|
package/src/utils/util.test.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import { sanitiseFileName } from "./util";
|
|
1
|
+
import { isFloat, sanitiseFileName } from "./util";
|
|
2
2
|
|
|
3
3
|
describe("sanitiseFileName", () => {
|
|
4
|
+
test("isFloat", () => {
|
|
5
|
+
expect(isFloat("")).toBe(false);
|
|
6
|
+
expect(isFloat("x")).toBe(false);
|
|
7
|
+
expect(isFloat("1e10")).toBe(false);
|
|
8
|
+
expect(isFloat("1x")).toBe(false);
|
|
9
|
+
expect(isFloat("1.x")).toBe(false);
|
|
10
|
+
expect(isFloat("x.1")).toBe(false);
|
|
11
|
+
expect(isFloat("1")).toBe(true);
|
|
12
|
+
expect(isFloat("1.")).toBe(true);
|
|
13
|
+
expect(isFloat(".1")).toBe(true);
|
|
14
|
+
});
|
|
4
15
|
test("sanitiseFileName", () => {
|
|
5
16
|
expect(sanitiseFileName(" LT 1235/543 &%//*$ ")).toBe("LT_1235-543_&%-$");
|
|
6
17
|
expect(sanitiseFileName(" @filename here!!! ")).toBe("@filename_here!!!");
|
package/src/utils/util.ts
CHANGED
|
@@ -8,9 +8,18 @@ export const wait = (timeoutMs: number) =>
|
|
|
8
8
|
setTimeout(resolve, timeoutMs);
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
+
// This regexp only works if you parseFloat first, it won't validate a float on its own
|
|
12
|
+
// It prevents scientific 1e10, or trailing decimal 1.2.3, or trailing garbage 1.2xyz
|
|
13
|
+
const isFloatRegExp = /^-?\d*\.?\d*$/;
|
|
11
14
|
export const isFloat = (value: string) => {
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
try {
|
|
16
|
+
// Just checking it's not scientific notation or "NaN" here.
|
|
17
|
+
// Also parse float will parse up to the first invalid character,
|
|
18
|
+
// so we need to check there's no remaining invalids e.g. "1.2xyz" would parse as 1.2
|
|
19
|
+
return !Number.isNaN(parseFloat(value)) && isFloatRegExp.test(value);
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
14
23
|
};
|
|
15
24
|
|
|
16
25
|
export const findParentWithClass = function (className: string, child: Node): HTMLElement | null {
|