@dhis2/ui-forms 8.4.2 → 8.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,5 +26,5 @@
26
26
  "Please provide a number": "Please provide a number",
27
27
  "Please provide a string": "Please provide a string",
28
28
  "Please provide a valid url": "Please provide a valid url",
29
- "Please provide a lowercase username between 4 and 255 characters long and possibly separated by . _ @ or #": "Please provide a lowercase username between 4 and 255 characters long and possibly separated by . _ @ or #"
29
+ "Please provide a username between 4 and 255 characters long and possibly separated by . _ @ or #": "Please provide a username between 4 and 255 characters long and possibly separated by . _ @ or #"
30
30
  }
@@ -20,7 +20,7 @@ describe('validator: dhis2Username', () => {
20
20
  (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, _dhis2Username.invalidUsernameMessage, ['__xx', '..xx', '@@xx']);
21
21
  });
22
22
  describe('constrains characters in usernames to [a-z0-9._@]', () => {
23
- (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, undefined, ['v@lid_user.name', '123another_v@lid_usern@me']);
23
+ (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, undefined, ['v@lid_user.name', '123another_v@lid_usern@me', 'UPPER_CASE', 'lower@ca.se']);
24
24
  (0, _index.testValidatorValues)(_dhis2Username.dhis2Username, _dhis2Username.invalidUsernameMessage, ['あいうえお', 'some_username^%&*(']);
25
25
  });
