@ukhomeoffice/cop-react-form-renderer 4.58.0 → 4.59.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/utils/Validate/additional/mustBeGreaterThan.js +7 -6
- package/dist/utils/Validate/additional/mustBeGreaterThan.test.js +10 -0
- package/dist/utils/Validate/additional/mustBeLessThan.js +7 -6
- package/dist/utils/Validate/additional/mustBeLessThan.test.js +11 -1
- package/dist/utils/Validate/additional/mustBeNumbersOnly.js +9 -6
- package/dist/utils/Validate/additional/mustBeNumbersOnly.test.js +10 -2
- package/package.json +1 -1
|
@@ -6,18 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {number} config.value - the
|
|
11
|
-
* @returns true if
|
|
9
|
+
* @param {*} value - the value to check.
|
|
10
|
+
* @param {number} config.value - the value must be greater than config.value.
|
|
11
|
+
* @returns true if value is greater than config.value, false if not.
|
|
12
12
|
*/
|
|
13
|
-
var mustBeGreaterThan = function mustBeGreaterThan(
|
|
14
|
-
if (!
|
|
13
|
+
var mustBeGreaterThan = function mustBeGreaterThan(value, config) {
|
|
14
|
+
if (!value) {
|
|
15
15
|
// null, undefined and empty strings should be picked up by the required flag
|
|
16
16
|
// and not considered here as they would be valid for optional fields.
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
var finalValue = typeof value === 'string' ? value.replace(/,/g, '') : value;
|
|
21
|
+
return parseFloat(finalValue) > config.value;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
var _default = mustBeGreaterThan;
|
|
@@ -24,6 +24,16 @@ describe('utils', function () {
|
|
|
24
24
|
});
|
|
25
25
|
expect(result2).toBeFalsy();
|
|
26
26
|
});
|
|
27
|
+
test('should correctly handle numbers with commas in', function () {
|
|
28
|
+
var result1 = (0, _mustBeGreaterThan.default)('999,999,999.99', {
|
|
29
|
+
value: 1000000000
|
|
30
|
+
});
|
|
31
|
+
expect(result1).toEqual(false);
|
|
32
|
+
var result2 = (0, _mustBeGreaterThan.default)('1,000,000,123', {
|
|
33
|
+
value: 1000000000
|
|
34
|
+
});
|
|
35
|
+
expect(result2).toEqual(true);
|
|
36
|
+
});
|
|
27
37
|
test('should return true when string is undefined', function () {
|
|
28
38
|
var result = (0, _mustBeGreaterThan.default)(undefined, {
|
|
29
39
|
value: 10
|
|
@@ -6,18 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {number} config.value - the
|
|
11
|
-
* @returns true if
|
|
9
|
+
* @param {*} value - the value to check.
|
|
10
|
+
* @param {number} config.value - the value must be equal or less than config.value.
|
|
11
|
+
* @returns true if value is equal to or less then config.value, false if not.
|
|
12
12
|
*/
|
|
13
|
-
var mustBeLessThan = function mustBeLessThan(
|
|
14
|
-
if (!
|
|
13
|
+
var mustBeLessThan = function mustBeLessThan(value, config) {
|
|
14
|
+
if (!value) {
|
|
15
15
|
// null, undefined and empty strings should be picked up by the required flag
|
|
16
16
|
// and not considered here as they would be valid for optional fields.
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
var finalValue = typeof value === 'string' ? value.replace(/,/g, '') : value;
|
|
21
|
+
return parseFloat(finalValue) < config.value;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
var _default = mustBeLessThan;
|
|
@@ -7,7 +7,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
7
7
|
describe('utils', function () {
|
|
8
8
|
describe('Validate', function () {
|
|
9
9
|
describe('additional', function () {
|
|
10
|
-
describe('
|
|
10
|
+
describe('mustBeLessThan', function () {
|
|
11
11
|
test('should return true given a number equal to or less than 1000000000', function () {
|
|
12
12
|
var result = (0, _mustBeLessThan.default)(999999999.999, {
|
|
13
13
|
value: 1000000000
|
|
@@ -20,6 +20,16 @@ describe('utils', function () {
|
|
|
20
20
|
});
|
|
21
21
|
expect(result).toBeFalsy();
|
|
22
22
|
});
|
|
23
|
+
test('should correctly handle numbers with commas in', function () {
|
|
24
|
+
var result1 = (0, _mustBeLessThan.default)('999,999,999.99', {
|
|
25
|
+
value: 1000000000
|
|
26
|
+
});
|
|
27
|
+
expect(result1).toEqual(true);
|
|
28
|
+
var result2 = (0, _mustBeLessThan.default)('1,000,000,123', {
|
|
29
|
+
value: 1000000000
|
|
30
|
+
});
|
|
31
|
+
expect(result2).toEqual(false);
|
|
32
|
+
});
|
|
23
33
|
test('should return true when string is undefined', function () {
|
|
24
34
|
var result = (0, _mustBeLessThan.default)(undefined, {
|
|
25
35
|
value: 3
|
|
@@ -6,18 +6,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Checks if a string contains only numberical characters.
|
|
10
|
+
* An optional flag in config can be used to allow commas.
|
|
11
|
+
* @param {*} value The value to check for only numerical characters.
|
|
12
|
+
* @param {object} config The config of the validation check.
|
|
13
|
+
* @returns true if value passes the regex, false if not.
|
|
10
14
|
*/
|
|
11
|
-
var mustBeNumbersOnly = function mustBeNumbersOnly(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (!number) {
|
|
15
|
+
var mustBeNumbersOnly = function mustBeNumbersOnly(value, config) {
|
|
16
|
+
if (!value) {
|
|
15
17
|
// null, undefined and empty numbers should be picked up by the required flag
|
|
16
18
|
// and not considered here as they would be valid for optional fields.
|
|
17
19
|
return true;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
var regex = config !== null && config !== void 0 && config.allowCommas ? /^[0-9,]*\.?[0-9]*$/ : /^[0-9]*\.?[0-9]*$/;
|
|
23
|
+
return regex.test(value);
|
|
21
24
|
};
|
|
22
25
|
|
|
23
26
|
var _default = mustBeNumbersOnly;
|
|
@@ -16,10 +16,18 @@ describe('utils', function () {
|
|
|
16
16
|
var result = (0, _mustBeNumbersOnly.default)('123456.123');
|
|
17
17
|
expect(result).toEqual(true);
|
|
18
18
|
});
|
|
19
|
-
test('should return false if given number contains
|
|
20
|
-
var
|
|
19
|
+
test('should return false if given number contains commas and config does not allow them', function () {
|
|
20
|
+
var CONFIG = {};
|
|
21
|
+
var result = (0, _mustBeNumbersOnly.default)('1,234', CONFIG);
|
|
21
22
|
expect(result).toEqual(false);
|
|
22
23
|
});
|
|
24
|
+
test('should return true if given number contains commas and config allows them', function () {
|
|
25
|
+
var CONFIG = {
|
|
26
|
+
allowCommas: true
|
|
27
|
+
};
|
|
28
|
+
var result = (0, _mustBeNumbersOnly.default)('1,234', CONFIG);
|
|
29
|
+
expect(result).toEqual(true);
|
|
30
|
+
});
|
|
23
31
|
test('should return true when string is undefined', function () {
|
|
24
32
|
var result = (0, _mustBeNumbersOnly.default)(undefined);
|
|
25
33
|
expect(result).toEqual(true);
|