@streamscloud/kit 0.0.1-1770364570820

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 (146) hide show
  1. package/dist/core/continuation-token.d.ts +10 -0
  2. package/dist/core/continuation-token.js +32 -0
  3. package/dist/core/css/index.d.ts +1 -0
  4. package/dist/core/css/index.js +1 -0
  5. package/dist/core/css/style-functions.d.ts +5 -0
  6. package/dist/core/css/style-functions.js +12 -0
  7. package/dist/core/cursor-result.d.ts +9 -0
  8. package/dist/core/cursor-result.js +1 -0
  9. package/dist/core/data-loaders/cursor-data-loader-with-search.svelte.d.ts +19 -0
  10. package/dist/core/data-loaders/cursor-data-loader-with-search.svelte.js +57 -0
  11. package/dist/core/data-loaders/cursor-data-loader.svelte.d.ts +13 -0
  12. package/dist/core/data-loaders/cursor-data-loader.svelte.js +33 -0
  13. package/dist/core/data-loaders/data-loader.d.ts +4 -0
  14. package/dist/core/data-loaders/data-loader.js +1 -0
  15. package/dist/core/data-loaders/index.d.ts +4 -0
  16. package/dist/core/data-loaders/index.js +4 -0
  17. package/dist/core/data-loaders/page-data-loader.svelte.d.ts +15 -0
  18. package/dist/core/data-loaders/page-data-loader.svelte.js +37 -0
  19. package/dist/core/deferred.d.ts +6 -0
  20. package/dist/core/deferred.js +13 -0
  21. package/dist/core/event-dispatcher.d.ts +9 -0
  22. package/dist/core/event-dispatcher.js +28 -0
  23. package/dist/core/files/base64-helper.d.ts +4 -0
  24. package/dist/core/files/base64-helper.js +22 -0
  25. package/dist/core/files/blob-storage.d.ts +1 -0
  26. package/dist/core/files/blob-storage.js +19 -0
  27. package/dist/core/files/file-helper.d.ts +6 -0
  28. package/dist/core/files/file-helper.js +27 -0
  29. package/dist/core/files/file-service.d.ts +4 -0
  30. package/dist/core/files/file-service.js +54 -0
  31. package/dist/core/files/file-types.d.ts +16 -0
  32. package/dist/core/files/file-types.js +28 -0
  33. package/dist/core/files/file-with-blob-data-helper.d.ts +19 -0
  34. package/dist/core/files/file-with-blob-data-helper.js +86 -0
  35. package/dist/core/files/files-provider.d.ts +8 -0
  36. package/dist/core/files/files-provider.js +38 -0
  37. package/dist/core/files/image-resizer.d.ts +31 -0
  38. package/dist/core/files/image-resizer.js +92 -0
  39. package/dist/core/files/index.d.ts +9 -0
  40. package/dist/core/files/index.js +9 -0
  41. package/dist/core/files/types.d.ts +12 -0
  42. package/dist/core/files/types.js +10 -0
  43. package/dist/core/graphql.d.ts +4 -0
  44. package/dist/core/graphql.js +10 -0
  45. package/dist/core/handle-generator.d.ts +1 -0
  46. package/dist/core/handle-generator.js +32 -0
  47. package/dist/core/i18n/index.d.ts +1 -0
  48. package/dist/core/i18n/index.js +1 -0
  49. package/dist/core/i18n/plural.d.ts +14 -0
  50. package/dist/core/i18n/plural.js +18 -0
  51. package/dist/core/index.d.ts +6 -0
  52. package/dist/core/index.js +6 -0
  53. package/dist/core/repository/index.d.ts +2 -0
  54. package/dist/core/repository/index.js +2 -0
  55. package/dist/core/repository/map-container.svelte.d.ts +9 -0
  56. package/dist/core/repository/map-container.svelte.js +22 -0
  57. package/dist/core/repository/repository-notifier.d.ts +19 -0
  58. package/dist/core/repository/repository-notifier.js +88 -0
  59. package/dist/core/repository/repository.svelte.d.ts +2 -0
  60. package/dist/core/repository/repository.svelte.js +59 -0
  61. package/dist/core/repository/types.d.ts +15 -0
  62. package/dist/core/repository/types.js +1 -0
  63. package/dist/core/theme/app-theme.svelte.d.ts +15 -0
  64. package/dist/core/theme/app-theme.svelte.js +48 -0
  65. package/dist/core/theme/index.d.ts +4 -0
  66. package/dist/core/theme/index.js +3 -0
  67. package/dist/core/theme/theme-cookie.d.ts +5 -0
  68. package/dist/core/theme/theme-cookie.js +19 -0
  69. package/dist/core/theme/types.d.ts +5 -0
  70. package/dist/core/theme/types.js +8 -0
  71. package/dist/core/toastr/index.d.ts +3 -0
  72. package/dist/core/toastr/index.js +2 -0
  73. package/dist/core/toastr/toaster-host.svelte.d.ts +5 -0
  74. package/dist/core/toastr/toaster-host.svelte.js +40 -0
  75. package/dist/core/toastr/toastr.scss +27 -0
  76. package/dist/core/toastr/toastr.svelte.d.ts +8 -0
  77. package/dist/core/toastr/toastr.svelte.js +27 -0
  78. package/dist/core/toastr/types.d.ts +14 -0
  79. package/dist/core/toastr/types.js +1 -0
  80. package/dist/core/transitions/index.d.ts +1 -0
  81. package/dist/core/transitions/index.js +1 -0
  82. package/dist/core/transitions/slide-horizontally.d.ts +8 -0
  83. package/dist/core/transitions/slide-horizontally.js +54 -0
  84. package/dist/core/utils/array-helper.d.ts +21 -0
  85. package/dist/core/utils/array-helper.js +130 -0
  86. package/dist/core/utils/base64-serializer.d.ts +4 -0
  87. package/dist/core/utils/base64-serializer.js +21 -0
  88. package/dist/core/utils/browser.d.ts +1 -0
  89. package/dist/core/utils/browser.js +1 -0
  90. package/dist/core/utils/date-helper.d.ts +51 -0
  91. package/dist/core/utils/date-helper.js +244 -0
  92. package/dist/core/utils/dom-helper.d.ts +10 -0
  93. package/dist/core/utils/dom-helper.js +34 -0
  94. package/dist/core/utils/href-validator.d.ts +22 -0
  95. package/dist/core/utils/href-validator.js +52 -0
  96. package/dist/core/utils/html-helper.d.ts +12 -0
  97. package/dist/core/utils/html-helper.js +104 -0
  98. package/dist/core/utils/index.d.ts +13 -0
  99. package/dist/core/utils/index.js +13 -0
  100. package/dist/core/utils/lazy-init.d.ts +1 -0
  101. package/dist/core/utils/lazy-init.js +7 -0
  102. package/dist/core/utils/number-helper.d.ts +5 -0
  103. package/dist/core/utils/number-helper.js +32 -0
  104. package/dist/core/utils/string-generator.d.ts +2 -0
  105. package/dist/core/utils/string-generator.js +5 -0
  106. package/dist/core/utils/string-helper.d.ts +12 -0
  107. package/dist/core/utils/string-helper.js +75 -0
  108. package/dist/core/utils/url-helper.d.ts +3 -0
  109. package/dist/core/utils/url-helper.js +13 -0
  110. package/dist/core/utils/utils.d.ts +29 -0
  111. package/dist/core/utils/utils.js +108 -0
  112. package/dist/core/validation/form-validation-handler/form-validation-handler.svelte.d.ts +47 -0
  113. package/dist/core/validation/form-validation-handler/form-validation-handler.svelte.js +182 -0
  114. package/dist/core/validation/form-validation-handler/index.d.ts +4 -0
  115. package/dist/core/validation/form-validation-handler/index.js +3 -0
  116. package/dist/core/validation/form-validation-handler/stub-form-validator.d.ts +5 -0
  117. package/dist/core/validation/form-validation-handler/stub-form-validator.js +12 -0
  118. package/dist/core/validation/form-validation-handler/types.d.ts +10 -0
  119. package/dist/core/validation/form-validation-handler/types.js +1 -0
  120. package/dist/core/validation/form-validation-handler/yup-form-validator.d.ts +11 -0
  121. package/dist/core/validation/form-validation-handler/yup-form-validator.js +49 -0
  122. package/dist/core/validation/form-validator.svelte.d.ts +12 -0
  123. package/dist/core/validation/form-validator.svelte.js +21 -0
  124. package/dist/core/validation/i-validator.d.ts +6 -0
  125. package/dist/core/validation/i-validator.js +1 -0
  126. package/dist/core/validation/index.d.ts +5 -0
  127. package/dist/core/validation/index.js +4 -0
  128. package/dist/core/validation/validation-schemas/email-validation.d.ts +3 -0
  129. package/dist/core/validation/validation-schemas/email-validation.js +17 -0
  130. package/dist/core/validation/validation-schemas/handle-validations.d.ts +3 -0
  131. package/dist/core/validation/validation-schemas/handle-validations.js +16 -0
  132. package/dist/core/validation/validation-schemas/index.d.ts +6 -0
  133. package/dist/core/validation/validation-schemas/index.js +5 -0
  134. package/dist/core/validation/validation-schemas/number-validations.d.ts +4 -0
  135. package/dist/core/validation/validation-schemas/number-validations.js +30 -0
  136. package/dist/core/validation/validation-schemas/text-validations.d.ts +4 -0
  137. package/dist/core/validation/validation-schemas/text-validations.js +19 -0
  138. package/dist/core/validation/validation-schemas/types.d.ts +19 -0
  139. package/dist/core/validation/validation-schemas/types.js +1 -0
  140. package/dist/core/validation/validation-schemas/validation-messages.d.ts +11 -0
  141. package/dist/core/validation/validation-schemas/validation-messages.js +14 -0
  142. package/dist/core/validation/validators-hub.svelte.d.ts +14 -0
  143. package/dist/core/validation/validators-hub.svelte.js +51 -0
  144. package/dist/ui/index.d.ts +1 -0
  145. package/dist/ui/index.js +2 -0
  146. package/package.json +125 -0
