dce-reactkit 3.4.0 → 3.5.1-beta.1

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.
Files changed (129) hide show
  1. package/.eslintrc.js +2 -0
  2. package/.vscode/settings.json +1 -0
  3. package/dist/cjs/index.js +36372 -191
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +10 -0
  6. package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +34 -0
  7. package/dist/cjs/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +9 -0
  8. package/dist/cjs/types/components/DBEntryManagerPanel/index.d.ts +25 -0
  9. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +8 -0
  10. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +49 -0
  11. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntryFieldType.d.ts +12 -0
  12. package/dist/cjs/types/helpers/addDBEditorEndpoints.d.ts +40 -0
  13. package/dist/cjs/types/helpers/canReviewLogs.d.ts +0 -5
  14. package/dist/cjs/types/index.d.ts +6 -1
  15. package/dist/esm/index.js +36587 -427
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +10 -0
  18. package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +34 -0
  19. package/dist/esm/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +9 -0
  20. package/dist/esm/types/components/DBEntryManagerPanel/index.d.ts +25 -0
  21. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +8 -0
  22. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +49 -0
  23. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntryFieldType.d.ts +12 -0
  24. package/dist/esm/types/helpers/addDBEditorEndpoints.d.ts +40 -0
  25. package/dist/esm/types/helpers/canReviewLogs.d.ts +0 -5
  26. package/dist/esm/types/index.d.ts +6 -1
  27. package/dist/index.d.ts +166 -35
  28. package/package.json +16 -12
  29. package/src/client/initClient.tsx +23 -31
  30. package/src/components/AppWrapper.tsx +1 -1
  31. package/src/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.tsx +303 -0
  32. package/src/components/DBEntryManagerPanel/AddOrEditDBEntry/index.tsx +737 -0
  33. package/src/components/DBEntryManagerPanel/helpers/generateEndpointPath.ts +16 -0
  34. package/src/components/DBEntryManagerPanel/index.tsx +522 -0
  35. package/src/components/DBEntryManagerPanel/types/DBEntry.ts +7 -0
  36. package/src/components/DBEntryManagerPanel/types/DBEntryField.ts +94 -0
  37. package/src/components/DBEntryManagerPanel/types/DBEntryFieldType.ts +18 -0
  38. package/src/components/ItemPicker/index.test.tsx +10 -10
  39. package/src/helpers/addDBEditorEndpoints.ts +128 -0
  40. package/src/helpers/canReviewLogs.ts +0 -20
  41. package/src/helpers/genCSV.ts +2 -5
  42. package/src/helpers/{getOrdinal.ts → getOrdinal.tsx} +0 -1
  43. package/src/index.ts +11 -9
  44. package/tsconfig.json +2 -6
  45. package/dist/cjs/types/helpers/abbreviate.test.d.ts +0 -5
  46. package/dist/cjs/types/helpers/avg.test.d.ts +0 -5
  47. package/dist/cjs/types/helpers/canReviewLogs.test.d.ts +0 -5
  48. package/dist/cjs/types/helpers/ceilToNumDecimals.test.d.ts +0 -5
  49. package/dist/cjs/types/helpers/compareArraysByProp.test.d.ts +0 -5
  50. package/dist/cjs/types/helpers/extractProp.test.d.ts +0 -5
  51. package/dist/cjs/types/helpers/floorToNumDecimals.test.d.ts +0 -5
  52. package/dist/cjs/types/helpers/forceNumIntoBounds.test.d.ts +0 -5
  53. package/dist/cjs/types/helpers/genCSV.test.d.ts +0 -5
  54. package/dist/cjs/types/helpers/genCommaList.d.ts +0 -12
  55. package/dist/cjs/types/helpers/genCommaList.test.d.ts +0 -1
  56. package/dist/cjs/types/helpers/getHumanReadableDate.test.d.ts +0 -5
  57. package/dist/cjs/types/helpers/getLocalTimeInfo.test.d.ts +0 -6
  58. package/dist/cjs/types/helpers/getMonthName.test.d.ts +0 -5
  59. package/dist/cjs/types/helpers/getOrdinal.test.d.ts +0 -5
  60. package/dist/cjs/types/helpers/getPartOfDay.test.d.ts +0 -5
  61. package/dist/cjs/types/helpers/getTimeInfoInET.test.d.ts +0 -5
  62. package/dist/cjs/types/helpers/validators/shared/constants/ERROR_MESSAGES.d.ts +0 -10
  63. package/dist/cjs/types/helpers/validators/shared/helpers/validateRegex.d.ts +0 -19
  64. package/dist/cjs/types/helpers/validators/shared/types/ValidationResult.d.ts +0 -12
  65. package/dist/cjs/types/helpers/validators/validateEmail.d.ts +0 -11
  66. package/dist/cjs/types/helpers/validators/validateEmail.test.d.ts +0 -1
  67. package/dist/cjs/types/helpers/validators/validatePhoneNumber.d.ts +0 -11
  68. package/dist/cjs/types/helpers/validators/validatePhoneNumber.test.d.ts +0 -1
  69. package/dist/cjs/types/helpers/validators/validateString.d.ts +0 -22
  70. package/dist/cjs/types/helpers/validators/validateString.test.d.ts +0 -1
  71. package/dist/esm/types/helpers/abbreviate.test.d.ts +0 -5
  72. package/dist/esm/types/helpers/avg.test.d.ts +0 -5
  73. package/dist/esm/types/helpers/canReviewLogs.test.d.ts +0 -5
  74. package/dist/esm/types/helpers/ceilToNumDecimals.test.d.ts +0 -5
  75. package/dist/esm/types/helpers/compareArraysByProp.test.d.ts +0 -5
  76. package/dist/esm/types/helpers/extractProp.test.d.ts +0 -5
  77. package/dist/esm/types/helpers/floorToNumDecimals.test.d.ts +0 -5
  78. package/dist/esm/types/helpers/forceNumIntoBounds.test.d.ts +0 -5
  79. package/dist/esm/types/helpers/genCSV.test.d.ts +0 -5
  80. package/dist/esm/types/helpers/genCommaList.d.ts +0 -12
  81. package/dist/esm/types/helpers/genCommaList.test.d.ts +0 -1
  82. package/dist/esm/types/helpers/getHumanReadableDate.test.d.ts +0 -5
  83. package/dist/esm/types/helpers/getLocalTimeInfo.test.d.ts +0 -6
  84. package/dist/esm/types/helpers/getMonthName.test.d.ts +0 -5
  85. package/dist/esm/types/helpers/getOrdinal.test.d.ts +0 -5
  86. package/dist/esm/types/helpers/getPartOfDay.test.d.ts +0 -5
  87. package/dist/esm/types/helpers/getTimeInfoInET.test.d.ts +0 -5
  88. package/dist/esm/types/helpers/validators/shared/constants/ERROR_MESSAGES.d.ts +0 -10
  89. package/dist/esm/types/helpers/validators/shared/helpers/validateRegex.d.ts +0 -19
  90. package/dist/esm/types/helpers/validators/shared/types/ValidationResult.d.ts +0 -12
  91. package/dist/esm/types/helpers/validators/validateEmail.d.ts +0 -11
  92. package/dist/esm/types/helpers/validators/validateEmail.test.d.ts +0 -1
  93. package/dist/esm/types/helpers/validators/validatePhoneNumber.d.ts +0 -11
  94. package/dist/esm/types/helpers/validators/validatePhoneNumber.test.d.ts +0 -1
  95. package/dist/esm/types/helpers/validators/validateString.d.ts +0 -22
  96. package/dist/esm/types/helpers/validators/validateString.test.d.ts +0 -1
  97. package/src/helpers/abbreviate.test.ts +0 -26
  98. package/src/helpers/avg.test.ts +0 -24
  99. package/src/helpers/canReviewLogs.test.ts +0 -67
  100. package/src/helpers/ceilToNumDecimals.test.ts +0 -39
  101. package/src/helpers/compareArraysByProp.test.ts +0 -102
  102. package/src/helpers/extractProp.test.ts +0 -34
  103. package/src/helpers/floorToNumDecimals.test.ts +0 -39
  104. package/src/helpers/forceNumIntoBounds.test.ts +0 -34
  105. package/src/helpers/genCSV.test.ts +0 -61
  106. package/src/helpers/genCommaList.test.ts +0 -57
  107. package/src/helpers/genCommaList.ts +0 -21
  108. package/src/helpers/getHumanReadableDate.test.ts +0 -29
  109. package/src/helpers/getLocalTimeInfo.test.ts +0 -48
  110. package/src/helpers/getMonthName.test.ts +0 -79
  111. package/src/helpers/getOrdinal.test.ts +0 -84
  112. package/src/helpers/getPartOfDay.test.ts +0 -56
  113. package/src/helpers/getTimeInfoInET.test.ts +0 -72
  114. package/src/helpers/validators/shared/constants/ERROR_MESSAGES.ts +0 -18
  115. package/src/helpers/validators/shared/helpers/validateRegex.ts +0 -47
  116. package/src/helpers/validators/shared/types/ValidationResult.ts +0 -20
  117. package/src/helpers/validators/validateEmail.test.ts +0 -110
  118. package/src/helpers/validators/validateEmail.ts +0 -47
  119. package/src/helpers/validators/validatePhoneNumber.test.ts +0 -94
  120. package/src/helpers/validators/validatePhoneNumber.ts +0 -49
  121. package/src/helpers/validators/validateString.test.ts +0 -175
  122. package/src/helpers/validators/validateString.ts +0 -171
  123. /package/src/helpers/{abbreviate.ts → abbreviate.tsx} +0 -0
  124. /package/src/helpers/{avg.ts → avg.tsx} +0 -0
  125. /package/src/helpers/{ceilToNumDecimals.ts → ceilToNumDecimals.tsx} +0 -0
  126. /package/src/helpers/{floorToNumDecimals.ts → floorToNumDecimals.tsx} +0 -0
  127. /package/src/helpers/{forceNumIntoBounds.ts → forceNumIntoBounds.tsx} +0 -0
  128. /package/src/helpers/{getLocalTimeInfo.ts → getLocalTimeInfo.tsx} +0 -0
  129. /package/src/helpers/{getTimeInfoInET.ts → getTimeInfoInET.tsx} +0 -0
