dce-reactkit 3.5.1-beta.1 → 3.5.3

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 (191) hide show
  1. package/.eslintrc.js +0 -2
  2. package/dist/cjs/index.js +320 -27
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/types/client/initClient.d.ts +1 -1
  5. package/dist/cjs/types/components/AppWrapper.d.ts +6 -6
  6. package/dist/cjs/types/components/ButtonInputGroup.d.ts +1 -1
  7. package/dist/cjs/types/components/CSVDownloadButton.d.ts +1 -1
  8. package/dist/cjs/types/components/CheckboxButton.d.ts +1 -1
  9. package/dist/cjs/types/components/CopiableBox.d.ts +1 -1
  10. package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +7 -1
  11. package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +5 -4
  12. package/dist/cjs/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +1 -1
  13. package/dist/cjs/types/components/DBEntryManagerPanel/index.d.ts +13 -2
  14. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +1 -1
  15. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +1 -1
  16. package/dist/cjs/types/components/Drawer.d.ts +1 -1
  17. package/dist/cjs/types/components/ErrorBox.d.ts +1 -1
  18. package/dist/cjs/types/components/IntelliTable.d.ts +1 -1
  19. package/dist/cjs/types/components/ItemPicker/NestableItemList.d.ts +1 -1
  20. package/dist/cjs/types/components/ItemPicker/index.d.ts +1 -1
  21. package/dist/cjs/types/components/ItemPicker/types/PickableItem.d.ts +1 -1
  22. package/dist/cjs/types/components/LogReviewer.d.ts +1 -1
  23. package/dist/cjs/types/components/Modal.d.ts +1 -1
  24. package/dist/cjs/types/components/PopFailureMark.d.ts +1 -1
  25. package/dist/cjs/types/components/PopPendingMark.d.ts +1 -1
  26. package/dist/cjs/types/components/PopSuccessMark.d.ts +1 -1
  27. package/dist/cjs/types/components/RadioButton.d.ts +1 -1
  28. package/dist/cjs/types/components/SimpleDateChooser.d.ts +1 -1
  29. package/dist/cjs/types/components/TabBox.d.ts +1 -1
  30. package/dist/cjs/types/helpers/abbreviate.test.d.ts +5 -0
  31. package/dist/cjs/types/helpers/addDBEditorEndpoints.d.ts +4 -3
  32. package/dist/cjs/types/helpers/avg.test.d.ts +5 -0
  33. package/dist/cjs/types/helpers/canReviewLogs.d.ts +5 -0
  34. package/dist/cjs/types/helpers/canReviewLogs.test.d.ts +5 -0
  35. package/dist/cjs/types/helpers/ceilToNumDecimals.test.d.ts +5 -0
  36. package/dist/cjs/types/helpers/compareArraysByProp.d.ts +3 -2
  37. package/dist/cjs/types/helpers/compareArraysByProp.test.d.ts +5 -0
  38. package/dist/cjs/types/helpers/extractProp.test.d.ts +5 -0
  39. package/dist/cjs/types/helpers/floorToNumDecimals.test.d.ts +5 -0
  40. package/dist/cjs/types/helpers/forceNumIntoBounds.test.d.ts +5 -0
  41. package/dist/cjs/types/helpers/genCSV.test.d.ts +5 -0
  42. package/dist/cjs/types/helpers/genCommaList.d.ts +12 -0
  43. package/dist/cjs/types/helpers/genCommaList.test.d.ts +1 -0
  44. package/dist/cjs/types/helpers/genRouteHandler.d.ts +7 -7
  45. package/dist/cjs/types/helpers/getHumanReadableDate.d.ts +1 -1
  46. package/dist/cjs/types/helpers/getHumanReadableDate.test.d.ts +5 -0
  47. package/dist/cjs/types/helpers/getLocalTimeInfo.d.ts +1 -1
  48. package/dist/cjs/types/helpers/getLocalTimeInfo.test.d.ts +6 -0
  49. package/dist/cjs/types/helpers/getMonthName.test.d.ts +5 -0
  50. package/dist/cjs/types/helpers/getOrdinal.test.d.ts +5 -0
  51. package/dist/cjs/types/helpers/getPartOfDay.test.d.ts +5 -0
  52. package/dist/cjs/types/helpers/getTimeInfoInET.d.ts +1 -1
  53. package/dist/cjs/types/helpers/getTimeInfoInET.test.d.ts +5 -0
  54. package/dist/cjs/types/helpers/parallelLimit.d.ts +1 -1
  55. package/dist/cjs/types/helpers/validators/shared/constants/ERROR_MESSAGES.d.ts +10 -0
  56. package/dist/cjs/types/helpers/validators/shared/helpers/validateRegex.d.ts +19 -0
  57. package/dist/cjs/types/helpers/validators/shared/types/ValidationResult.d.ts +12 -0
  58. package/dist/cjs/types/helpers/validators/validateEmail.d.ts +11 -0
  59. package/dist/cjs/types/helpers/validators/validateEmail.test.d.ts +1 -0
  60. package/dist/cjs/types/helpers/validators/validatePhoneNumber.d.ts +11 -0
  61. package/dist/cjs/types/helpers/validators/validatePhoneNumber.test.d.ts +1 -0
  62. package/dist/cjs/types/helpers/validators/validateString.d.ts +22 -0
  63. package/dist/cjs/types/helpers/validators/validateString.test.d.ts +1 -0
  64. package/dist/cjs/types/index.d.ts +5 -1
  65. package/dist/cjs/types/server/initServer.d.ts +1 -1
  66. package/dist/cjs/types/types/IntelliTableColumn.d.ts +1 -1
  67. package/dist/cjs/types/types/Log/LogMainInfo.d.ts +1 -1
  68. package/dist/cjs/types/types/Log/LogSourceSpecificInfo.d.ts +1 -1
  69. package/dist/cjs/types/types/Log/LogTypeSpecificInfo.d.ts +1 -1
  70. package/dist/cjs/types/types/Log/index.d.ts +1 -1
  71. package/dist/cjs/types/types/LogFunction.d.ts +1 -1
  72. package/dist/cjs/types/types/LogMetadataContextMap.d.ts +1 -1
  73. package/dist/cjs/types/types/LogMetadataTagMap.d.ts +1 -1
  74. package/dist/cjs/types/types/LogMetadataTargetMap.d.ts +1 -1
  75. package/dist/cjs/types/types/LogMetadataType.d.ts +1 -1
  76. package/dist/esm/index.js +317 -28
  77. package/dist/esm/index.js.map +1 -1
  78. package/dist/esm/types/client/initClient.d.ts +1 -1
  79. package/dist/esm/types/components/AppWrapper.d.ts +6 -6
  80. package/dist/esm/types/components/ButtonInputGroup.d.ts +1 -1
  81. package/dist/esm/types/components/CSVDownloadButton.d.ts +1 -1
  82. package/dist/esm/types/components/CheckboxButton.d.ts +1 -1
  83. package/dist/esm/types/components/CopiableBox.d.ts +1 -1
  84. package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +7 -1
  85. package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +5 -4
  86. package/dist/esm/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +1 -1
  87. package/dist/esm/types/components/DBEntryManagerPanel/index.d.ts +13 -2
  88. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +1 -1
  89. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +1 -1
  90. package/dist/esm/types/components/Drawer.d.ts +1 -1
  91. package/dist/esm/types/components/ErrorBox.d.ts +1 -1
  92. package/dist/esm/types/components/IntelliTable.d.ts +1 -1
  93. package/dist/esm/types/components/ItemPicker/NestableItemList.d.ts +1 -1
  94. package/dist/esm/types/components/ItemPicker/index.d.ts +1 -1
  95. package/dist/esm/types/components/ItemPicker/types/PickableItem.d.ts +1 -1
  96. package/dist/esm/types/components/LogReviewer.d.ts +1 -1
  97. package/dist/esm/types/components/Modal.d.ts +1 -1
  98. package/dist/esm/types/components/PopFailureMark.d.ts +1 -1
  99. package/dist/esm/types/components/PopPendingMark.d.ts +1 -1
  100. package/dist/esm/types/components/PopSuccessMark.d.ts +1 -1
  101. package/dist/esm/types/components/RadioButton.d.ts +1 -1
  102. package/dist/esm/types/components/SimpleDateChooser.d.ts +1 -1
  103. package/dist/esm/types/components/TabBox.d.ts +1 -1
  104. package/dist/esm/types/helpers/abbreviate.test.d.ts +5 -0
  105. package/dist/esm/types/helpers/addDBEditorEndpoints.d.ts +4 -3
  106. package/dist/esm/types/helpers/avg.test.d.ts +5 -0
  107. package/dist/esm/types/helpers/canReviewLogs.d.ts +5 -0
  108. package/dist/esm/types/helpers/canReviewLogs.test.d.ts +5 -0
  109. package/dist/esm/types/helpers/ceilToNumDecimals.test.d.ts +5 -0
  110. package/dist/esm/types/helpers/compareArraysByProp.d.ts +3 -2
  111. package/dist/esm/types/helpers/compareArraysByProp.test.d.ts +5 -0
  112. package/dist/esm/types/helpers/extractProp.test.d.ts +5 -0
  113. package/dist/esm/types/helpers/floorToNumDecimals.test.d.ts +5 -0
  114. package/dist/esm/types/helpers/forceNumIntoBounds.test.d.ts +5 -0
  115. package/dist/esm/types/helpers/genCSV.test.d.ts +5 -0
  116. package/dist/esm/types/helpers/genCommaList.d.ts +12 -0
  117. package/dist/esm/types/helpers/genCommaList.test.d.ts +1 -0
  118. package/dist/esm/types/helpers/genRouteHandler.d.ts +7 -7
  119. package/dist/esm/types/helpers/getHumanReadableDate.d.ts +1 -1
  120. package/dist/esm/types/helpers/getHumanReadableDate.test.d.ts +5 -0
  121. package/dist/esm/types/helpers/getLocalTimeInfo.d.ts +1 -1
  122. package/dist/esm/types/helpers/getLocalTimeInfo.test.d.ts +6 -0
  123. package/dist/esm/types/helpers/getMonthName.test.d.ts +5 -0
  124. package/dist/esm/types/helpers/getOrdinal.test.d.ts +5 -0
  125. package/dist/esm/types/helpers/getPartOfDay.test.d.ts +5 -0
  126. package/dist/esm/types/helpers/getTimeInfoInET.d.ts +1 -1
  127. package/dist/esm/types/helpers/getTimeInfoInET.test.d.ts +5 -0
  128. package/dist/esm/types/helpers/parallelLimit.d.ts +1 -1
  129. package/dist/esm/types/helpers/validators/shared/constants/ERROR_MESSAGES.d.ts +10 -0
  130. package/dist/esm/types/helpers/validators/shared/helpers/validateRegex.d.ts +19 -0
  131. package/dist/esm/types/helpers/validators/shared/types/ValidationResult.d.ts +12 -0
  132. package/dist/esm/types/helpers/validators/validateEmail.d.ts +11 -0
  133. package/dist/esm/types/helpers/validators/validateEmail.test.d.ts +1 -0
  134. package/dist/esm/types/helpers/validators/validatePhoneNumber.d.ts +11 -0
  135. package/dist/esm/types/helpers/validators/validatePhoneNumber.test.d.ts +1 -0
  136. package/dist/esm/types/helpers/validators/validateString.d.ts +22 -0
  137. package/dist/esm/types/helpers/validators/validateString.test.d.ts +1 -0
  138. package/dist/esm/types/index.d.ts +5 -1
  139. package/dist/esm/types/server/initServer.d.ts +1 -1
  140. package/dist/esm/types/types/IntelliTableColumn.d.ts +1 -1
  141. package/dist/esm/types/types/Log/LogMainInfo.d.ts +1 -1
  142. package/dist/esm/types/types/Log/LogSourceSpecificInfo.d.ts +1 -1
  143. package/dist/esm/types/types/Log/LogTypeSpecificInfo.d.ts +1 -1
  144. package/dist/esm/types/types/Log/index.d.ts +1 -1
  145. package/dist/esm/types/types/LogFunction.d.ts +1 -1
  146. package/dist/esm/types/types/LogMetadataContextMap.d.ts +1 -1
  147. package/dist/esm/types/types/LogMetadataTagMap.d.ts +1 -1
  148. package/dist/esm/types/types/LogMetadataTargetMap.d.ts +1 -1
  149. package/dist/esm/types/types/LogMetadataType.d.ts +1 -1
  150. package/dist/index.d.ts +134 -56
  151. package/package.json +14 -13
  152. package/src/components/ItemPicker/index.test.tsx +10 -10
  153. package/src/helpers/abbreviate.test.ts +26 -0
  154. package/src/helpers/avg.test.ts +24 -0
  155. package/src/helpers/canReviewLogs.test.ts +67 -0
  156. package/src/helpers/canReviewLogs.ts +20 -0
  157. package/src/helpers/ceilToNumDecimals.test.ts +39 -0
  158. package/src/helpers/compareArraysByProp.test.ts +147 -0
  159. package/src/helpers/compareArraysByProp.ts +41 -22
  160. package/src/helpers/extractProp.test.ts +34 -0
  161. package/src/helpers/floorToNumDecimals.test.ts +39 -0
  162. package/src/helpers/forceNumIntoBounds.test.ts +34 -0
  163. package/src/helpers/genCSV.test.ts +61 -0
  164. package/src/helpers/genCSV.ts +5 -2
  165. package/src/helpers/genCommaList.test.ts +57 -0
  166. package/src/helpers/genCommaList.ts +21 -0
  167. package/src/helpers/getHumanReadableDate.test.ts +29 -0
  168. package/src/helpers/getLocalTimeInfo.test.ts +48 -0
  169. package/src/helpers/getMonthName.test.ts +79 -0
  170. package/src/helpers/getOrdinal.test.ts +84 -0
  171. package/src/helpers/{getOrdinal.tsx → getOrdinal.ts} +1 -0
  172. package/src/helpers/getPartOfDay.test.ts +56 -0
  173. package/src/helpers/getTimeInfoInET.test.ts +72 -0
  174. package/src/helpers/validators/shared/constants/ERROR_MESSAGES.ts +18 -0
  175. package/src/helpers/validators/shared/helpers/validateRegex.ts +47 -0
  176. package/src/helpers/validators/shared/types/ValidationResult.ts +20 -0
  177. package/src/helpers/validators/validateEmail.test.ts +110 -0
  178. package/src/helpers/validators/validateEmail.ts +47 -0
  179. package/src/helpers/validators/validatePhoneNumber.test.ts +94 -0
  180. package/src/helpers/validators/validatePhoneNumber.ts +49 -0
  181. package/src/helpers/validators/validateString.test.ts +173 -0
  182. package/src/helpers/validators/validateString.ts +171 -0
  183. package/src/index.ts +8 -0
  184. package/tsconfig.json +6 -2
  185. /package/src/helpers/{abbreviate.tsx → abbreviate.ts} +0 -0
  186. /package/src/helpers/{avg.tsx → avg.ts} +0 -0
  187. /package/src/helpers/{ceilToNumDecimals.tsx → ceilToNumDecimals.ts} +0 -0
  188. /package/src/helpers/{floorToNumDecimals.tsx → floorToNumDecimals.ts} +0 -0
  189. /package/src/helpers/{forceNumIntoBounds.tsx → forceNumIntoBounds.ts} +0 -0
  190. /package/src/helpers/{getLocalTimeInfo.tsx → getLocalTimeInfo.ts} +0 -0
  191. /package/src/helpers/{getTimeInfoInET.tsx → getTimeInfoInET.ts} +0 -0
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Test file for the genCSV helper
3
+ * @author Gabe Abrams
4
+ */
5
+
6
+ // Import main helper
7
+ import genCSV from './genCSV';
8
+
9
+ describe('genCSV', () => {
10
+ it('should return an empty string for empty data', () => {
11
+ const result = genCSV([], []);
12
+ expect(result).toEqual('');
13
+ });
14
+
15
+ it('should generate a CSV with the correct headers and data', () => {
16
+ const columns = [
17
+ { title: 'Name', param: 'name' },
18
+ { title: 'Age', param: 'age' },
19
+ { title: 'Email', param: 'email' },
20
+ ];
21
+ const data = [
22
+ { name: 'Alice', age: 25, email: 'alice@example.com' },
23
+ { name: 'Bob', age: 30, email: 'bob@example.com' },
24
+ { name: 'Charlie', age: 35, email: 'charlie@example.com' },
25
+ ];
26
+ const expected = `Name,Age,Email\nAlice,25,alice@example.com\nBob,30,bob@example.com\nCharlie,35,charlie@example.com`;
27
+ const result = genCSV(data, columns);
28
+ expect(result).toEqual(expected);
29
+ });
30
+
31
+ it('should handle undefined and null values correctly', () => {
32
+ const columns = [
33
+ { title: 'Name', param: 'name' },
34
+ { title: 'Age', param: 'age' },
35
+ { title: 'Email', param: 'email' },
36
+ ];
37
+ const data = [
38
+ { name: 'Alice', age: undefined, email: null },
39
+ { name: 'Bob', age: null, email: 'bob@example.com' },
40
+ { name: 'Charlie', age: 35, email: undefined },
41
+ ];
42
+ const expected = `Name,Age,Email\nAlice,,\nBob,,bob@example.com\nCharlie,35,`;
43
+ const result = genCSV(data, columns);
44
+ expect(result).toEqual(expected);
45
+ });
46
+
47
+ it('should handle objects in cells correctly', () => {
48
+ const columns = [
49
+ { title: 'Name', param: 'name' },
50
+ { title: 'Data', param: 'data' },
51
+ ];
52
+ const data = [
53
+ { name: 'Alice', data: { foo: 'bar' } },
54
+ { name: 'Bob', data: [1, 2, 3] },
55
+ { name: 'Charlie', data: null },
56
+ ];
57
+ const expected = `Name,Data\nAlice,"{""foo"":""bar""}"\nBob,"[1,2,3]"\nCharlie,`;
58
+ const result = genCSV(data, columns);
59
+ expect(result).toEqual(expected);
60
+ });
61
+ });
@@ -5,13 +5,16 @@
5
5
  * @returns escaped cell text