26
26
  describe('rejects non-string data types', () => {
@@ -9,10 +9,10 @@ describe('validator: integer', () => {
9
9
  describe('allows integers and string representations of integers', () => {
10
10
  (0, _index.testValidatorValues)(_integer.integer, undefined, [-2, 0, 2, 10000, '-2', '0', '2', '10000', 12e4]);
11
11
  });
12
- describe('rejects other data types', () => {
13
- (0, _index.testValidatorValues)(_integer.integer, _integer.invalidIntegerMessage, ['text', true, {}, [], () => {}]);
12
+ describe('rejects other data types and leading zeros', () => {
13
+ (0, _index.testValidatorValues)(_integer.integer, _integer.invalidIntegerMessage, ['text', '014', true, {}, [], () => {}]);
14
14
  });
15
15
  describe('rejects floats and string representations of floats', () => {
16
- (0, _index.testValidatorValues)(_integer.integer, _integer.invalidIntegerMessage, [0.23456, 5.987, 1e-12, '0.23456', '5.987', '1e-12']);
16
+ (0, _index.testValidatorValues)(_integer.integer, _integer.invalidIntegerMessage, [0.23456, 5.987, 1e-12, '4.0', '4.000', '4,0', '0.23456', '5.987', '1e-12']);
17
17
  });
18
18
  });
@@ -11,9 +11,9 @@ var _index2 = require("./helpers/index.js");
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- const USERNAME_PATTERN = /^(?=.{4,255}$)(?![_.@])(?!.*[_.@]{2})[a-z0-9._@]+(?<![_.@])$/;
14
+ const USERNAME_PATTERN = /^(?=.{4,255}$)(?![_.@])(?!.*[_.@]{2})[a-zA-Z0-9._@]+(?<![_.@])$/;
15
15
 
16
- const invalidUsernameMessage = _index.default.t('Please provide a lowercase username between 4 and 255 characters long and possibly separated by . _ @ or #');
16
+ const invalidUsernameMessage = _index.default.t('Please provide a username between 4 and 255 characters long and possibly separated by . _ @ or #');
17
17
 
18
18
  exports.invalidUsernameMessage = invalidUsernameMessage;
19
19
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.toNumber = exports.requiredArgumentErrorMessage = exports.requireArgument = exports.isString = exports.isNumeric = exports.isNumber = exports.isInteger = exports.isInRange = exports.isEmpty = void 0;
6
+ exports.toNumber = exports.requiredArgumentErrorMessage = exports.requireArgument = exports.isString = exports.isNumeric = exports.isNumber = exports.isInRange = exports.isEmpty = void 0;
7
7
 
8
8
  const isEmpty = value => typeof value === 'undefined' || value === null || value === '';
9
9
 
@@ -13,10 +13,6 @@ const isString = value => typeof value === 'string';
13
13
 
14
14
  exports.isString = isString;
15
15
 
16
- const isInteger = value => Number.isSafeInteger(value);
17
-
18
- exports.isInteger = isInteger;
19
-
20
16
  const isNumber = value => typeof value === 'number';
21
17
 
22
18
  exports.isNumber = isNumber;
@@ -11,10 +11,13 @@ var _index2 = require("./helpers/index.js");
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- const invalidIntegerMessage = _index.default.t('Please provide a round number without decimals');
14
+ const invalidIntegerMessage = _index.default.t('Please provide a round number without decimals'); // Regex accepts only digits (no decimals even if it is trailing like 4.0)
15
+ // it also rejects a leading 0 (i.e 04) as this is rejected by backend
16
+
15
17
 
16
18
  exports.invalidIntegerMessage = invalidIntegerMessage;
19
+ const INTEGER_PATTERN = /^(-?[1-9]\d*|0)$/;
17
20
 
18
- const integer = value => (0, _index2.isEmpty)(value) || (0, _index2.isNumeric)(value) && (0, _index2.isInteger)((0, _index2.toNumber)(value)) ? undefined : invalidIntegerMessage;
21
+ const integer = value => (0, _index2.isEmpty)(value) || INTEGER_PATTERN.test(value) && (0, _index2.isNumeric)(value) && Number.isSafeInteger((0, _index2.toNumber)(value)) ? undefined : invalidIntegerMessage;
19
22
 
20
23
  exports.integer = integer;
@@ -26,5 +26,5 @@
26
26
  "Please provide a number": "Please provide a number",
27
27
  "Please provide a string": "Please provide a string",
28
28
  "Please provide a valid url": "Please provide a valid url",
29
- "Please provide a lowercase username between 4 and 255 characters long and possibly separated by . _ @ or #": "Please provide a lowercase username between 4 and 255 characters long and possibly separated by . _ @ or #"
29
+ "Please provide a username between 4 and 255 characters long and possibly separated by . _ @ or #": "Please provide a username between 4 and 255 characters long and possibly separated by . _ @ or #"
30
30
  }
@@ -16,7 +16,7 @@ describe('validator: dhis2Username', () => {
16
16
  testValidatorValues(dhis2Username, invalidUsernameMessage, ['__xx', '..xx', '@@xx']);
17
17
  });
18
18
  describe('constrains characters in usernames to [a-z0-9._@]', () => {
19
- testValidatorValues(dhis2Username, undefined, ['v@lid_user.name', '123another_v@lid_usern@me']);
19
+ testValidatorValues(dhis2Username, undefined, ['v@lid_user.name', '123another_v@lid_usern@me', 'UPPER_CASE', 'lower@ca.se']);
20
20
  testValidatorValues(dhis2Username, invalidUsernameMessage, ['あいうえお', 'some_username^%&*(']);
21
21
  });
22
22
  describe('rejects non-string data types', () => {
@@ -5,10 +5,10 @@ describe('validator: integer', () => {
5
5
  describe('allows integers and string representations of integers', () => {
6
6
  testValidatorValues(integer, undefined, [-2, 0, 2, 10000, '-2', '0', '2', '10000', 12e4]);
7
7
  });
8
- describe('rejects other data types', () => {
9
- testValidatorValues(integer, invalidIntegerMessage, ['text', true, {}, [], () => {}]);
8
+ describe('rejects other data types and leading zeros', () => {
9
+ testValidatorValues(integer, invalidIntegerMessage, ['text', '014', true, {}, [], () => {}]);
10
10
  });
11
11
  describe('rejects floats and string representations of floats', () => {
12
- testValidatorValues(integer, invalidIntegerMessage, [0.23456, 5.987, 1e-12, '0.23456', '5.987', '1e-12']);
12
+ testValidatorValues(integer, invalidIntegerMessage, [0.23456, 5.987, 1e-12, '4.0', '4.000', '4,0', '0.23456', '5.987', '1e-12']);
13
13
  });
14
14
  });
@@ -1,7 +1,7 @@
1
1
  import i18n from '../locales/index.js';
2
2
  import { isEmpty, isString } from './helpers/index.js';
3
- const USERNAME_PATTERN = /^(?=.{4,255}$)(?![_.@])(?!.*[_.@]{2})[a-z0-9._@]+(?<![_.@])$/;
4
- const invalidUsernameMessage = i18n.t('Please provide a lowercase username between 4 and 255 characters long and possibly separated by . _ @ or #');
3
+ const USERNAME_PATTERN = /^(?=.{4,255}$)(?![_.@])(?!.*[_.@]{2})[a-zA-Z0-9._@]+(?<![_.@])$/;
4
+ const invalidUsernameMessage = i18n.t('Please provide a username between 4 and 255 characters long and possibly separated by . _ @ or #');
5
5
 
6
6
  const dhis2Username = value => isEmpty(value) || isString(value) && USERNAME_PATTERN.test(value) ? undefined : invalidUsernameMessage;
7
7
 
@@ -1,6 +1,5 @@
1
1
  export const isEmpty = value => typeof value === 'undefined' || value === null || value === '';
2
2
  export const isString = value => typeof value === 'string';
3
- export const isInteger = value => Number.isSafeInteger(value);
4
3
  export const isNumber = value => typeof value === 'number';
5
4
  export const isNumeric = value => (isString(value) || isNumber(value)) && !isNaN(value);
6
5
  export const isInRange = (lowerBound, upperBound, value) => value >= lowerBound && value <= upperBound;
@@ -1,7 +1,10 @@
1
1
  import i18n from '../locales/index.js';
2
- import { isEmpty, isInteger, isNumeric, toNumber } from './helpers/index.js';
3
- const invalidIntegerMessage = i18n.t('Please provide a round number without decimals');
2
+ import { isEmpty, isNumeric, toNumber } from './helpers/index.js';
3
+ const invalidIntegerMessage = i18n.t('Please provide a round number without decimals'); // Regex accepts only digits (no decimals even if it is trailing like 4.0)
4
+ // it also rejects a leading 0 (i.e 04) as this is rejected by backend
4
5
 
5
- const integer = value => isEmpty(value) || isNumeric(value) && isInteger(toNumber(value)) ? undefined : invalidIntegerMessage;
6
+ const INTEGER_PATTERN = /^(-?[1-9]\d*|0)$/;
7
+
8
+ const integer = value => isEmpty(value) || INTEGER_PATTERN.test(value) && isNumeric(value) && Number.isSafeInteger(toNumber(value)) ? undefined : invalidIntegerMessage;
6
9
 
7
10
  export { integer, invalidIntegerMessage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/ui-forms",
3
- "version": "8.4.2",
3
+ "version": "8.4.5",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "sideEffects": [
@@ -34,15 +34,15 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@dhis2/prop-types": "^3.1.2",
37
- "@dhis2-ui/button": "8.4.2",
38
- "@dhis2-ui/checkbox": "8.4.2",
39
- "@dhis2-ui/field": "8.4.2",
40
- "@dhis2-ui/file-input": "8.4.2",
41
- "@dhis2-ui/input": "8.4.2",
42
- "@dhis2-ui/radio": "8.4.2",
43
- "@dhis2-ui/select": "8.4.2",
44
- "@dhis2-ui/switch": "8.4.2",
45
- "@dhis2-ui/text-area": "8.4.2",
37
+ "@dhis2-ui/button": "8.4.5",
38
+ "@dhis2-ui/checkbox": "8.4.5",
39
+ "@dhis2-ui/field": "8.4.5",
40
+ "@dhis2-ui/file-input": "8.4.5",
41
+ "@dhis2-ui/input": "8.4.5",
42
+ "@dhis2-ui/radio": "8.4.5",
43
+ "@dhis2-ui/select": "8.4.5",
44
+ "@dhis2-ui/switch": "8.4.5",
45
+ "@dhis2-ui/text-area": "8.4.5",
46
46
  "classnames": "^2.3.1",
47
47
  "final-form": "^4.20.2",
48
48
  "prop-types": "^15.7.2",