@@ -0,0 +1,244 @@
1
+ export class DateHelper {
2
+ static toDate(date, resetTime = false) {
3
+ date = new Date(date);
4
+ if (resetTime) {
5
+ date.setHours(0, 0, 0, 0);
6
+ }
7
+ return date;
8
+ }
9
+ static addMonths(date, months = 1) {
10
+ const newDate = new Date(date);
11
+ newDate.setMonth(newDate.getMonth() + months);
12
+ return newDate;
13
+ }
14
+ static addDays(date, days) {
15
+ date = DateHelper.toDate(date);
16
+ date.setDate(date.getDate() + days);
17
+ return date;
18
+ }
19
+ static secondsToTimeRepresentation(seconds, duration) {
20
+ const longerThanHour = Math.floor(duration / 3600) > 0;
21
+ if (!seconds) {
22
+ return longerThanHour ? '0:00:00' : '0:00';
23
+ }
24
+ const hours = Math.floor(seconds / 3600);
25
+ const mins = Math.floor((seconds - hours * 3600) / 60);
26
+ seconds = seconds - hours * 3600 - mins * 60;
27
+ let res = '';
28
+ if (longerThanHour) {
29
+ if (hours) {
30
+ res += `${hours}:`;
31
+ }
32
+ else {
33
+ res += '0:';
34
+ }
35
+ if (mins < 10) {
36
+ res += '0';
37
+ }
38
+ }
39
+ res += `${mins}:`;
40
+ if (seconds < 10) {
41
+ res += '0';
42
+ }
43
+ res += seconds;
44
+ return res;
45
+ }
46
+ static getDate(date) {
47
+ date = DateHelper.toDate(date);
48
+ return date.getDate();
49
+ }
50
+ static getYear(date) {
51
+ date = DateHelper.toDate(date);
52
+ return date.getFullYear();
53
+ }
54
+ static getDiffInDays(date1, date2) {
55
+ date1 = DateHelper.toDate(date1);
56
+ date2 = DateHelper.toDate(date2);
57
+ const diffTime = Math.abs(date2.getTime() - date1.getTime());
58
+ return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
59
+ }
60
+ static getMonthName(date, locale, short = false) {
61
+ date = DateHelper.toDate(date);
62
+ return date.toLocaleString(locale, { month: short ? 'short' : 'long' });
63
+ }
64
+ static getWeekdayName(date, locale, short = false) {
65
+ date = DateHelper.toDate(date);
66
+ return date.toLocaleString(locale, { weekday: short ? 'short' : 'long' });
67
+ }
68
+ static getMonthRange(date) {
69
+ date = DateHelper.toDate(date);
70
+ const fullYear = date.getFullYear();
71
+ const month = date.getMonth();
72
+ const firstDay = new Date(fullYear, month, 1);
73
+ const lastDay = new Date(fullYear, month + 1, 1);
74
+ lastDay.setMilliseconds(-1);
75
+ return { firstDay, lastDay };
76
+ }
77
+ static daysInMonth(date) {
78
+ date = DateHelper.toDate(date);
79
+ return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
80
+ }
81
+ static getDayOfWeek(date) {
82
+ date = DateHelper.toDate(date);
83
+ const day = date.getDay();
84
+ return day === 0 ? 7 : day;
85
+ }
86
+ static getShiftedDate(date, daysShift) {
87
+ date = DateHelper.toDate(date);
88
+ date.setDate(date.getDate() + daysShift);
89
+ return date;
90
+ }
91
+ static getDateOnlyString(date) {
92
+ date = DateHelper.toDate(date);
93
+ const year = date.getFullYear();
94
+ const month = date.getMonth() + 1;
95
+ const day = date.getDate();
96
+ return `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`;
97
+ }
98
+ static formatDateRange(startDate, endDate, locale) {
99
+ const startTime = DateHelper.toDate(startDate);
100
+ const endTime = DateHelper.toDate(endDate);
101
+ const startMonthName = DateHelper.getMonthName(startDate, locale).toLocaleLowerCase();
102
+ const endMonthName = DateHelper.getMonthName(endDate, locale).toLocaleLowerCase();
103
+ const isSameDateWithStart = startTime.getDate() === endTime.getDate() && startTime.getMonth() === endTime.getMonth() && startTime.getFullYear() === endTime.getFullYear();
104
+ const isSameMonth = startTime.getMonth() === endTime.getMonth();
105
+ if (isSameDateWithStart) {
106
+ return `${startTime.getDate()}. ${startMonthName}`;
107
+ }
108
+ if (isSameMonth) {
109
+ return `${startTime.getDate()}. –${endTime.getDate()}. ${startMonthName}`;
110
+ }
111
+ return `${startTime.getDate()}. ${startMonthName} – ${endTime.getDate()}. ${endMonthName}`;
112
+ }
113
+ static dateRangeDescriptionString(startDate, endDate, locale) {
114
+ let eventTime;
115
+ const currentDate = new Date();
116
+ const startTime = DateHelper.toDate(startDate);
117
+ const getFormattedDate = (d) => {
118
+ const month = DateHelper.getMonthName(d, locale, false);
119
+ const date = d.getDate();
120
+ const year = d.getFullYear() === currentDate.getFullYear() ? '' : d.getFullYear().toString();
121
+ const dateString = [month, date, year].join(' ');
122
+ return dateString;
123
+ };
124
+ const getFormattedTime = (d) => {
125
+ return `${d.getHours().toString().padStart(2, '0')}:${d.getMinutes().toString().padStart(2, '0')}`;
126
+ };
127
+ const getWeekday = (d) => DateHelper.getWeekdayName(d, locale, false);
128
+ if (!endDate) {
129
+ eventTime = [getWeekday(startTime), getFormattedDate(startTime), getFormattedTime(startTime)].join(' · ');
130
+ }
131
+ else {
132
+ const endTime = DateHelper.toDate(endDate);
133
+ const isSameDateWithStart = startTime.getDate() === endTime.getDate() && startTime.getMonth() === endTime.getMonth() && startTime.getFullYear() === endTime.getFullYear();
134
+ if (isSameDateWithStart) {
135
+ eventTime = [getWeekday(startTime), getFormattedDate(startTime), `${getFormattedTime(startTime)}-${getFormattedTime(endTime)}`].join(' · ');
136
+ }
137
+ else {
138
+ const getFormattedDateWithTime = (d) => [getFormattedDate(d), getFormattedTime(d)].join(' · ');
139
+ eventTime = `${getFormattedDateWithTime(startTime)} - ${getFormattedDateWithTime(endTime)}`;
140
+ }
141
+ }
142
+ return eventTime;
143
+ }
144
+ static toDefaultDateTimeRepresentation = (val, locale, alwaysIncludeYear = false) => {
145
+ const dateTime = DateHelper.toDate(val);
146
+ const sameYear = dateTime.getFullYear() === new Date().getFullYear();
147
+ const formatNumber = (n) => n.toString().padStart(2, '0');
148
+ const date = `${formatNumber(dateTime.getDate())}`;
149
+ const monthName = DateHelper.getMonthName(dateTime, locale, !sameYear);
150
+ const year = sameYear && !alwaysIncludeYear ? '' : ' ' + dateTime.getFullYear();
151
+ const time = `${formatNumber(dateTime.getHours())}:${formatNumber(dateTime.getMinutes())}`;
152
+ return `${date}. ${monthName}${year} - ${time}`;
153
+ };
154
+ static addYears(dateToModify, yearsToAdd, resetTime = true) {
155
+ const date = new Date(dateToModify);
156
+ date.setFullYear(date.getFullYear() + yearsToAdd);
157
+ if (resetTime) {
158
+ date.setHours(0, 0, 0, 0);
159
+ }
160
+ return date;
161
+ }
162
+ static startOfLastWeek() {
163
+ const now = new Date();
164
+ const day = now.getDay();
165
+ const diffToMonday = (day === 0 ? 7 : day) - 1;
166
+ const lastMonday = new Date(now);
167
+ lastMonday.setDate(now.getDate() - diffToMonday - 7);
168
+ lastMonday.setHours(0, 0, 0, 0);
169
+ return lastMonday.toISOString().slice(0, 10);
170
+ }
171
+ static endOfLastWeek() {
172
+ const now = new Date();
173
+ const day = now.getDay();
174
+ const lastSunday = new Date(now);
175
+ lastSunday.setDate(now.getDate() - (day === 0 ? 0 : day));
176
+ lastSunday.setHours(23, 59, 59, 999);
177
+ lastSunday.setDate(lastSunday.getDate() - 1);
178
+ return lastSunday.toISOString().slice(0, 10);
179
+ }
180
+ static startOfLastMonth() {
181
+ const now = new Date();
182
+ const firstDayOfThisMonth = new Date(now.getFullYear(), now.getMonth(), 1);
183
+ const firstDayOfLastMonth = new Date(firstDayOfThisMonth);
184
+ firstDayOfLastMonth.setMonth(firstDayOfThisMonth.getMonth() - 1);
185
+ return firstDayOfLastMonth.toISOString().slice(0, 10);
186
+ }
187
+ static endOfLastMonth() {
188
+ const now = new Date();
189
+ const firstDayOfThisMonth = new Date(now.getFullYear(), now.getMonth(), 1);
190
+ const lastDayOfLastMonth = new Date(firstDayOfThisMonth);
191
+ lastDayOfLastMonth.setDate(0);
192
+ lastDayOfLastMonth.setHours(23, 59, 59, 999);
193
+ return lastDayOfLastMonth.toISOString().slice(0, 10);
194
+ }
195
+ static startOfLastYear() {
196
+ const now = new Date();
197
+ const firstDayOfLastYear = new Date(now.getFullYear() - 1, 0, 1);
198
+ return firstDayOfLastYear.toISOString().slice(0, 10);
199
+ }
200
+ static endOfLastYear() {
201
+ const now = new Date();
202
+ const lastDayOfLastYear = new Date(now.getFullYear() - 1, 11, 31);
203
+ lastDayOfLastYear.setHours(23, 59, 59, 999);
204
+ return lastDayOfLastYear.toISOString().slice(0, 10);
205
+ }
206
+ static startOfRollingDays(days) {
207
+ const now = new Date();
208
+ const start = new Date(now);
209
+ start.setDate(now.getDate() - (days - 1));
210
+ start.setHours(0, 0, 0, 0);
211
+ return start.toISOString().slice(0, 10);
212
+ }
213
+ static endOfRollingDays() {
214
+ const now = new Date();
215
+ now.setHours(23, 59, 59, 999);
216
+ return now.toISOString().slice(0, 10);
217
+ }
218
+ static startOfCurrentMonthToNow() {
219
+ const now = new Date();
220
+ const from = new Date(now.getFullYear(), now.getMonth(), 1);
221
+ return { from: DateHelper.getDateOnlyString(from), to: DateHelper.getDateOnlyString(now) };
222
+ }
223
+ static startOfCurrentYearToNow() {
224
+ const now = new Date();
225
+ const from = new Date(now.getFullYear(), 0, 1);
226
+ return { from: DateHelper.getDateOnlyString(from), to: DateHelper.getDateOnlyString(now) };
227
+ }
228
+ }
229
+ export class DateFormatOptions {
230
+ static dateTimeFormat = {
231
+ day: '2-digit',
232
+ month: 'short',
233
+ year: 'numeric',
234
+ hour: '2-digit',
235
+ minute: '2-digit',
236
+ hour12: false
237
+ };
238
+ static dateTimeWithoutYearFormat = { day: '2-digit', month: 'short', hour: '2-digit', minute: '2-digit', hour12: false };
239
+ static timeFormat = { hour: '2-digit', minute: '2-digit', hour12: false };
240
+ static dateFormat = { day: '2-digit', month: 'short', year: 'numeric' };
241
+ static dateNumericFormat = { day: '2-digit', month: '2-digit', year: 'numeric' };
242
+ static dateFormatWithoutYear = { day: '2-digit', month: 'short' };
243
+ static dateFullMonthFormat = { day: '2-digit', month: 'long' };
244
+ }
@@ -0,0 +1,10 @@
1
+ export declare class DomHelper {
2
+ /**
3
+ * Checks whether initial object is located inside specified boundaries
4
+ * @param {HTMLElement} element The initial element
5
+ * @param {HTMLElement[]} boundaryElements Parent elements concerned to be valid boundaries
6
+ * @return {boolean} true if initial element is located inside specified boundaries, otherwise false
7
+ */
8
+ static checkElementOutsideSpecifiedBoundaries(element: Element | EventTarget | null, boundaryElements: Array<Element | EventTarget>): boolean;
9
+ static calcHeightBasedOnRows(element: HTMLElement, rows: number): string;
10
+ }
@@ -0,0 +1,34 @@
1
+ export class DomHelper {
2
+ /**
3
+ * Checks whether initial object is located inside specified boundaries
4
+ * @param {HTMLElement} element The initial element
5
+ * @param {HTMLElement[]} boundaryElements Parent elements concerned to be valid boundaries
6
+ * @return {boolean} true if initial element is located inside specified boundaries, otherwise false
7
+ */
8
+ static checkElementOutsideSpecifiedBoundaries(element, boundaryElements) {
9
+ let node = element;
10
+ boundaryElements = boundaryElements || [];
11
+ while (node) {
12
+ if (boundaryElements.includes(node)) {
13
+ return false;
14
+ }
15
+ node = node.parentElement;
16
+ }
17
+ return true;
18
+ }
19
+ static calcHeightBasedOnRows(element, rows) {
20
+ const computed = window.getComputedStyle(element);
21
+ const paddingTop = parseFloat(computed.getPropertyValue('padding-top'));
22
+ const paddingBottom = parseFloat(computed.getPropertyValue('padding-bottom'));
23
+ const lineHeightPx = computed.getPropertyValue('line-height');
24
+ let lineHeight;
25
+ if (lineHeightPx === 'normal') {
26
+ lineHeight = parseFloat(computed.getPropertyValue('font-size')) * 1.2;
27
+ }
28
+ else {
29
+ lineHeight = parseFloat(lineHeightPx);
30
+ }
31
+ const computedHeight = paddingBottom + paddingTop + lineHeight * rows;
32
+ return `${computedHeight}px`;
33
+ }
34
+ }
@@ -0,0 +1,22 @@
1
+ export declare enum ValidationError {
2
+ NotString = 0,
3
+ Empty = 1,
4
+ ControlChars = 2,
5
+ DisallowedScheme = 3,
6
+ MissingHost = 4,
7
+ EmbeddedCredentials = 5,
8
+ Relative = 6,
9
+ BareRelative = 7
10
+ }
11
+ type DetailedResult = {
12
+ valid: true;
13
+ } | {
14
+ valid: false;
15
+ error: ValidationError;
16
+ };
17
+ export type ValidateOptions = {
18
+ allowRelative?: 'all' | 'prefixed';
19
+ allowedSchemes?: Set<string>;
20
+ };
21
+ export declare const validateHref: (input: unknown, opts?: ValidateOptions) => DetailedResult;
22
+ export {};
@@ -0,0 +1,52 @@
1
+ export var ValidationError;
2
+ (function (ValidationError) {
3
+ ValidationError[ValidationError["NotString"] = 0] = "NotString";
4
+ ValidationError[ValidationError["Empty"] = 1] = "Empty";
5
+ ValidationError[ValidationError["ControlChars"] = 2] = "ControlChars";
6
+ ValidationError[ValidationError["DisallowedScheme"] = 3] = "DisallowedScheme";
7
+ ValidationError[ValidationError["MissingHost"] = 4] = "MissingHost";
8
+ ValidationError[ValidationError["EmbeddedCredentials"] = 5] = "EmbeddedCredentials";
9
+ ValidationError[ValidationError["Relative"] = 6] = "Relative";
10
+ ValidationError[ValidationError["BareRelative"] = 7] = "BareRelative";
11
+ })(ValidationError || (ValidationError = {}));
12
+ const DEFAULT_ALLOWED_SCHEMES = new Set(['http:', 'https:', 'mailto:', 'tel:']);
13
+ export const validateHref = (input, opts = {}) => {
14
+ if (typeof input !== 'string') {
15
+ return { valid: false, error: ValidationError.NotString };
16
+ }
17
+ const s = input.trim();
18
+ if (s.length === 0) {
19
+ return { valid: false, error: ValidationError.Empty };
20
+ }
21
+ for (let i = 0; i < s.length; i++) {
22
+ const code = s.charCodeAt(i);
23
+ if ((code >= 0 && code <= 31) || code === 127) {
24
+ return { valid: false, error: ValidationError.ControlChars };
25
+ }
26
+ }
27
+ try {
28
+ const u = new URL(s);
29
+ const proto = u.protocol.toLowerCase();
30
+ if (!(opts.allowedSchemes ?? DEFAULT_ALLOWED_SCHEMES).has(proto)) {
31
+ return { valid: false, error: ValidationError.DisallowedScheme };
32
+ }
33
+ if ((proto === 'http:' || proto === 'https:') && !u.hostname) {
34
+ return { valid: false, error: ValidationError.MissingHost };
35
+ }
36
+ if (u.username || u.password) {
37
+ return { valid: false, error: ValidationError.EmbeddedCredentials };
38
+ }
39
+ return { valid: true };
40
+ }
41
+ catch {
42
+ // Not an absolute URL, continue with relative checks
43
+ }
44
+ if (!opts.allowRelative) {
45
+ return { valid: false, error: ValidationError.Relative };
46
+ }
47
+ const hasAllowedRelativePrefix = s.startsWith('/') || s.startsWith('./') || s.startsWith('../') || s.startsWith('#') || s.startsWith('?') || s.startsWith('//');
48
+ if (hasAllowedRelativePrefix) {
49
+ return { valid: true };
50
+ }
51
+ return opts.allowRelative === 'all' ? { valid: true } : { valid: false, error: ValidationError.BareRelative };
52
+ };
@@ -0,0 +1,12 @@
1
+ export declare class HtmlHelper {
2
+ static clearSelection(): void;
3
+ static elementFromString(html: string): Element;
4
+ /**
5
+ * Replaces reserved html characters with html entities e.g. '<' with '&lt;'
6
+ */
7
+ static escapeSpecialChars(s: string): string;
8
+ static pasteIntoInput(value: string, element: HTMLInputElement | HTMLTextAreaElement): void;
9
+ static sanitizeSvg(svg: string): string;
10
+ static sanitizeHtml(html: string): string;
11
+ static stripHtml(html: string, lineBreaksReplacer?: string | null, trimResult?: boolean): string;
12
+ }
@@ -0,0 +1,104 @@
1
+ import dp from 'dompurify';
2
+ export class HtmlHelper {
3
+ static clearSelection() {
4
+ if (window.getSelection) {
5
+ const selection = window.getSelection();
6
+ if (!selection) {
7
+ return;
8
+ }
9
+ if (selection.empty) {
10
+ // Chrome
11
+ selection.empty();
12
+ }
13
+ else if (selection.removeAllRanges) {
14
+ // Firefox
15
+ selection.removeAllRanges();
16
+ }
17
+ }
18
+ }
19
+ static elementFromString(html) {
20
+ const wrapper = document.createElement('div');
21
+ wrapper.innerHTML = html;
22
+ const result = wrapper.firstElementChild;
23
+ wrapper.remove();
24
+ return result;
25
+ }
26
+ /**
27
+ * Replaces reserved html characters with html entities e.g. '<' with '&lt;'
28
+ */
29
+ static escapeSpecialChars(s) {
30
+ return s.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#039;');
31
+ }
32
+ static pasteIntoInput(value, element) {
33
+ if (element.selectionStart || element.selectionStart === 0) {
34
+ const startPos = element.selectionStart;
35
+ const endPos = element.selectionEnd;
36
+ if (endPos === null) {
37
+ element.value = value;
38
+ }
39
+ else {
40
+ const beforeSelection = element.value.substring(0, startPos);
41
+ const afterSelection = element.value.substring(endPos, element.value.length);
42
+ element.value = `${beforeSelection}${value}${afterSelection}`;
43
+ }
44
+ const newCursor = startPos + value.length;
45
+ element.setSelectionRange(newCursor, newCursor);
46
+ }
47
+ else {
48
+ element.value += value;
49
+ }
50
+ element.dispatchEvent(new Event('input', {
51
+ bubbles: true,
52
+ cancelable: true
53
+ }));
54
+ element.focus();
55
+ }
56
+ static sanitizeSvg(svg) {
57
+ return dp.sanitize(svg, { USE_PROFILES: { svg: true, svgFilters: true }, ADD_ATTR: ['dominant-baseline'] });
58
+ }
59
+ static sanitizeHtml(html) {
60
+ return HtmlSanitizer.sanitize(html);
61
+ }
62
+ static stripHtml(html, lineBreaksReplacer = null, trimResult = true) {
63
+ if (!html) {
64
+ return '';
65
+ }
66
+ html = HtmlHelper.sanitizeHtml(html);
67
+ const tmp = document.createElement('div');
68
+ tmp.innerHTML = html;
69
+ // move element out of visible area
70
+ tmp.style.position = 'fixed';
71
+ tmp.style.left = '200%';
72
+ // element should be appended into the DOM otherwise element.innerText doesn't contain line breaks (\n) (at least at Chrome)
73
+ document.body.appendChild(tmp);
74
+ let result = tmp.innerText || tmp.textContent || '';
75
+ result = result.replace(/\n\n/g, '\n');
76
+ if (trimResult) {
77
+ result = result.trim();
78
+ }
79
+ if (lineBreaksReplacer !== null) {
80
+ result = result.replace(/\n/g, lineBreaksReplacer);
81
+ }
82
+ tmp.remove();
83
+ return result;
84
+ }
85
+ }
86
+ class HtmlSanitizer {
87
+ static initialized = false;
88
+ static sanitize(html) {
89
+ HtmlSanitizer.ensureInitialized();
90
+ return dp.sanitize(html, {
91
+ ADD_ATTR: ['target']
92
+ });
93
+ }
94
+ static ensureInitialized() {
95
+ if (!HtmlSanitizer.initialized) {
96
+ dp.addHook('afterSanitizeAttributes', (node) => {
97
+ if (node.tagName === 'A' && node.hasAttribute('target')) {
98
+ node.setAttribute('rel', 'noopener noreferrer');
99
+ }
100
+ });
101
+ HtmlSanitizer.initialized = true;
102
+ }
103
+ }
104
+ }
@@ -0,0 +1,13 @@
1
+ export * from './array-helper';
2
+ export * from './base64-serializer';
3
+ export * from './browser';
4
+ export * from './date-helper';
5
+ export * from './dom-helper';
6
+ export * from './href-validator';
7
+ export * from './html-helper';
8
+ export * from './lazy-init';
9
+ export * from './number-helper';
10
+ export * from './string-generator';
11
+ export * from './string-helper';
12
+ export * from './url-helper';
13
+ export * from './utils';
@@ -0,0 +1,13 @@
1
+ export * from './array-helper';
2
+ export * from './base64-serializer';
3
+ export * from './browser';
4
+ export * from './date-helper';
5
+ export * from './dom-helper';
6
+ export * from './href-validator';
7
+ export * from './html-helper';
8
+ export * from './lazy-init';
9
+ export * from './number-helper';
10
+ export * from './string-generator';
11
+ export * from './string-helper';
12
+ export * from './url-helper';
13
+ export * from './utils';
@@ -0,0 +1 @@
1
+ export declare const lazyInit: <T>(factory: () => T) => (() => T);
@@ -0,0 +1,7 @@
1
+ export const lazyInit = (factory) => {
2
+ let instance = null;
3
+ return () => {
4
+ instance ??= factory();
5
+ return instance;
6
+ };
7
+ };
@@ -0,0 +1,5 @@
1
+ export declare class NumberHelper {
2
+ static formatNumber: (n: number | string) => string;
3
+ static formatCompactNumber: (num: number, locale?: string) => string;
4
+ static randomIntFromInterval: (min: number, max: number) => number;
5
+ }
@@ -0,0 +1,32 @@
1
+ export class NumberHelper {
2
+ static formatNumber = (n) => {
3
+ if (!n) {
4
+ return '0';
5
+ }
6
+ if (typeof n === 'string') {
7
+ n = parseInt(n);
8
+ }
9
+ const isNegative = n < 0;
10
+ let modulo = isNegative ? 0 - n : n;
11
+ const output = [];
12
+ for (; modulo >= 1000; modulo = Math.floor(n / 1000)) {
13
+ output.unshift(String(modulo % 1000).padStart(3, '0'));
14
+ }
15
+ output.unshift(modulo);
16
+ return `${isNegative ? '-' : ''}${output.join(' ')}`;
17
+ };
18
+ static formatCompactNumber = (num, locale) => {
19
+ if (num < 1000) {
20
+ return num.toString();
21
+ }
22
+ return new Intl.NumberFormat(locale, {
23
+ notation: 'compact',
24
+ compactDisplay: 'short',
25
+ maximumFractionDigits: 1
26
+ }).format(num);
27
+ };
28
+ static randomIntFromInterval = (min, max) => {
29
+ // min and max included
30
+ return Math.floor(Math.random() * (max - min + 1) + min);
31
+ };
32
+ }
@@ -0,0 +1,2 @@
1
+ export declare const randomString: (size?: number) => string;
2
+ export declare const randomNanoid: (size?: number) => string;
@@ -0,0 +1,5 @@
1
+ import { customAlphabet } from 'nanoid';
2
+ const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
3
+ const alphanumeric = letters + '0123456789';
4
+ export const randomString = (size = 15) => customAlphabet(letters, size)();
5
+ export const randomNanoid = (size = 15) => customAlphabet(alphanumeric, size)();
@@ -0,0 +1,12 @@
1
+ export declare class StringHelper {
2
+ static isBlobUrl(val: string | null | undefined): boolean;
3
+ static isEmail(val: string): boolean;
4
+ static isNumeric(n: string): boolean;
5
+ static isUrl(val: string): boolean;
6
+ static isNullOrEmpty(str: string | null | undefined): boolean;
7
+ static toKebabCase(str: string): string;
8
+ static toSnakeCase(str: string): string;
9
+ static truncate(str: string, length: number): string;
10
+ static capitalizeFirstLetter(word: string): string;
11
+ static toFileSizeString(sizeBytes: number): string;
12
+ }
@@ -0,0 +1,75 @@
1
+ export class StringHelper {
2
+ static isBlobUrl(val) {
3
+ return !!val && val.startsWith('blob:');
4
+ }
5
+ static isEmail(val) {
6
+ if (!val) {
7
+ return false;
8
+ }
9
+ const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
10
+ return re.test(String(val).toLowerCase());
11
+ }
12
+ static isNumeric(n) {
13
+ const parsed = parseFloat(n);
14
+ return !isNaN(parsed) && isFinite(parsed);
15
+ }
16
+ static isUrl(val) {
17
+ if (!val) {
18
+ return false;
19
+ }
20
+ try {
21
+ const url = new URL(val);
22
+ return (val.startsWith('http://') || val.startsWith('https://')) && url && ['http:', 'https:'].includes(url.protocol);
23
+ }
24
+ catch {
25
+ return false;
26
+ }
27
+ }
28
+ static isNullOrEmpty(str) {
29
+ return !str || str.trim().length === 0;
30
+ }
31
+ static toKebabCase(str) {
32
+ return (str
33
+ .match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
34
+ ?.join('-')
35
+ .toLowerCase() || str);
36
+ }
37
+ static toSnakeCase(str) {
38
+ if (!str) {
39
+ return str;
40
+ }
41
+ return str
42
+ .split(/(?=[A-Z])/)
43
+ .join('_')
44
+ .toLowerCase();
45
+ }
46
+ static truncate(str, length) {
47
+ if (str.length <= length) {
48
+ return str;
49
+ }
50
+ str = str.slice(0, length) + '...';
51
+ return str;
52
+ }
53
+ static capitalizeFirstLetter(word) {
54
+ return word.charAt(0).toUpperCase() + word.slice(1);
55
+ }
56
+ static toFileSizeString(sizeBytes) {
57
+ const kilobytes = Math.round((sizeBytes / 1000) * 10) / 10;
58
+ const megabytes = Math.round((sizeBytes / Math.pow(1000, 2)) * 10) / 10;
59
+ const gigabytes = Math.round((sizeBytes / Math.pow(1000, 3)) * 10) / 10;
60
+ const terabytes = Math.round((sizeBytes / Math.pow(1000, 4)) * 10) / 10;
61
+ if (kilobytes < 1000) {
62
+ return `${kilobytes} KB`;
63
+ }
64
+ if (megabytes < 1000) {
65
+ return `${megabytes} MB`;
66
+ }
67
+ if (gigabytes < 1000) {
68
+ return `${gigabytes} GB`;
69
+ }
70
+ if (terabytes < 1000) {
71
+ return `${terabytes} TB`;
72
+ }
73
+ return `${megabytes} MB`;
74
+ }
75
+ }
@@ -0,0 +1,3 @@
1
+ export declare class UrlHelper {
2
+ static getRootDomain(url: URL | Location): string;
3
+ }