6
6
  */
7
7
  const escapeCellText = (text: string): string => {
8
- if (!String(text).includes(',')) {
8
+ if (
9
+ !String(text).includes(',')
10
+ && !String(text).includes('"')
11
+ ) {
9
12
  // No need to escape
10
13
  return String(text);
11
14
  }
12
15
 
13
16
  // Perform escape
14
- return `"${String(text).replace(/"/g, '""')}`;
17
+ return `"${String(text).replace(/"/g, '""')}"`;
15
18
  };
16
19
 
17
20
  /**
@@ -0,0 +1,57 @@
1
+ // Import function
2
+ import genCommaList from './genCommaList';
3
+
4
+ test(
5
+ 'Empty list.',
6
+ async () => {
7
+ const emptyList: string[] = [];
8
+ const emptyListResponse: string = '';
9
+
10
+ const result = genCommaList(emptyList);
11
+ expect(result).toStrictEqual(emptyListResponse);
12
+ },
13
+ );
14
+
15
+ test(
16
+ 'One word list.',
17
+ async () => {
18
+ const oneList: string[] = ['apples'];
19
+ const oneListResponse: string = 'apples';
20
+
21
+ const result = genCommaList(oneList);
22
+ expect(result).toStrictEqual(oneListResponse);
23
+ },
24
+ );
25
+
26
+ test(
27
+ 'Two word list.',
28
+ async () => {
29
+ const twoList: string[] = ['apples', 'oranges'];
30
+ const twoListResponse: string = 'apples and oranges';
31
+
32
+ const result = genCommaList(twoList);
33
+ expect(result).toStrictEqual(twoListResponse);
34
+ },
35
+ );
36
+
37
+ test(
38
+ 'Three word list.',
39
+ async () => {
40
+ const threeList: string[] = ['apples', 'oranges', 'bananas'];
41
+ const threeListResponse: string = 'apples, oranges, and bananas';
42
+
43
+ const result = genCommaList(threeList);
44
+ expect(result).toStrictEqual(threeListResponse);
45
+ },
46
+ );
47
+
48
+ test(
49
+ 'Four word list.',
50
+ async () => {
51
+ const fourList: string[] = ['apples', 'oranges', 'bananas', 'grapes'];
52
+ const fourListResponse: string = 'apples, oranges, bananas, and grapes';
53
+
54
+ const result = genCommaList(fourList);
55
+ expect(result).toStrictEqual(fourListResponse);
56
+ },
57
+ );
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Given an array of strings, create a single comma-separated string that includes
3
+ * 'and' as well as an oxford comma.
4
+ * Ex: ['apples'] => 'apples'
5
+ * Ex: ['apples', 'bananas'] => 'apples and bananas'
6
+ * Ex: ['apples', 'bananas', 'grapes'] => 'apples, bananas, and grapes'
7
+ * @author Austen Money
8
+ * @param list an array of elements to be made into a single comma-separated string.
9
+ * @returns a comma-separated string.
10
+ */
11
+ const genCommaList = (list: string[]): string => {
12
+ const { length } = list;
13
+
14
+ return (
15
+ length < 2
16
+ ? list.join('')
17
+ : `${list.slice(0, length - 1).join(', ')}${length < 3 ? ' and ' : ', and '}${list[length - 1]}`
18
+ );
19
+ };
20
+
21
+ export default genCommaList;
@@ -0,0 +1,29 @@
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
+ });
@@ -0,0 +1,48 @@
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
+ });
@@ -0,0 +1,79 @@
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
+ });
@@ -0,0 +1,84 @@
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,3 +1,4 @@
1
+ // Constants
1
2
  const ORDINALS = ['th', 'st', 'nd', 'rd'];
2
3
 
3
4
  /**
@@ -0,0 +1,56 @@
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
+ });
@@ -0,0 +1,72 @@
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 = true;
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 = true;
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
+ });
@@ -0,0 +1,18 @@
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
+ };
@@ -0,0 +1,47 @@
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;
@@ -0,0 +1,20 @@
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;