@@ -1,29 +0,0 @@
1
- /**
2
- * Test file for the getHumanReadableDate helper
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import helpers
7
- import getHumanReadableDate from './getHumanReadableDate';
8
- import getOrdinal from './getOrdinal';
9
-
10
- describe('getHumanReadableDate', () => {
11
- it('should return the current date if no argument is passed', () => {
12
- const result = getHumanReadableDate();
13
- const now = new Date();
14
- const expected = `${now.toLocaleString('default', { month: 'short' })} ${now.getDate()}${getOrdinal(now.getDate())}`;
15
- expect(result).toEqual(expected);
16
- });
17
-
18
- it('should return the correct date for a given timestamp', () => {
19
- const timestamp = 1629822000000; // 2021-08-24T12:20:00.000Z
20
- const result = getHumanReadableDate(timestamp);
21
- expect(result).toEqual('Aug 24th 2021');
22
- });
23
-
24
- it('should return the correct date for a given Date object', () => {
25
- const date = new Date('2021-08-24T12:20:00.000Z');
26
- const result = getHumanReadableDate(date);
27
- expect(result).toEqual('Aug 24th 2021');
28
- });
29
- });
@@ -1,48 +0,0 @@
1
- /**
2
- * Test for getLocalTimeInfo helper function
3
- * NOTE: only works if this test is run on a machine in ET
4
- * @author Gabe Abrams
5
- */
6
-
7
- // Import main function
8
- import getLocalTimeInfo from './getLocalTimeInfo';
9
-
10
- describe('getLocalTimeInfo', () => {
11
- it('should return current time info if no argument is passed', () => {
12
- const result = getLocalTimeInfo();
13
- const now = new Date();
14
- expect(result.timestamp).toBeCloseTo(now.getTime(), -3);
15
- expect(result.year).toEqual(now.getFullYear());
16
- expect(result.month).toEqual(now.getMonth() + 1);
17
- expect(result.day).toEqual(now.getDate());
18
- expect(result.hour).toEqual(now.getHours());
19
- expect(result.minute).toEqual(now.getMinutes());
20
- expect(result.isPM).toEqual(now.getHours() >= 12);
21
- });
22
-
23
- it('should return correct time info for a given timestamp', () => {
24
- const timestamp = 1629822000000; // 2021-08-24T12:20:00.000Z
25
- const result = getLocalTimeInfo(timestamp);
26
- expect(result.timestamp).toEqual(timestamp);
27
- expect(result.year).toEqual(2021);
28
- expect(result.month).toEqual(8);
29
- expect(result.day).toEqual(24);
30
- expect(result.hour).toEqual(12);
31
- expect(result.hour12).toEqual(12);
32
- expect(result.minute).toEqual(20);
33
- expect(result.isPM).toEqual(true);
34
- });
35
-
36
- it('should return correct time info for a given Date object', () => {
37
- const date = new Date('2021-08-24T12:20:00.000Z');
38
- const result = getLocalTimeInfo(date);
39
- expect(result.timestamp).toEqual(date.getTime());
40
- expect(result.year).toEqual(2021);
41
- expect(result.month).toEqual(8);
42
- expect(result.day).toEqual(24);
43
- expect(result.hour).toEqual(8);
44
- expect(result.hour12).toEqual(8);
45
- expect(result.minute).toEqual(20);
46
- expect(result.isPM).toEqual(false);
47
- });
48
- });
@@ -1,79 +0,0 @@
1
- /**
2
- * Test for getMonthName helper
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import main helper
7
- import getMonthName from './getMonthName';
8
-
9
- describe('getMonthName', () => {
10
- it('should return January for 1', () => {
11
- const result = getMonthName(1);
12
- expect(result).toEqual({ short: 'Jan', full: 'January' });
13
- });
14
-
15
- it('should return February for 2', () => {
16
- const result = getMonthName(2);
17
- expect(result).toEqual({ short: 'Feb', full: 'February' });
18
- });
19
-
20
- it('should return March for 3', () => {
21
- const result = getMonthName(3);
22
- expect(result).toEqual({ short: 'Mar', full: 'March' });
23
- });
24
-
25
- it('should return April for 4', () => {
26
- const result = getMonthName(4);
27
- expect(result).toEqual({ short: 'Apr', full: 'April' });
28
- });
29
-
30
- it('should return May for 5', () => {
31
- const result = getMonthName(5);
32
- expect(result).toEqual({ short: 'May', full: 'May' });
33
- });
34
-
35
- it('should return June for 6', () => {
36
- const result = getMonthName(6);
37
- expect(result).toEqual({ short: 'Jun', full: 'June' });
38
- });
39
-
40
- it('should return July for 7', () => {
41
- const result = getMonthName(7);
42
- expect(result).toEqual({ short: 'Jul', full: 'July' });
43
- });
44
-
45
- it('should return August for 8', () => {
46
- const result = getMonthName(8);
47
- expect(result).toEqual({ short: 'Aug', full: 'August' });
48
- });
49
-
50
- it('should return September for 9', () => {
51
- const result = getMonthName(9);
52
- expect(result).toEqual({ short: 'Sep', full: 'September' });
53
- });
54
-
55
- it('should return October for 10', () => {
56
- const result = getMonthName(10);
57
- expect(result).toEqual({ short: 'Oct', full: 'October' });
58
- });
59
-
60
- it('should return November for 11', () => {
61
- const result = getMonthName(11);
62
- expect(result).toEqual({ short: 'Nov', full: 'November' });
63
- });
64
-
65
- it('should return December for 12', () => {
66
- const result = getMonthName(12);
67
- expect(result).toEqual({ short: 'Dec', full: 'December' });
68
- });
69
-
70
- it('should return January for 0', () => {
71
- const result = getMonthName(0);
72
- expect(result).toEqual({ short: 'Jan', full: 'January' });
73
- });
74
-
75
- it('should return January for 13', () => {
76
- const result = getMonthName(13);
77
- expect(result).toEqual({ short: 'Jan', full: 'January' });
78
- });
79
- });
@@ -1,84 +0,0 @@
1
- /**
2
- * Test file for the getOrdinal helper
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import main function
7
- import getOrdinal from './getOrdinal';
8
-
9
- describe('getOrdinal', () => {
10
- it('should return "th" for 0', () => {
11
- const result = getOrdinal(0);
12
- expect(result).toEqual('th');
13
- });
14
-
15
- it('should return "st" for 1', () => {
16
- const result = getOrdinal(1);
17
- expect(result).toEqual('st');
18
- });
19
-
20
- it('should return "nd" for 2', () => {
21
- const result = getOrdinal(2);
22
- expect(result).toEqual('nd');
23
- });
24
-
25
- it('should return "rd" for 3', () => {
26
- const result = getOrdinal(3);
27
- expect(result).toEqual('rd');
28
- });
29
-
30
- it('should return "th" for 4', () => {
31
- const result = getOrdinal(4);
32
- expect(result).toEqual('th');
33
- });
34
-
35
- it('should return "th" for 11', () => {
36
- const result = getOrdinal(11);
37
- expect(result).toEqual('th');
38
- });
39
-
40
- it('should return "st" for 21', () => {
41
- const result = getOrdinal(21);
42
- expect(result).toEqual('st');
43
- });
44
-
45
- it('should return "nd" for 22', () => {
46
- const result = getOrdinal(22);
47
- expect(result).toEqual('nd');
48
- });
49
-
50
- it('should return "rd" for 23', () => {
51
- const result = getOrdinal(23);
52
- expect(result).toEqual('rd');
53
- });
54
-
55
- it('should return "th" for 24', () => {
56
- const result = getOrdinal(24);
57
- expect(result).toEqual('th');
58
- });
59
-
60
- it('should return "th" for 100', () => {
61
- const result = getOrdinal(100);
62
- expect(result).toEqual('th');
63
- });
64
-
65
- it('should return "st" for 101', () => {
66
- const result = getOrdinal(101);
67
- expect(result).toEqual('st');
68
- });
69
-
70
- it('should return "nd" for 102', () => {
71
- const result = getOrdinal(102);
72
- expect(result).toEqual('nd');
73
- });
74
-
75
- it('should return "rd" for 103', () => {
76
- const result = getOrdinal(103);
77
- expect(result).toEqual('rd');
78
- });
79
-
80
- it('should return "th" for 104', () => {
81
- const result = getOrdinal(104);
82
- expect(result).toEqual('th');
83
- });
84
- });
@@ -1,56 +0,0 @@
1
- /**
2
- * Test file for the getPartOfDay helper
3
- * @author Gabe Abrams
4
- */
5
-
6
- import getPartOfDay from './getPartOfDay';
7
-
8
- describe('getPartOfDay', () => {
9
- it('should return "morning" if the current hour is less than 12', () => {
10
- // Mock the current hour to be 9am
11
- jest.spyOn(Date.prototype, 'getHours').mockReturnValue(9);
12
-
13
- const result = getPartOfDay();
14
- expect(result).toEqual('morning');
15
- });
16
-
17
- it('should return "afternoon" if the current hour is between 12 and 16 (inclusive)', () => {
18
- // Mock the current hour to be 2pm
19
- jest.spyOn(Date.prototype, 'getHours').mockReturnValue(14);
20
-
21
- const result = getPartOfDay();
22
- expect(result).toEqual('afternoon');
23
- });
24
-
25
- it('should return "evening" if the current hour is between 17 and 24 (inclusive)', () => {
26
- // Mock the current hour to be 8pm
27
- jest.spyOn(Date.prototype, 'getHours').mockReturnValue(20);
28
-
29
- const result = getPartOfDay();
30
- expect(result).toEqual('evening');
31
- });
32
-
33
- it('should return "evening" if the current hour is 17', () => {
34
- // Mock the current hour to be 5pm
35
- jest.spyOn(Date.prototype, 'getHours').mockReturnValue(17);
36
-
37
- const result = getPartOfDay();
38
- expect(result).toEqual('evening');
39
- });
40
-
41
- it('should return "evening" if the current hour is 24', () => {
42
- // Mock the current hour to be midnight
43
- jest.spyOn(Date.prototype, 'getHours').mockReturnValue(24);
44
-
45
- const result = getPartOfDay();
46
- expect(result).toEqual('evening');
47
- });
48
-
49
- it('should return "morning" if the current hour is 0', () => {
50
- // Mock the current hour to be midnight
51
- jest.spyOn(Date.prototype, 'getHours').mockReturnValue(0);
52
-
53
- const result = getPartOfDay();
54
- expect(result).toEqual('morning');
55
- });
56
- });
@@ -1,72 +0,0 @@
1
- /**
2
- * Test file for the getTimeInfoInET helper
3
- * @author Gabe Abrams
4
- */
5
-
6
- // Import main function
7
- import getTimeInfoInET from './getTimeInfoInET';
8
-
9
- describe('getTimeInfoInET', () => {
10
- it('should return the current time info in ET if no argument is passed', () => {
11
- const result = getTimeInfoInET();
12
- const now = new Date();
13
- const expectedTimestamp = now.getTime();
14
- const expectedYear = now.getFullYear();
15
- const expectedMonth = now.getMonth() + 1;
16
- const expectedDay = now.getDate();
17
- const expectedHour = now.getHours();
18
- const expectedHour12 = expectedHour % 12 || 12;
19
- const expectedMinute = now.getMinutes();
20
- const expectedIsPM = expectedHour >= 12;
21
- expect(result.timestamp).toBeCloseTo(expectedTimestamp, -2);
22
- expect(result.year).toEqual(expectedYear);
23
- expect(result.month).toEqual(expectedMonth);
24
- expect(result.day).toEqual(expectedDay);
25
- expect(result.hour).toEqual(expectedHour);
26
- expect(result.hour12).toEqual(expectedHour12);
27
- expect(result.minute).toEqual(expectedMinute);
28
- expect(result.isPM).toEqual(expectedIsPM);
29
- });
30
-
31
- it('should return the time info in ET for a specified date', () => {
32
- const date = new Date('2022-01-01T00:00:00Z');
33
- const result = getTimeInfoInET(date);
34
- const expectedTimestamp = date.getTime();
35
- const expectedYear = 2021;
36
- const expectedMonth = 12;
37
- const expectedDay = 31;
38
- const expectedHour = 19;
39
- const expectedHour12 = 7;
40
- const expectedMinute = 0;
41
- const expectedIsPM = false;
42
- expect(result.timestamp).toEqual(expectedTimestamp);
43
- expect(result.year).toEqual(expectedYear);
44
- expect(result.month).toEqual(expectedMonth);
45
- expect(result.day).toEqual(expectedDay);
46
- expect(result.hour).toEqual(expectedHour);
47
- expect(result.hour12).toEqual(expectedHour12);
48
- expect(result.minute).toEqual(expectedMinute);
49
- expect(result.isPM).toEqual(expectedIsPM);
50
- });
51
-
52
- it('should return the time info in ET for a specified timestamp', () => {
53
- const timestamp = 1640995200000; // 2022-01-01T00:00:00Z
54
- const result = getTimeInfoInET(timestamp);
55
- const expectedTimestamp = timestamp;
56
- const expectedYear = 2021;
57
- const expectedMonth = 12;
58
- const expectedDay = 31;
59
- const expectedHour = 19;
60
- const expectedHour12 = 7;
61
- const expectedMinute = 0;
62
- const expectedIsPM = false;
63
- expect(result.timestamp).toEqual(expectedTimestamp);
64
- expect(result.year).toEqual(expectedYear);
65
- expect(result.month).toEqual(expectedMonth);
66
- expect(result.day).toEqual(expectedDay);
67
- expect(result.hour).toEqual(expectedHour);
68
- expect(result.hour12).toEqual(expectedHour12);
69
- expect(result.minute).toEqual(expectedMinute);
70
- expect(result.isPM).toEqual(expectedIsPM);
71
- });
72
- });
@@ -1,18 +0,0 @@
1
- /*------------------------------------------------------------------------*/
2
- /* ------------------------------ Constants ----------------------------- */
3
- /*------------------------------------------------------------------------*/
4
-
5
- export const INVALID_REGEX_ERROR = 'input does not follow the requested format';
6
- export const INVALID_EMAIL_ERROR = 'Please provide a valid email address.';
7
- export const INVALID_PHONE_ERROR = 'Please provide a valid phone number.';
8
- export const INVALID_STRING_ERRORS = {
9
- MIN_LEN: (minLen: number) => {
10
- return `input must not be under ${minLen} character(s)`;
11
- },
12
- MAX_LEN: (maxLen: number) => {
13
- return `input must not be over ${maxLen} character(s)`;
14
- },
15
- LETTERS_ONLY: 'input must only contain letters',
16
- NUMBERS_ONLY: 'input must only contain numbers',
17
- MESSAGE_INTRO: 'The following error(s) occurred: ',
18
- };
@@ -1,47 +0,0 @@
1
- // Import types
2
- import ValidationResult from '../types/ValidationResult';
3
-
4
- // Import constants
5
- import { INVALID_REGEX_ERROR } from '../constants/ERROR_MESSAGES';
6
-
7
- /**
8
- * Determines whether a given input string is considered valid based on
9
- * the provided regex.
10
- * @author Austen Money
11
- * @param opts object containing all args
12
- * @param opts.input user-provided input to validate
13
- * @param opts.regex regular expression to check against input
14
- * @param [opts.regexDescription] description of what regexString is checking
15
- * for, used to customize error message
16
- * @returns the unchanged input if valid, or a customized error message if
17
- * invalid
18
- */
19
- const validateRegex = (
20
- opts: {
21
- input: string,
22
- regex: RegExp,
23
- regexDescription?: string,
24
- },
25
- ): ValidationResult<string> => {
26
- // customize error message in case of invalid input
27
- const errorMessage = `${INVALID_REGEX_ERROR}${
28
- opts.regexDescription
29
- ? ': '
30
- : ''
31
- }${opts.regexDescription}`;
32
-
33
- // return error message if test is invalid, or input string if valid
34
- return (
35
- opts.regex.test(opts.input)
36
- ? {
37
- isValid: true,
38
- cleanedValue: opts.input,
39
- }
40
- : {
41
- isValid: false,
42
- errorMessage,
43
- }
44
- );
45
- };
46
-
47
- export default validateRegex;
@@ -1,20 +0,0 @@
1
- /**
2
- * Result of a validation function.
3
- * @author Austen Money
4
- */
5
- type ValidationResult<CleanedValueType> = (
6
- | {
7
- // if true, the validation was successful
8
- isValid: true,
9
- // the cleaned version of the value
10
- cleanedValue: CleanedValueType,
11
- }
12
- | {
13
- // if false, the validation was not successful
14
- isValid: false,
15
- // describes why the validation failed
16
- errorMessage: string,
17
- }
18
- );
19
-
20
- export default ValidationResult;
@@ -1,110 +0,0 @@
1
- // Import types
2
- import ValidationResult from './shared/types/ValidationResult';
3
-
4
- // Import constants
5
- import { INVALID_EMAIL_ERROR } from './shared/constants/ERROR_MESSAGES';
6
-
7
- // Import function
8
- import validateEmail from './validateEmail';
9
-
10
- /*------------------------------------------------------------------------*/
11
- /* ---------------------------- Valid Tests --------------------------- */
12
- /*------------------------------------------------------------------------*/
13
-
14
- const validEmailPairs: { input: string, cleaned: string }[] = [
15
- {
16
- input: 'username@gmail.com',
17
- cleaned: 'username@gmail.com',
18
- },
19
- {
20
- input: 'u@hotmail.org',
21
- cleaned: 'u@hotmail.org',
22
- },
23
- {
24
- input: ' username@gmail.com',
25
- cleaned: 'username@gmail.com',
26
- },
27
- {
28
- input: 'username@gmail.com ',
29
- cleaned: 'username@gmail.com',
30
- },
31
- {
32
- input: ' username@gmail.com ',
33
- cleaned: 'username@gmail.com',
34
- },
35
- {
36
- input: 'username@harvard.edu',
37
- cleaned: 'username@harvard.edu',
38
- },
39
- {
40
- input: 'username@harvard.subdomain.edu',
41
- cleaned: 'username@harvard.subdomain.edu',
42
- },
43
- {
44
- input: '\nusername@harvard.subdomain.edu',
45
- cleaned: 'username@harvard.subdomain.edu',
46
- },
47
- {
48
- input: '\n\tusername@harvard.subdomain.edu',
49
- cleaned: 'username@harvard.subdomain.edu',
50
- },
51
- {
52
- input: 'username@harvard.subdomain.edu\n',
53
- cleaned: 'username@harvard.subdomain.edu',
54
- },
55
- {
56
- input: 'username@harvard.subdomain.edu\n\t',
57
- cleaned: 'username@harvard.subdomain.edu',
58
- },
59
- ];
60
-
61
- test(
62
- 'Returns true for a given valid email and removes any leading or trailing whitespace.',
63
- async () => {
64
- validEmailPairs.forEach((pair) => {
65
- const validResponse: ValidationResult<string> = {
66
- isValid: true,
67
- cleanedValue: pair.cleaned,
68
- };
69
-
70
- expect(validateEmail(pair.input)).toStrictEqual(validResponse);
71
- });
72
- },
73
- );
74
-
75
- /*------------------------------------------------------------------------*/
76
- /* ---------------------------- Invalid Tests --------------------------- */
77
- /*------------------------------------------------------------------------*/
78
-
79
- const invalidEmails: string[] = [
80
- '',
81
- ' ',
82
- 'gmail.com',
83
- '@gmail.com ',
84
- 'username',
85
- 'username@.com',
86
- 'user name@gmail.com',
87
- 'username @gmail.com',
88
- 'username@ gmail.com',
89
- 'username@gmail .com',
90
- 'username\t@gmail.com',
91
- 'username\n@gmail.com',
92
- 'username@gmail\n.com',
93
- 'username@gmail.\tcom',
94
- 'user\nname@gmail.com',
95
- 'user\tname@gmail.com',
96
- ];
97
-
98
- const invalidResponse: ValidationResult<string> = {
99
- isValid: false,
100
- errorMessage: INVALID_EMAIL_ERROR,
101
- };
102
-
103
- test(
104
- 'Returns false for a given invalid email.',
105
- async () => {
106
- invalidEmails.forEach((email) => {
107
- expect(validateEmail(email)).toStrictEqual(invalidResponse);
108
- });
109
- },
110
- );
@@ -1,47 +0,0 @@
1
- // Import helpers
2
- import validateRegex from './shared/helpers/validateRegex';
3
-
4
- // Import constants
5
- import { INVALID_EMAIL_ERROR } from './shared/constants/ERROR_MESSAGES';
6
-
7
- // Import types
8
- import ValidationResult from './shared/types/ValidationResult';
9
-
10
- /**
11
- * Determines whether a given email address is valid.
12
- * @author Austen Money
13
- * @param email email address to validate
14
- * @returns whether email fulfills proper formatting requirements, includes a
15
- * cleaned version of the address without leading or trailing
16
- * whitespace if valid or an error message if invalid.
17
- */
18
- const validateEmail = (
19
- email: string,
20
- ): ValidationResult<string> => {
21
- // validation regex, sourced from HTML living standard: http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#e-mail-state-(type=email)
22
- // eslint-disable-next-line max-len
23
- const emailRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
24
-
25
- // remove leading and trailing whitespace
26
- const cleanedValue: string = email.replace(/^\s+|\s+$/g, '');
27
-
28
- // validate email with regex, and return error if not valid
29
- return (
30
- validateRegex(
31
- {
32
- input: cleanedValue,
33
- regex: emailRegex,
34
- },
35
- ).isValid
36
- ? {
37
- isValid: true,
38
- cleanedValue,
39
- }
40
- : {
41
- isValid: false,
42
- errorMessage: INVALID_EMAIL_ERROR,
43
- }
44
- );
45
- };
46
-
47
- export default validateEmail;