fluency-v8-components 1.3.4 → 1.3.6

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 (179) hide show
  1. package/dist/fluency-v8-components.es.js +1 -1
  2. package/dist/fluency-v8-components.umd.js +31 -31
  3. package/dist/{index-Dxs_Gn5T.mjs → index-BBxccHNP.mjs} +53 -47
  4. package/dist/index.css +1 -1
  5. package/dist/{index.es-YeMpD96e.mjs → index.es-D_XhLSeH.mjs} +1 -1
  6. package/package.json +3 -2
  7. package/src/assets/images/ai.svg +1 -0
  8. package/src/assets/images/github-dark.svg +1 -0
  9. package/src/assets/images/github.svg +1 -0
  10. package/src/assets/images/high-priority.svg +1 -0
  11. package/src/assets/images/power-off.svg +1 -0
  12. package/src/assets/images/save.svg +1 -0
  13. package/src/assets/index.ts +15 -0
  14. package/src/assets/main.css +505 -0
  15. package/src/assets/prism-theme.css +290 -0
  16. package/src/components/buttons/ActionButtons.vue +374 -0
  17. package/src/components/buttons/DropdownButton.vue +104 -0
  18. package/src/components/buttons/IconButton.vue +63 -0
  19. package/src/components/buttons/ImageButton.vue +16 -0
  20. package/src/components/buttons/MenuButton.vue +138 -0
  21. package/src/components/buttons/SubmitButtons.vue +51 -0
  22. package/src/components/buttons/TextButton.vue +40 -0
  23. package/src/components/charts/AlertChart.vue +376 -0
  24. package/src/components/charts/BarChart.vue +212 -0
  25. package/src/components/charts/BarChartHorizontal.vue +243 -0
  26. package/src/components/charts/CronChart.vue +146 -0
  27. package/src/components/charts/EmptyChart.vue +76 -0
  28. package/src/components/charts/GradientChart.vue +310 -0
  29. package/src/components/charts/LineChart.test.js +59 -0
  30. package/src/components/charts/LineChart.vue +434 -0
  31. package/src/components/charts/PieChart.vue +293 -0
  32. package/src/components/charts/ProgressChart.vue +106 -0
  33. package/src/components/charts/StackedChart.vue +364 -0
  34. package/src/components/charts/StackedChartClustered.vue +395 -0
  35. package/src/components/charts/TimelineChart.vue +215 -0
  36. package/src/components/charts/WorkflowChart.vue +520 -0
  37. package/src/components/common/AutoCompleteSearchBar.vue +100 -0
  38. package/src/components/common/AutoRefreshButton.vue +53 -0
  39. package/src/components/common/Breadcrumb.vue +45 -0
  40. package/src/components/common/ButtonToggle.vue +24 -0
  41. package/src/components/common/Card.vue +116 -0
  42. package/src/components/common/Carousel.vue +66 -0
  43. package/src/components/common/CategoryCard.vue +28 -0
  44. package/src/components/common/CodeEditor.vue +59 -0
  45. package/src/components/common/DatePicker.vue +21 -0
  46. package/src/components/common/DatePickerInput.vue +109 -0
  47. package/src/components/common/Dialog.vue +103 -0
  48. package/src/components/common/EditorHeading.vue +10 -0
  49. package/src/components/common/EventList.vue +41 -0
  50. package/src/components/common/Facet.vue +206 -0
  51. package/src/components/common/Feed.vue +58 -0
  52. package/src/components/common/Flag.vue +27 -0
  53. package/src/components/common/HomeCard.vue +20 -0
  54. package/src/components/common/ItemBox.vue +49 -0
  55. package/src/components/common/Loading.vue +19 -0
  56. package/src/components/common/LoadingDots.vue +12 -0
  57. package/src/components/common/PageHeading.vue +30 -0
  58. package/src/components/common/Pagination.vue +105 -0
  59. package/src/components/common/Popover.vue +24 -0
  60. package/src/components/common/PowerToggle.vue +130 -0
  61. package/src/components/common/ProgressBar.vue +33 -0
  62. package/src/components/common/RadioButtons.vue +52 -0
  63. package/src/components/common/Schedule.vue +79 -0
  64. package/src/components/common/SearchBar.vue +30 -0
  65. package/src/components/common/Separator.vue +3 -0
  66. package/src/components/common/Slideout.vue +95 -0
  67. package/src/components/common/Sort.vue +83 -0
  68. package/src/components/common/Table.vue +48 -0
  69. package/src/components/common/Tabs.vue +129 -0
  70. package/src/components/common/Tag.vue +53 -0
  71. package/src/components/common/Tooltip.vue +49 -0
  72. package/src/components/common/VerticalTabs.vue +34 -0
  73. package/src/components/common/card/CardItem.vue +27 -0
  74. package/src/components/common/card/CardItemGroup.vue +45 -0
  75. package/src/components/common/facet/Leaf.vue +97 -0
  76. package/src/components/common/facet/TriState.vue +37 -0
  77. package/src/components/common/table/TableData.vue +48 -0
  78. package/src/components/common/table/TableHeader.vue +21 -0
  79. package/src/components/dialogs/ChooseValueDialog.vue +97 -0
  80. package/src/components/dialogs/ConfirmDialog.vue +73 -0
  81. package/src/components/dialogs/CopyDialog.vue +51 -0
  82. package/src/components/dialogs/DownloadDialog.vue +48 -0
  83. package/src/components/dialogs/NameDescDialog.vue +74 -0
  84. package/src/components/dialogs/NameDialog.vue +56 -0
  85. package/src/components/dialogs/PopupEditor.vue +113 -0
  86. package/src/components/dialogs/ProgressDialog.vue +58 -0
  87. package/src/components/dialogs/ResetPasswordDialog.vue +58 -0
  88. package/src/components/dialogs/Wizard.vue +99 -0
  89. package/src/components/dialogs/wizard/Stepper.vue +31 -0
  90. package/src/components/form/CheckBox.vue +26 -0
  91. package/src/components/form/Editor.vue +93 -0
  92. package/src/components/form/FormCol.vue +19 -0
  93. package/src/components/form/FormRow.vue +19 -0
  94. package/src/components/form/FormSection.vue +21 -0
  95. package/src/components/form/GreyForm.vue +7 -0
  96. package/src/components/form/GreyInput.vue +51 -0
  97. package/src/components/form/GreyInputAutocomplete.vue +100 -0
  98. package/src/components/form/GreyInputCopy.vue +66 -0
  99. package/src/components/form/GreyInputGrow.vue +42 -0
  100. package/src/components/form/GreyInputToken.vue +78 -0
  101. package/src/components/form/GreyPassword.vue +36 -0
  102. package/src/components/form/GreySelect.vue +154 -0
  103. package/src/components/form/GreySelectInput.vue +123 -0
  104. package/src/components/form/GreySelectInputMultiple.vue +218 -0
  105. package/src/components/form/GreyTel.vue +58 -0
  106. package/src/components/form/HamburgerItem.vue +95 -0
  107. package/src/components/form/KeyValueEntry.vue +74 -0
  108. package/src/components/form/RadioInput.vue +38 -0
  109. package/src/components/form/UploadFile.vue +99 -0
  110. package/src/components/icons/AiIcon.vue +6 -0
  111. package/src/components/icons/GithubIcon.vue +18 -0
  112. package/src/components/icons/HighPriorityIcon.vue +6 -0
  113. package/src/components/icons/PowerOffIcon.vue +6 -0
  114. package/src/components/icons/SaveIcon.vue +6 -0
  115. package/src/components/index.js +134 -0
  116. package/src/components/menu/DialogMenu.vue +142 -0
  117. package/src/components/menu/GrandChild.vue +39 -0
  118. package/src/components/menu/GridMenu.vue +88 -0
  119. package/src/components/menu/MenuAvatar.vue +66 -0
  120. package/src/components/menu/MenuDesktop.vue +90 -0
  121. package/src/components/notifications/Notify.vue +123 -0
  122. package/src/components/notifications/NotifyList.vue +130 -0
  123. package/src/components/page-structure/FacetPage.vue +77 -0
  124. package/src/components/query/Child.vue +63 -0
  125. package/src/components/query/LVDBQuery.vue +38 -0
  126. package/src/components/status/Active.vue +44 -0
  127. package/src/components/status/ScoreLevel.vue +43 -0
  128. package/src/components/status/Status.vue +51 -0
  129. package/src/components/status/TaskDot.vue +25 -0
  130. package/src/components/status/TaskStatus.vue +26 -0
  131. package/src/components/status/TicketStatus.vue +201 -0
  132. package/src/components/status/Trend.vue +20 -0
  133. package/src/components/tables/ArgumentRunTable.vue +96 -0
  134. package/src/components/tables/ArgumentTable.vue +67 -0
  135. package/src/components/tables/CloudFormationParameters.vue +25 -0
  136. package/src/constants/colors.js +248 -0
  137. package/src/constants/font-map.js +128 -0
  138. package/src/constants/fpl2.js +162 -0
  139. package/src/constants/icon-svg.js +405 -0
  140. package/src/constants/schedule.js +52 -0
  141. package/src/fpl/AddPanel.vue +237 -0
  142. package/src/fpl/Configs/Alert.vue +16 -0
  143. package/src/fpl/Configs/AlertSprite.vue +2 -0
  144. package/src/fpl/Configs/Chart.vue +63 -0
  145. package/src/fpl/Configs/Config.js +154 -0
  146. package/src/fpl/Configs/Counter.vue +35 -0
  147. package/src/fpl/Configs/Histogram.vue +70 -0
  148. package/src/fpl/Configs/IPMap.vue +37 -0
  149. package/src/fpl/Configs/Image.vue +163 -0
  150. package/src/fpl/Configs/MetricChart.vue +20 -0
  151. package/src/fpl/Configs/PieChart.vue +37 -0
  152. package/src/fpl/Configs/SparkChart.vue +41 -0
  153. package/src/fpl/Configs/StackedBarChart.vue +49 -0
  154. package/src/fpl/Configs/Table.vue +211 -0
  155. package/src/fpl/Configs/Text.vue +14 -0
  156. package/src/fpl/Configs/TopNChart.vue +37 -0
  157. package/src/fpl/Outputs/FPLAlert.vue +64 -0
  158. package/src/fpl/Outputs/FPLStream.vue +41 -0
  159. package/src/fpl/Outputs/FPLTable.vue +77 -0
  160. package/src/fpl/Panel.vue +202 -0
  161. package/src/fpl/Panels/Alert.vue +85 -0
  162. package/src/fpl/Panels/AlertSprite.vue +9 -0
  163. package/src/fpl/Panels/Chart.vue +98 -0
  164. package/src/fpl/Panels/Counter.vue +43 -0
  165. package/src/fpl/Panels/Histogram.vue +138 -0
  166. package/src/fpl/Panels/IPMap.vue +48 -0
  167. package/src/fpl/Panels/Image.vue +35 -0
  168. package/src/fpl/Panels/MetricChart.vue +97 -0
  169. package/src/fpl/Panels/PieChart.vue +54 -0
  170. package/src/fpl/Panels/SparkChart.vue +166 -0
  171. package/src/fpl/Panels/StackedBarChart.vue +74 -0
  172. package/src/fpl/Panels/Table.vue +103 -0
  173. package/src/fpl/Panels/Text.vue +24 -0
  174. package/src/fpl/Panels/TopNChart.vue +69 -0
  175. package/src/fpl/index.js +39 -0
  176. package/src/utils/download.js +220 -0
  177. package/src/utils/formatOutput.js +156 -0
  178. package/src/utils/random.js +32 -0
  179. package/src/utils/timeUtils.js +138 -0
@@ -0,0 +1,220 @@
1
+ import JSZip from "jszip";
2
+ import FileSaver from "file-saver";
3
+ import html2canvas from "html2canvas";
4
+ import { jsPDF as JSpdf } from "jspdf";
5
+
6
+ const saveFile = (data, filename) => {
7
+ const blob = new Blob([data], { type: "text/plain" });
8
+ const event = document.createEvent("MouseEvents");
9
+ const link = document.createElement("a");
10
+ link.download = filename;
11
+ link.href = window.URL.createObjectURL(blob);
12
+ link.dataset.downloadurl = ["text/csv", link.download, link.href].join(":");
13
+ event.initEvent(
14
+ "click",
15
+ true,
16
+ false,
17
+ window,
18
+ 0,
19
+ 0,
20
+ 0,
21
+ 0,
22
+ 0,
23
+ false,
24
+ false,
25
+ false,
26
+ false,
27
+ 0,
28
+ null
29
+ );
30
+ link.dispatchEvent(event);
31
+ };
32
+
33
+ const exportPanelAsCsv = (columns, rows) => {
34
+ let csv = columns.map((col) => col.header).join(",") + "\n";
35
+ const order = {};
36
+ columns.forEach((col, index) => {
37
+ order[col.field] = index;
38
+ });
39
+ rows.forEach((row) => {
40
+ let r = "";
41
+ Object.keys(order).forEach((key) => {
42
+ let val = row[key];
43
+ if (typeof val === "undefined") {
44
+ val = "";
45
+ }
46
+ if (typeof val === "string") {
47
+ val = val.replace(", ", " ").replace(",", " ");
48
+ }
49
+ // add double quotes to csv export
50
+ r += '"' + val + '"' + ",";
51
+ });
52
+ csv += r.slice(0, -1) + "\n";
53
+ });
54
+ return csv;
55
+ };
56
+
57
+ const panelCSVDownload = (title, columns, rows) => {
58
+ const csv = exportPanelAsCsv(columns, rows);
59
+ const name = title || "data";
60
+ saveFile(csv, `${name}.csv`);
61
+ };
62
+
63
+ // needs to be in the format of columns and rows
64
+ const exportAsCsv = (table) => {
65
+ let csv =
66
+ table.columns
67
+ .map((col) => col.replaceAll(", ", " ").replaceAll(",", " "))
68
+ .join(",") + "\n";
69
+
70
+ const order = {};
71
+ table.columns.forEach((col, index) => {
72
+ order[col] = index;
73
+ });
74
+ table.rows.forEach((row) => {
75
+ let r = "";
76
+ Object.keys(order).forEach((key) => {
77
+ let val = row[key];
78
+ if (typeof val === "undefined") {
79
+ val = "";
80
+ }
81
+ if (typeof val === "string") {
82
+ val = val.replaceAll(", ", " ").replaceAll(",", " ");
83
+ }
84
+ // add double quotes to csv export
85
+ r += '"' + val + '"' + ",";
86
+ });
87
+ csv += r.slice(0, -1) + "\n";
88
+ });
89
+ return csv;
90
+ };
91
+
92
+ // accepts a table object with name, columns, and rows
93
+ const csvDownload = (table) => {
94
+ const csv = exportAsCsv(table);
95
+ const name = table.name || "data";
96
+ saveFile(csv, `${name}.csv`);
97
+ };
98
+
99
+ const csvDownloadZip = (tables, filename = "data") => {
100
+ if (tables.length === 0) {
101
+ return;
102
+ }
103
+
104
+ const zip = new JSZip();
105
+ tables.forEach((table, index) => {
106
+ const csv = exportAsCsv(table);
107
+ const name = table.name || `${filename}-${index}`;
108
+ zip.file(`${name}.csv`, csv);
109
+ });
110
+ zip.generateAsync({ type: "blob" }).then((content) => {
111
+ return FileSaver.saveAs(content, `${filename}.zip`);
112
+ });
113
+ };
114
+
115
+ const reportToPdf = async (name, layouts) => {
116
+ const pdf = new JSpdf("p", "px", "a4", true);
117
+ const pageHeight = pdf.internal.pageSize.getHeight();
118
+ const pageWidth = pdf.internal.pageSize.getWidth();
119
+ const fontSize = 10;
120
+ const layoutColumns = 18;
121
+ const xMargin = 20;
122
+ const yMargin = 35;
123
+ const xGap = 3;
124
+ const yGap = 3;
125
+
126
+ const logoWidth = 80;
127
+ const logoHeight = 20;
128
+ const logoXOffset = 20;
129
+ const logoYOffset = 10;
130
+ const logo = await getLogo();
131
+
132
+ let pageIndexOffset = 0;
133
+ let pageNumber = 1;
134
+
135
+ const widthUnit = Math.floor((pageWidth - xMargin) / layoutColumns);
136
+ const heightUnit = widthUnit * 0.9;
137
+ pdf.setFontSize(fontSize);
138
+ pdf.setFont(undefined, "normal");
139
+ pdf.addImage(logo, "png", logoXOffset, logoYOffset, logoWidth, logoHeight);
140
+ pdf.text(pageWidth - 2 * xMargin, pageHeight - 10, `Page ${pageNumber}`);
141
+
142
+ for (const layout of layouts.layout) {
143
+ const widget = document.getElementById(`grid-item-${layout.i}`);
144
+ const canvasOptions = {};
145
+ const canvas = await html2canvas(widget, canvasOptions);
146
+ const img = canvas.toDataURL("image/png");
147
+ const x = layout.x * widthUnit;
148
+ const y = layout.y * heightUnit;
149
+ const endOfImg = y + yMargin + layout.h * heightUnit;
150
+ // if panel is too large for page, add new page
151
+ if (endOfImg > pageHeight + pageIndexOffset) {
152
+ pdf.addPage();
153
+ pageNumber += 1;
154
+ pdf.addImage(
155
+ logo,
156
+ "png",
157
+ logoXOffset,
158
+ logoYOffset,
159
+ logoWidth,
160
+ logoHeight
161
+ );
162
+ pdf.text(pageWidth - 2 * xMargin, pageHeight - 10, `Page ${pageNumber}`);
163
+ pageIndexOffset = y;
164
+ }
165
+ // check if panel is oversized for page
166
+ if (layout.h * heightUnit > pageHeight) {
167
+ pdf.addImage(
168
+ img,
169
+ "png",
170
+ x + xMargin,
171
+ y + yMargin - pageIndexOffset,
172
+ layout.w * widthUnit - xGap,
173
+ pageHeight - yMargin
174
+ );
175
+ } else {
176
+ pdf.addImage(
177
+ img,
178
+ "png",
179
+ x + xMargin,
180
+ y + yMargin - pageIndexOffset,
181
+ layout.w * widthUnit - xGap,
182
+ layout.h * heightUnit - yGap
183
+ );
184
+ }
185
+ }
186
+
187
+ pdf.save(`${name}.pdf`);
188
+ };
189
+
190
+ const getLogo = () => {
191
+ return document.getElementById("logo");
192
+ };
193
+
194
+ const base64toImage = async (logo) => {
195
+ let data = {};
196
+ const img = new Image();
197
+ const logoHeight = 20;
198
+ img.src = logo;
199
+ await img.decode().then((res) => {
200
+ const aspectRatio = img.width / img.height;
201
+ const type = logo.split("data:image/")[1].split(";")[0];
202
+ data = {
203
+ logo: logo,
204
+ type: type,
205
+ height: logoHeight,
206
+ width: logoHeight * aspectRatio,
207
+ };
208
+ });
209
+ return data;
210
+ };
211
+
212
+ export {
213
+ saveFile,
214
+ panelCSVDownload,
215
+ csvDownload,
216
+ csvDownloadZip,
217
+ exportAsCsv,
218
+ reportToPdf,
219
+ base64toImage,
220
+ };
@@ -0,0 +1,156 @@
1
+ const costCount = (total) => {
2
+ return `$${total.toFixed(2)}`;
3
+ };
4
+
5
+ const humanCount = (total) => {
6
+ const units = ["", "K", "M", "G", "T", "P"];
7
+ let u = 0;
8
+ const sign = total >= 0;
9
+ let count = Math.abs(total);
10
+ if (count < 1000) {
11
+ return count;
12
+ }
13
+ while (count >= 1000 && u < units.length - 1) {
14
+ count /= 1000;
15
+ ++u;
16
+ }
17
+ return sign
18
+ ? `${count.toFixed(1)} ${units[u]}`
19
+ : `-${count.toFixed(1)} ${units[u]}`;
20
+ };
21
+
22
+ const dataCount = (total) => {
23
+ const units = ["", "Ki", "Mi", "Gi", "Ti", "Pi"];
24
+ let u = 0;
25
+ const sign = total >= 0;
26
+ let count = Math.abs(total);
27
+ if (count < 1024) {
28
+ if (count === 1000) return 1000;
29
+ return count.toPrecision(3);
30
+ }
31
+ while (count >= 1024 && u < units.length - 1) {
32
+ count /= 1024;
33
+ ++u;
34
+ }
35
+ return sign
36
+ ? `${count.toFixed(1)} ${units[u]}`
37
+ : `-${count.toFixed(1)} ${units[u]}`;
38
+ };
39
+
40
+ const readableNumber = (x) => {
41
+ if (Number.isNaN(x)) return x;
42
+
43
+ if (x < 9999) {
44
+ return x.toFixed(2);
45
+ }
46
+
47
+ if (x < 1000000) {
48
+ return Math.round(x / 1000) + "K";
49
+ }
50
+
51
+ if (x < 1000000000) {
52
+ return Math.round(x / 1000000) + "M";
53
+ }
54
+
55
+ if (x < 1000000000000) {
56
+ return Math.round(x / 1000000000) + "G";
57
+ }
58
+
59
+ if (x < 1000000000000000) {
60
+ return Math.round(x / 1000000000000) + "T";
61
+ }
62
+
63
+ return Math.round(x / 1000000000000000) + "P";
64
+ };
65
+
66
+ const formatReadableTime = (delay) => {
67
+ if (delay > 60000) {
68
+ if (delay > 3600000) {
69
+ if (delay > 86400000) {
70
+ return Math.floor(delay / 86400000) + " days";
71
+ }
72
+ return Math.floor(delay / 3600000) + " hrs";
73
+ }
74
+ return Math.floor(delay / 60000) + " mins";
75
+ }
76
+ return delay + " ms";
77
+ };
78
+
79
+ const durationCount = (duration) => {
80
+ const units = ["s", "mins", "hrs", "days"];
81
+ let count = duration;
82
+ let str = "";
83
+ if (count >= 86400) {
84
+ const days = Math.floor(count / 86400);
85
+ count %= 86400;
86
+ str += `${days} ${units[3]} `;
87
+ }
88
+ if (count >= 3600) {
89
+ const hours = Math.floor(count / 3600);
90
+ count %= 3600;
91
+ str += `${hours} ${units[2]} `;
92
+ }
93
+ if (count >= 60) {
94
+ const minutes = Math.floor(count / 60);
95
+ count %= 60;
96
+ str += `${minutes} ${units[1]} `;
97
+ }
98
+
99
+ return `${str}${count} ${units[0]}`;
100
+ };
101
+
102
+ const formatMS = (duration) => {
103
+ if (duration < 1000) {
104
+ return `${duration} ms`;
105
+ }
106
+ const units = ["s", "mins", "hrs", "days"];
107
+ let count = Math.floor(duration / 1000);
108
+ let str = "";
109
+ if (count >= 86400) {
110
+ const days = Math.floor(count / 86400);
111
+ count %= 86400;
112
+ str += `${days} ${units[3]} `;
113
+ }
114
+ if (count >= 3600) {
115
+ const hours = Math.floor(count / 3600);
116
+ count %= 3600;
117
+ str += `${hours} ${units[2]} `;
118
+ }
119
+ if (count >= 60) {
120
+ const minutes = Math.floor(count / 60);
121
+ count %= 60;
122
+ str += `${minutes} ${units[1]} `;
123
+ }
124
+
125
+ return `${str}${count} ${units[0]}`;
126
+ };
127
+
128
+ // hide . as 3 spaces
129
+ const encodeURLQuery = (query) => {
130
+ return query.replaceAll(".", " ");
131
+ };
132
+ const decodeURLQuery = (query) => {
133
+ return query.replaceAll("%020%020%020", ".").replaceAll(" ", ".");
134
+ };
135
+
136
+ const encodeJSONKey = (key) => {
137
+ let keyStr = `[\\\"` + key.join(`\\\",\\\"`) + `\\\"]`;
138
+ return keyStr;
139
+ };
140
+ const encodeJSONID = (key) => {
141
+ return key.replaceAll('"', `\\\"`);
142
+ };
143
+
144
+ export {
145
+ readableNumber,
146
+ humanCount,
147
+ dataCount,
148
+ costCount,
149
+ formatReadableTime,
150
+ durationCount,
151
+ formatMS,
152
+ encodeURLQuery,
153
+ decodeURLQuery,
154
+ encodeJSONKey,
155
+ encodeJSONID,
156
+ };
@@ -0,0 +1,32 @@
1
+ const randomId = (length) => {
2
+ let result = "";
3
+ const characters =
4
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
5
+ const charactersLength = characters.length;
6
+ for (let i = 0; i < length; i++) {
7
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
8
+ }
9
+ return result;
10
+ };
11
+
12
+ const randomRoleId = (length = 10) => {
13
+ let result = "";
14
+ const characters = "abcdefghijklmnopqrstuvwxyz0123456789";
15
+ const charactersLength = characters.length;
16
+ for (let i = 0; i < length; i++) {
17
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
18
+ }
19
+ return "ext_" + result;
20
+ };
21
+
22
+ const randomNumber = (length = 10) => {
23
+ let result = "";
24
+ const characters = "0123456789";
25
+ const charactersLength = characters.length;
26
+ for (let i = 0; i < length; i++) {
27
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
28
+ }
29
+ return result;
30
+ };
31
+
32
+ export { randomId, randomRoleId, randomNumber };
@@ -0,0 +1,138 @@
1
+ import moment from "moment";
2
+
3
+ const dateLocalTime = (timestamp) => {
4
+ const d = new Date(timestamp);
5
+ const options = {
6
+ weekday: "long",
7
+ year: "numeric",
8
+ month: "short",
9
+ day: "numeric",
10
+ hour: "2-digit",
11
+ minute: "2-digit",
12
+ };
13
+ return d.toLocaleTimeString("en-us", options);
14
+ };
15
+
16
+ // DATE in year month day format (local time zone)
17
+ const dateString = (timestamp) => {
18
+ return date.formatDate(timestamp, "YYYY MMM DD");
19
+ };
20
+
21
+ // DATE in year month day format, in UTC timezone
22
+ const dateStringUTC = (timestamp) => {
23
+ return (
24
+ moment
25
+ .unix(timestamp / 1000)
26
+ .utc()
27
+ .format("YYYY MMM DD") + " UTC"
28
+ );
29
+ };
30
+ // DATE in US month day year format (local time zone)
31
+ const dateStringUS = (timestamp) => {
32
+ return date.formatDate(timestamp, "MMM DD, YYYY");
33
+ };
34
+ // DATE in EU/World day month year format (local time zone)
35
+ const dateStringWorld = (timestamp) => {
36
+ return date.formatDate(timestamp, "DD MMM YYYY");
37
+ };
38
+ // DATE with TIME in year month day format with TZ offset
39
+ const dateStringTime = (timestamp) => {
40
+ const date = new Date(timestamp);
41
+ return date.formatDate(timestamp, "YYYY MMM DD h:mm A Z");
42
+ };
43
+
44
+ // DATE in DoW month day format (local time zone)
45
+ const dateWeek = (timestamp) => {
46
+ return moment.unix(timestamp / 1000).format("ddd, MMM DD");
47
+ };
48
+
49
+ // Version without Moment
50
+ function presentDate(rawDate) {
51
+ const local = new Date(rawDate);
52
+ const options = {
53
+ year: "numeric",
54
+ month: "long",
55
+ day: "numeric",
56
+ hour12: false,
57
+ };
58
+ return (
59
+ local.toLocaleDateString("en-US", options) +
60
+ " " +
61
+ local.toLocaleTimeString("en-US")
62
+ );
63
+ }
64
+
65
+ function shortTimeDate(rawDate) {
66
+ const local = new Date(rawDate);
67
+ const options = {
68
+ year: "numeric",
69
+ month: "numeric",
70
+ day: "numeric",
71
+ hour12: false,
72
+ };
73
+ return (
74
+ local.toLocaleDateString("en-US", options) +
75
+ " " +
76
+ local.toLocaleTimeString("en-US")
77
+ );
78
+ }
79
+
80
+ function hoursTimestampFromNow(ts) {
81
+ return ts ? moment(moment.now()).diff(ts, "hours") : NaN;
82
+ }
83
+
84
+ function dayTime(ts) {
85
+ return moment(ts).utc().format("MMM D Y, HH:mmz");
86
+ }
87
+
88
+ function formatTime(time) {
89
+ return moment(time).format("MMM Do Y, h:mm a");
90
+ }
91
+
92
+ function parseTime(time) {
93
+ if (!time) {
94
+ return new Date();
95
+ }
96
+ // get the format of the time
97
+ if (time.toString().indexOf("/") !== -1) {
98
+ return new Date(time);
99
+ } else if (time.toString().indexOf("-") !== -1) {
100
+ return new Date(time);
101
+ } else if (time.toString().startsWith("2")) {
102
+ const year = time.substring(0, 4);
103
+ const month = time.substring(4, 6);
104
+ const day = time.substring(6, 8);
105
+ return new Date(year, month - 1, day);
106
+ }
107
+ const date = new Date(time);
108
+ if (date.valueOf() !== time) {
109
+ return new Date(time * 1000);
110
+ }
111
+ return new Date(time);
112
+ }
113
+
114
+ function timeFromNow(time) {
115
+ return moment(time).fromNow();
116
+ }
117
+
118
+ function sleep(ms) {
119
+ return new Promise((resolve) => setTimeout(resolve, ms));
120
+ }
121
+
122
+ export {
123
+ dateWeek,
124
+ dateStringUS,
125
+ dateStringWorld,
126
+ dateStringTime,
127
+ dateString,
128
+ dateStringUTC,
129
+ presentDate,
130
+ shortTimeDate,
131
+ dateLocalTime,
132
+ hoursTimestampFromNow,
133
+ dayTime,
134
+ parseTime,
135
+ formatTime,
136
+ timeFromNow,
137
+ sleep,
138
+ };