@ssa-ui-kit/utils 1.0.0 → 1.1.55-canary-b1a0b68-20250224
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.
- package/dist/index.js +323 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/debounce/debounce.d.ts +1 -3
- package/dist/utils/objects/assocPath.d.ts +1 -1
- package/dist/utils/objects/path.d.ts +1 -1
- package/dist/utils/throttle/throttle.d.ts +1 -4
- package/package.json +4 -8
- package/src/index.ts +0 -8
- package/src/utils/CallAll.ts +0 -5
- package/src/utils/dates/dateFormatters.ts +0 -61
- package/src/utils/dates/dates.spec.tsx +0 -127
- package/src/utils/dates/index.ts +0 -1
- package/src/utils/debounce/debounce.spec.ts +0 -85
- package/src/utils/debounce/debounce.ts +0 -24
- package/src/utils/debounce/index.ts +0 -1
- package/src/utils/objects/assocPath.spec.tsx +0 -53
- package/src/utils/objects/assocPath.ts +0 -11
- package/src/utils/objects/dissocPath.spec.tsx +0 -49
- package/src/utils/objects/dissocPath.ts +0 -14
- package/src/utils/objects/index.ts +0 -7
- package/src/utils/objects/mapObjIndexed.spec.tsx +0 -33
- package/src/utils/objects/mapObjIndexed.ts +0 -15
- package/src/utils/objects/path.spec.tsx +0 -24
- package/src/utils/objects/path.ts +0 -4
- package/src/utils/objects/pathOr.spec.tsx +0 -23
- package/src/utils/objects/pathOr.ts +0 -11
- package/src/utils/objects/prop.spec.tsx +0 -17
- package/src/utils/objects/prop.ts +0 -4
- package/src/utils/objects/propOr.spec.tsx +0 -17
- package/src/utils/objects/propOr.ts +0 -11
- package/src/utils/pagination/generateRange.spec.ts +0 -100
- package/src/utils/pagination/generateRange.ts +0 -91
- package/src/utils/pagination/index.ts +0 -1
- package/src/utils/pagination/types.ts +0 -4
- package/src/utils/throttle/index.ts +0 -1
- package/src/utils/throttle/throttle.spec.ts +0 -56
- package/src/utils/throttle/throttle.ts +0 -43
- package/src/utils/types.ts +0 -4
- package/tsbuildcache +0 -1
- package/tsconfig.build.json +0 -35
- package/tsconfig.json +0 -17
- package/webpack.config.js +0 -16
package/dist/index.js
CHANGED
|
@@ -1,2 +1,324 @@
|
|
|
1
|
-
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
|
5
|
+
define([], factory);
|
|
6
|
+
else if(typeof exports === 'object')
|
|
7
|
+
exports["SSAUtils"] = factory();
|
|
8
|
+
else
|
|
9
|
+
root["SSAUtils"] = factory();
|
|
10
|
+
})(self, () => {
|
|
11
|
+
return /******/ (() => { // webpackBootstrap
|
|
12
|
+
/******/ "use strict";
|
|
13
|
+
/******/ // The require scope
|
|
14
|
+
/******/ var __webpack_require__ = {};
|
|
15
|
+
/******/
|
|
16
|
+
/************************************************************************/
|
|
17
|
+
/******/ /* webpack/runtime/define property getters */
|
|
18
|
+
/******/ (() => {
|
|
19
|
+
/******/ // define getter functions for harmony exports
|
|
20
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
21
|
+
/******/ for(var key in definition) {
|
|
22
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
23
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
24
|
+
/******/ }
|
|
25
|
+
/******/ }
|
|
26
|
+
/******/ };
|
|
27
|
+
/******/ })();
|
|
28
|
+
/******/
|
|
29
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
30
|
+
/******/ (() => {
|
|
31
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
32
|
+
/******/ })();
|
|
33
|
+
/******/
|
|
34
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
35
|
+
/******/ (() => {
|
|
36
|
+
/******/ // define __esModule on exports
|
|
37
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
38
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
39
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
40
|
+
/******/ }
|
|
41
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
42
|
+
/******/ };
|
|
43
|
+
/******/ })();
|
|
44
|
+
/******/
|
|
45
|
+
/************************************************************************/
|
|
46
|
+
var __webpack_exports__ = {};
|
|
47
|
+
// ESM COMPAT FLAG
|
|
48
|
+
__webpack_require__.r(__webpack_exports__);
|
|
49
|
+
|
|
50
|
+
// EXPORTS
|
|
51
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
52
|
+
assocPath: () => (/* reexport */ assocPath),
|
|
53
|
+
callAll: () => (/* reexport */ callAll),
|
|
54
|
+
dateFormatters: () => (/* reexport */ dateFormatters_namespaceObject),
|
|
55
|
+
debounce: () => (/* reexport */ debounce),
|
|
56
|
+
dissocPath: () => (/* reexport */ dissocPath),
|
|
57
|
+
generateRange: () => (/* reexport */ pagination_generateRange),
|
|
58
|
+
mapObjIndexed: () => (/* reexport */ mapObjIndexed),
|
|
59
|
+
path: () => (/* reexport */ path_path),
|
|
60
|
+
pathOr: () => (/* reexport */ pathOr),
|
|
61
|
+
prop: () => (/* reexport */ prop),
|
|
62
|
+
propOr: () => (/* reexport */ propOr),
|
|
63
|
+
throttle: () => (/* reexport */ throttle)
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// NAMESPACE OBJECT: ./src/utils/dates/dateFormatters.ts
|
|
67
|
+
var dateFormatters_namespaceObject = {};
|
|
68
|
+
__webpack_require__.r(dateFormatters_namespaceObject);
|
|
69
|
+
__webpack_require__.d(dateFormatters_namespaceObject, {
|
|
70
|
+
formatDate: () => (formatDate),
|
|
71
|
+
formatDayOfWeek: () => (formatDayOfWeek),
|
|
72
|
+
formatTime: () => (formatTime),
|
|
73
|
+
getTimeAgo: () => (getTimeAgo),
|
|
74
|
+
printDayOfTheWeek: () => (printDayOfTheWeek)
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
;// ./src/utils/CallAll.ts
|
|
78
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
79
|
+
const callAll = (...fns) => (...args) => fns.forEach(fn => fn?.(...args));
|
|
80
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
81
|
+
;// ./src/utils/throttle/throttle.ts
|
|
82
|
+
const throttle = (fn, delayMs) => {
|
|
83
|
+
let isThrottled = false;
|
|
84
|
+
let savedArgs = null;
|
|
85
|
+
let timeoutId = null;
|
|
86
|
+
function throttledFn(...args) {
|
|
87
|
+
if (isThrottled) {
|
|
88
|
+
savedArgs = args;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
isThrottled = true;
|
|
92
|
+
fn(...args);
|
|
93
|
+
timeoutId = setTimeout(() => {
|
|
94
|
+
isThrottled = false;
|
|
95
|
+
|
|
96
|
+
// istanbul ignore else
|
|
97
|
+
if (savedArgs) {
|
|
98
|
+
throttledFn(...savedArgs);
|
|
99
|
+
savedArgs = null;
|
|
100
|
+
}
|
|
101
|
+
}, delayMs);
|
|
102
|
+
}
|
|
103
|
+
return [throttledFn, function cancel() {
|
|
104
|
+
if (timeoutId) {
|
|
105
|
+
clearTimeout(timeoutId);
|
|
106
|
+
}
|
|
107
|
+
}];
|
|
108
|
+
};
|
|
109
|
+
;// ./src/utils/debounce/debounce.ts
|
|
110
|
+
const debounce = (func, wait = 200) => {
|
|
111
|
+
let timeoutId = null;
|
|
112
|
+
const executedFunction = (...args) => {
|
|
113
|
+
const postponedFn = () => {
|
|
114
|
+
if (timeoutId) {
|
|
115
|
+
clearTimeout(timeoutId);
|
|
116
|
+
}
|
|
117
|
+
func(...args);
|
|
118
|
+
};
|
|
119
|
+
if (timeoutId) {
|
|
120
|
+
clearTimeout(timeoutId);
|
|
121
|
+
}
|
|
122
|
+
timeoutId = setTimeout(postponedFn, wait);
|
|
123
|
+
};
|
|
124
|
+
const cancel = function () {
|
|
125
|
+
if (timeoutId) {
|
|
126
|
+
clearTimeout(timeoutId);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
return [executedFunction, cancel];
|
|
130
|
+
};
|
|
131
|
+
;// ./src/utils/debounce/index.ts
|
|
132
|
+
|
|
133
|
+
;// ./src/utils/dates/dateFormatters.ts
|
|
134
|
+
const dayOfWeekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
135
|
+
const periodValues = {
|
|
136
|
+
year: 31536000,
|
|
137
|
+
month: 2592000,
|
|
138
|
+
week: 604800,
|
|
139
|
+
day: 86400,
|
|
140
|
+
hour: 3600,
|
|
141
|
+
min: 60
|
|
142
|
+
};
|
|
143
|
+
const formatTime = timestampMs => new Date(timestampMs).toLocaleTimeString('en-US', {
|
|
144
|
+
hour: '2-digit',
|
|
145
|
+
minute: '2-digit'
|
|
146
|
+
});
|
|
147
|
+
const formatDayOfWeek = timestampMs => dayOfWeekNames[new Date(timestampMs).getDay()];
|
|
148
|
+
const formatDate = timestampMs => new Date(timestampMs).toLocaleDateString('en-US', {
|
|
149
|
+
day: '2-digit',
|
|
150
|
+
month: 'short'
|
|
151
|
+
});
|
|
152
|
+
const printDayOfTheWeek = day => {
|
|
153
|
+
switch (day) {
|
|
154
|
+
case 0:
|
|
155
|
+
return 'Sun';
|
|
156
|
+
case 1:
|
|
157
|
+
return 'Mon';
|
|
158
|
+
case 2:
|
|
159
|
+
return 'Tue';
|
|
160
|
+
case 3:
|
|
161
|
+
return 'Wed';
|
|
162
|
+
case 4:
|
|
163
|
+
return 'Thu';
|
|
164
|
+
case 5:
|
|
165
|
+
return 'Fri';
|
|
166
|
+
case 6:
|
|
167
|
+
return 'Sat';
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
const getTimeAgo = timeValue => {
|
|
171
|
+
const date = new Date(timeValue).getTime();
|
|
172
|
+
if (Number.isNaN(date)) {
|
|
173
|
+
throw new Error('Invalid date');
|
|
174
|
+
}
|
|
175
|
+
const diff = Math.floor((Date.now() - date) / 1000);
|
|
176
|
+
let interval;
|
|
177
|
+
for (const key in periodValues) {
|
|
178
|
+
interval = Math.floor(diff / periodValues[key]);
|
|
179
|
+
if (interval >= 1) {
|
|
180
|
+
const pluralValue = interval > 1 ? 's' : '';
|
|
181
|
+
return `${interval} ${key}${pluralValue} ago`;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return 'Just Now';
|
|
185
|
+
};
|
|
186
|
+
;// ./src/utils/objects/mapObjIndexed.ts
|
|
187
|
+
const mapObjIndexed = (fn, obj) => {
|
|
188
|
+
return Object.keys(obj).reduce((result, key) => {
|
|
189
|
+
result[key] = fn(obj[key], key, obj);
|
|
190
|
+
return result;
|
|
191
|
+
}, {});
|
|
192
|
+
};
|
|
193
|
+
;// ./src/utils/pagination/generateRange.ts
|
|
194
|
+
/**
|
|
195
|
+
* The function that returns an array of page numbers to show in the pagination
|
|
196
|
+
* component.
|
|
197
|
+
*
|
|
198
|
+
* Rules:
|
|
199
|
+
* - To always show the 1st and the last page.
|
|
200
|
+
* - To show one item before and one item after the selected page.
|
|
201
|
+
* - To return "-1" for the skipped items. This is to be able to display "..." in
|
|
202
|
+
* the pagination component.
|
|
203
|
+
* */
|
|
204
|
+
const SKIPPED_ITEMS_DELTA = 2;
|
|
205
|
+
const getSelectedRange = (pagesCount, selectedPage) => {
|
|
206
|
+
const range = [];
|
|
207
|
+
if (selectedPage !== pagesCount) {
|
|
208
|
+
range.push(selectedPage);
|
|
209
|
+
}
|
|
210
|
+
if (selectedPage > 1) {
|
|
211
|
+
range.unshift(selectedPage - 1);
|
|
212
|
+
}
|
|
213
|
+
if (selectedPage + 1 < pagesCount) {
|
|
214
|
+
range.push(selectedPage + 1);
|
|
215
|
+
}
|
|
216
|
+
return range;
|
|
217
|
+
};
|
|
218
|
+
const fill = (range, minValue, maxValue) => {
|
|
219
|
+
for (let i = minValue; i < maxValue; ++i) {
|
|
220
|
+
range.push(i);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
const generateRange = (pagesCount, selectedPage) => {
|
|
224
|
+
if (pagesCount == null || !Number.isInteger(pagesCount)) {
|
|
225
|
+
throw new Error('Pages count should be an integer');
|
|
226
|
+
}
|
|
227
|
+
if (pagesCount <= 0) {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
let range = [1];
|
|
231
|
+
if (pagesCount === 1) {
|
|
232
|
+
return range;
|
|
233
|
+
}
|
|
234
|
+
if (selectedPage != null && !Number.isInteger(selectedPage)) {
|
|
235
|
+
throw new Error('Selected page should be an integer');
|
|
236
|
+
}
|
|
237
|
+
if (selectedPage != null && (selectedPage < 1 || selectedPage > pagesCount)) {
|
|
238
|
+
throw new Error(`Selected page ${selectedPage} is out of range`);
|
|
239
|
+
}
|
|
240
|
+
if (selectedPage && selectedPage > 2) {
|
|
241
|
+
const selectedRange = getSelectedRange(pagesCount, selectedPage);
|
|
242
|
+
const [minSelectedRange,, maxSelectedRange] = selectedRange;
|
|
243
|
+
if (minSelectedRange - SKIPPED_ITEMS_DELTA > 1) {
|
|
244
|
+
range.push(-1);
|
|
245
|
+
} else {
|
|
246
|
+
fill(range, 2, minSelectedRange);
|
|
247
|
+
}
|
|
248
|
+
range = range.concat(selectedRange);
|
|
249
|
+
if (pagesCount - maxSelectedRange > SKIPPED_ITEMS_DELTA) {
|
|
250
|
+
range.push(-1);
|
|
251
|
+
} else {
|
|
252
|
+
fill(range, maxSelectedRange + 1, pagesCount);
|
|
253
|
+
}
|
|
254
|
+
} else if (pagesCount <= 5) {
|
|
255
|
+
fill(range, 2, pagesCount);
|
|
256
|
+
} else {
|
|
257
|
+
range.push(2, 3, -1);
|
|
258
|
+
}
|
|
259
|
+
range.push(pagesCount);
|
|
260
|
+
return range;
|
|
261
|
+
};
|
|
262
|
+
/* harmony default export */ const pagination_generateRange = (generateRange);
|
|
263
|
+
;// ./src/utils/objects/assocPath.ts
|
|
264
|
+
const assocPath = ([first, ...rest], value) => sourceObject => JSON.parse(JSON.stringify({
|
|
265
|
+
...sourceObject,
|
|
266
|
+
[first]: rest.length ? assocPath(rest, value)(sourceObject[first]) : value
|
|
267
|
+
}));
|
|
268
|
+
;// ./src/utils/objects/dissocPath.ts
|
|
269
|
+
const dissocPath = path => sourceObject => {
|
|
270
|
+
const resultObject = JSON.parse(JSON.stringify(sourceObject));
|
|
271
|
+
path.reduce((acc, key, index) => {
|
|
272
|
+
if (index === path.length - 1) {
|
|
273
|
+
delete acc[key];
|
|
274
|
+
}
|
|
275
|
+
return acc[key];
|
|
276
|
+
}, resultObject);
|
|
277
|
+
return resultObject;
|
|
278
|
+
};
|
|
279
|
+
;// ./src/utils/objects/path.ts
|
|
280
|
+
const path_path = path => obj => path.reduce((prev, curr) => prev?.[curr], obj);
|
|
281
|
+
;// ./src/utils/objects/pathOr.ts
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
285
|
+
const pathOr = (defaultValue, path) => obj => {
|
|
286
|
+
const result = path_path(path)(obj);
|
|
287
|
+
return result === null || result === undefined ? defaultValue : result;
|
|
288
|
+
};
|
|
289
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
290
|
+
;// ./src/utils/objects/prop.ts
|
|
291
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
292
|
+
const prop = propName => obj => obj?.[propName];
|
|
293
|
+
;// ./src/utils/objects/propOr.ts
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
297
|
+
const propOr = (defaultValue, propName) => obj => {
|
|
298
|
+
const result = prop(propName)(obj);
|
|
299
|
+
return result === null || result === undefined ? defaultValue : result;
|
|
300
|
+
};
|
|
301
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
302
|
+
;// ./src/utils/objects/index.ts
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
;// ./src/index.ts
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
/******/ return __webpack_exports__;
|
|
321
|
+
/******/ })()
|
|
322
|
+
;
|
|
323
|
+
});
|
|
2
324
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAkB,SAAID,IAEtBD,EAAe,SAAIC,GACpB,CATD,CASGK,MAAM,WACT,O,wBCTA,IAAIC,EAAsB,CCA1BA,EAAwB,SAASL,EAASM,GACzC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAG3E,ECPAF,EAAwB,SAASQ,EAAKC,GAAQ,OAAOL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,EAAO,ECCtGT,EAAwB,SAASL,GACX,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,GACvD,G,wkBCLO,MAAMC,EACXA,IAAIC,IACJ,IAAIC,IACFD,EAAIE,SAASC,GAAOA,OAAQF,KCInBG,EAAuBA,CAACD,EAAIE,KACvC,IAAIC,GAAc,EACdC,EAA8B,KAC9BC,EAAkD,KAuBtD,MAAO,CArBP,SAASC,KAAeR,GAClBK,EACFC,E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EAAGM,GAEfN,EAAMI,KAAK,EAAG,GAAI,GAKpB,OAFAJ,EAAMI,KAAKE,GAEJN,CAAK,ECvFP,MAAMe,EACXA,EAAKC,KAAUC,GAAiBvE,IAC/BwE,GACCC,KAAKC,MACHD,KAAKE,UAAU,IACVH,EACH,CAACF,GAAQC,EAAKK,OACVP,EAAUE,EAAMvE,EAAhBqE,CAAwBG,EAAqBF,IAC7CtE,KCRC6E,EACPC,GACHN,IACC,MAAMO,EAAeN,KAAKC,MAAMD,KAAKE,UAAUH,IAS/C,OAPAM,EAAK3B,QAAO,CAAC6B,EAAU7F,EAAK8F,KACtBA,IAAUH,EAAKF,OAAS,UACnBI,EAAI7F,GAEN6F,EAAI7F,KACV4F,GAEIA,CAAY,ECZVD,EACiCA,GAC3CrF,GACCqF,EAAK3B,QAAO,CAAC+B,EAAMC,IAA0BD,IAAOC,IAAO1F,GCDlD2F,EACXA,CACEC,EACAP,IAEDrF,IACC,MAAM2D,EAASkC,EAAaR,EAAbQ,CAAmB7F,GAClC,OAAO2D,QAA0CiC,EAAejC,CAAM,ECT7D1D,EACuC6F,GACjD9F,GACCA,IAAM8F,GCDGC,EACXA,CACEH,EACAE,IAED9F,IACC,MAAM2D,EAAS1D,EAAK6F,EAAL7F,CAAeD,GAC9B,OAAO2D,QAA0CiC,EAAejC,CAAM,E","sources":["webpack://SSAUtils/webpack/universalModuleDefinition","webpack://SSAUtils/webpack/bootstrap","webpack://SSAUtils/webpack/runtime/define property getters","webpack://SSAUtils/webpack/runtime/hasOwnProperty shorthand","webpack://SSAUtils/webpack/runtime/make namespace object","webpack://SSAUtils/./src/utils/CallAll.ts","webpack://SSAUtils/./src/utils/throttle/throttle.ts","webpack://SSAUtils/./src/utils/debounce/debounce.ts","webpack://SSAUtils/./src/utils/dates/dateFormatters.ts","webpack://SSAUtils/./src/utils/objects/mapObjIndexed.ts","webpack://SSAUtils/./src/utils/pagination/generateRange.ts","webpack://SSAUtils/./src/utils/objects/assocPath.ts","webpack://SSAUtils/./src/utils/objects/dissocPath.ts","webpack://SSAUtils/./src/utils/objects/path.ts","webpack://SSAUtils/./src/utils/objects/pathOr.ts","webpack://SSAUtils/./src/utils/objects/prop.ts","webpack://SSAUtils/./src/utils/objects/propOr.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"SSAUtils\"] = factory();\n\telse\n\t\troot[\"SSAUtils\"] = factory();\n})(self, function() {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = function(exports, definition) {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }","// define __esModule on exports\n__webpack_require__.r = function(exports) {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/* eslint-disable @typescript-eslint/no-explicit-any */\r\nexport const callAll =\r\n (...fns: any[]) =>\r\n (...args: any) =>\r\n fns.forEach((fn) => fn?.(...args));\r\n","// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\ntype UnknownFn = (...args: any[]) => unknown;\r\ntype ThrottleFn = (\r\n fn: UnknownFn,\r\n delayMs: number,\r\n) => [(...args: unknown[]) => void, () => void];\r\n/* eslint-enable @typescript-eslint/no-explicit-any */\r\n\r\nexport const throttle: ThrottleFn = (fn, delayMs) => {\r\n let isThrottled = false;\r\n let savedArgs: unknown[] | null = null;\r\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\r\n\r\n function throttledFn(...args: unknown[]) {\r\n if (isThrottled) {\r\n savedArgs = args;\r\n return;\r\n }\r\n\r\n isThrottled = true;\r\n\r\n fn(...args);\r\n\r\n timeoutId = setTimeout(() => {\r\n isThrottled = false;\r\n\r\n // istanbul ignore else\r\n if (savedArgs) {\r\n throttledFn(...savedArgs);\r\n savedArgs = null;\r\n }\r\n }, delayMs);\r\n }\r\n\r\n return [\r\n throttledFn,\r\n function cancel() {\r\n if (timeoutId) {\r\n clearTimeout(timeoutId);\r\n }\r\n },\r\n ];\r\n};\r\n","type UnknownFn = (...args: any[]) => unknown;\r\n\r\nexport const debounce = (func: UnknownFn, wait = 200) => {\r\n let timeoutId: NodeJS.Timeout | null = null;\r\n const executedFunction = (...args: any[]) => {\r\n const postponedFn = () => {\r\n if (timeoutId) {\r\n clearTimeout(timeoutId);\r\n }\r\n func(...args);\r\n };\r\n if (timeoutId) {\r\n clearTimeout(timeoutId);\r\n }\r\n timeoutId = setTimeout(postponedFn, wait);\r\n };\r\n\r\n const cancel = function () {\r\n if (timeoutId) {\r\n clearTimeout(timeoutId);\r\n }\r\n };\r\n return [executedFunction, cancel];\r\n};\r\n","const dayOfWeekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\r\nconst periodValues: Record<string, number> = {\r\n year: 31536000,\r\n month: 2592000,\r\n week: 604800,\r\n day: 86400,\r\n hour: 3600,\r\n min: 60,\r\n};\r\n\r\nexport const formatTime = (timestampMs: number) =>\r\n new Date(timestampMs).toLocaleTimeString('en-US', {\r\n hour: '2-digit',\r\n minute: '2-digit',\r\n });\r\n\r\nexport const formatDayOfWeek = (timestampMs: number) =>\r\n dayOfWeekNames[new Date(timestampMs).getDay()];\r\n\r\nexport const formatDate = (timestampMs: number) =>\r\n new Date(timestampMs).toLocaleDateString('en-US', {\r\n day: '2-digit',\r\n month: 'short',\r\n });\r\n\r\nexport const printDayOfTheWeek = (day: number) => {\r\n switch (day) {\r\n case 0:\r\n return 'Sun';\r\n case 1:\r\n return 'Mon';\r\n case 2:\r\n return 'Tue';\r\n case 3:\r\n return 'Wed';\r\n case 4:\r\n return 'Thu';\r\n case 5:\r\n return 'Fri';\r\n case 6:\r\n return 'Sat';\r\n }\r\n};\r\n\r\nexport const getTimeAgo = (timeValue: string | number) => {\r\n const date = new Date(timeValue).getTime();\r\n if (Number.isNaN(date)) {\r\n throw new Error('Invalid date');\r\n }\r\n const diff = Math.floor((Date.now() - date) / 1000);\r\n let interval;\r\n for (const key in periodValues) {\r\n interval = Math.floor(diff / periodValues[key]);\r\n if (interval >= 1) {\r\n const pluralValue = interval > 1 ? 's' : '';\r\n return `${interval} ${key}${pluralValue} ago`;\r\n }\r\n }\r\n\r\n return 'Just Now';\r\n};\r\n","type MapObjIndexedFn<T, U> = (\r\n value: T,\r\n key: string,\r\n obj: Record<string, T>,\r\n) => U;\r\n\r\nexport const mapObjIndexed = <T, U>(\r\n fn: MapObjIndexedFn<T, U>,\r\n obj: Record<string, T>,\r\n): Record<string, U> => {\r\n return Object.keys(obj).reduce((result: Record<string, U>, key: string) => {\r\n result[key] = fn(obj[key], key, obj);\r\n return result;\r\n }, {});\r\n};\r\n","import { GenerateRangeFn } from './types';\r\n\r\n/**\r\n * The function that returns an array of page numbers to show in the pagination\r\n * component.\r\n *\r\n * Rules:\r\n * - To always show the 1st and the last page.\r\n * - To show one item before and one item after the selected page.\r\n * - To return \"-1\" for the skipped items. This is to be able to display \"...\" in\r\n * the pagination component.\r\n * */\r\nconst SKIPPED_ITEMS_DELTA = 2;\r\n\r\nconst getSelectedRange = (pagesCount: number, selectedPage: number) => {\r\n const range: number[] = [];\r\n\r\n if (selectedPage !== pagesCount) {\r\n range.push(selectedPage);\r\n }\r\n\r\n if (selectedPage > 1) {\r\n range.unshift(selectedPage - 1);\r\n }\r\n\r\n if (selectedPage + 1 < pagesCount) {\r\n range.push(selectedPage + 1);\r\n }\r\n\r\n return range;\r\n};\r\n\r\nconst fill = (range: number[], minValue: number, maxValue: number) => {\r\n for (let i = minValue; i < maxValue; ++i) {\r\n range.push(i);\r\n }\r\n};\r\n\r\nconst generateRange: GenerateRangeFn = (pagesCount, selectedPage) => {\r\n if (pagesCount == null || !Number.isInteger(pagesCount)) {\r\n throw new Error('Pages count should be an integer');\r\n }\r\n\r\n if (pagesCount <= 0) {\r\n return [];\r\n }\r\n\r\n let range = [1];\r\n\r\n if (pagesCount === 1) {\r\n return range;\r\n }\r\n\r\n if (selectedPage != null && !Number.isInteger(selectedPage)) {\r\n throw new Error('Selected page should be an integer');\r\n }\r\n\r\n if (selectedPage != null && (selectedPage < 1 || selectedPage > pagesCount)) {\r\n throw new Error(`Selected page ${selectedPage} is out of range`);\r\n }\r\n\r\n if (selectedPage && selectedPage > 2) {\r\n const selectedRange = getSelectedRange(pagesCount, selectedPage);\r\n\r\n const [minSelectedRange, , maxSelectedRange] = selectedRange;\r\n\r\n if (minSelectedRange - SKIPPED_ITEMS_DELTA > 1) {\r\n range.push(-1);\r\n } else {\r\n fill(range, 2, minSelectedRange);\r\n }\r\n\r\n range = range.concat(selectedRange);\r\n\r\n if (pagesCount - maxSelectedRange > SKIPPED_ITEMS_DELTA) {\r\n range.push(-1);\r\n } else {\r\n fill(range, maxSelectedRange + 1, pagesCount);\r\n }\r\n } else if (pagesCount <= 5) {\r\n fill(range, 2, pagesCount);\r\n } else {\r\n range.push(2, 3, -1);\r\n }\r\n\r\n range.push(pagesCount);\r\n\r\n return range;\r\n};\r\n\r\nexport default generateRange;\r\n","export const assocPath =\r\n <T>([first, ...rest]: string[], value: any) =>\r\n (sourceObject: T): T =>\r\n JSON.parse(\r\n JSON.stringify({\r\n ...sourceObject,\r\n [first]: rest.length\r\n ? assocPath(rest, value)((sourceObject as any)[first])\r\n : value,\r\n }),\r\n ) as T;\r\n","export const dissocPath =\r\n <T>(path: string[]) =>\r\n (sourceObject: T): T => {\r\n const resultObject = JSON.parse(JSON.stringify(sourceObject));\r\n\r\n path.reduce((acc: any, key, index) => {\r\n if (index === path.length - 1) {\r\n delete acc[key];\r\n }\r\n return acc[key];\r\n }, resultObject);\r\n\r\n return resultObject;\r\n };\r\n","export const path =\r\n <T extends Record<string | number, any>, R>(path: Array<string | number>) =>\r\n (obj: T): unknown =>\r\n path.reduce((prev, curr: string | number) => prev?.[curr], obj);\r\n","import { path as originalPath } from './path';\r\n\r\nexport const pathOr =\r\n <T extends Record<string | number, any>, R>(\r\n defaultValue: any,\r\n path: Array<string | number>,\r\n ) =>\r\n (obj: T): R => {\r\n const result = originalPath(path)(obj);\r\n return result === null || result === undefined ? defaultValue : result;\r\n };\r\n","export const prop =\r\n <T extends Record<string | number, any>, R = any>(propName: string) =>\r\n (obj: T): R =>\r\n obj?.[propName];\r\n","import { prop } from './prop';\r\n\r\nexport const propOr =\r\n <T extends Record<string | number, any>, R = any>(\r\n defaultValue: any,\r\n propName: string,\r\n ) =>\r\n (obj: T): R => {\r\n const result = prop(propName)(obj);\r\n return result === null || result === undefined ? defaultValue : result;\r\n };\r\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","callAll","fns","args","forEach","fn","throttle","delayMs","isThrottled","savedArgs","timeoutId","throttledFn","setTimeout","clearTimeout","debounce","func","wait","executedFunction","postponedFn","dayOfWeekNames","periodValues","year","month","week","day","hour","min","formatTime","timestampMs","Date","toLocaleTimeString","minute","formatDayOfWeek","getDay","formatDate","toLocaleDateString","printDayOfTheWeek","getTimeAgo","timeValue","date","getTime","Number","isNaN","Error","diff","Math","floor","now","interval","mapObjIndexed","keys","reduce","result","fill","range","minValue","maxValue","i","push","generateRange","pagesCount","selectedPage","isInteger","selectedRange","getSelectedRange","unshift","minSelectedRange","maxSelectedRange","concat","assocPath","first","rest","sourceObject","JSON","parse","stringify","length","dissocPath","path","resultObject","acc","index","prev","curr","pathOr","defaultValue","originalPath","propName","propOr"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.js","mapp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AACO,MAAMsC,IAAI,GACmCC,QAAgB,IACjE3C,GAAM,IACLA,GAAG,GAAG2C,QAAQ,CAAM;;ACJM;;AAE9B;AACO,MAAMC,MAAM,GACjBA,CACEJ,YAAiB,EACjBG,QAAgB,KAEjB3C,GAAM,IAAQ;EACb,MAAMI,MAAM,GAAGsC,IAAI,CAACC,QAAQ,CAAC,CAAC3C,GAAG,CAAC;EAClC,OAAOI,MAAM,KAAK,IAAI,IAAIA,MAAM,KAAKqC,SAAS,GAAGD,YAAY,GAAGpC,MAAM;AACxE,CAAC;AACH;;ACZgC;AACJ;AACC;AACN;AACE;AACF;;;ACLmB;AACE;AACX;AAC8B;AAArC;AACoC;AACX;AACnB","sources":["webpack://SSAUtils/webpack/universalModuleDefinition","webpack://SSAUtils/webpack/bootstrap","webpack://SSAUtils/webpack/runtime/define property getters","webpack://SSAUtils/webpack/runtime/hasOwnProperty shorthand","webpack://SSAUtils/webpack/runtime/make namespace object","webpack://SSAUtils/./src/utils/CallAll.ts","webpack://SSAUtils/./src/utils/throttle/throttle.ts","webpack://SSAUtils/./src/utils/debounce/debounce.ts","webpack://SSAUtils/./src/utils/debounce/index.ts","webpack://SSAUtils/./src/utils/dates/dateFormatters.ts","webpack://SSAUtils/./src/utils/objects/mapObjIndexed.ts","webpack://SSAUtils/./src/utils/pagination/generateRange.ts","webpack://SSAUtils/./src/utils/objects/assocPath.ts","webpack://SSAUtils/./src/utils/objects/dissocPath.ts","webpack://SSAUtils/./src/utils/objects/path.ts","webpack://SSAUtils/./src/utils/objects/pathOr.ts","webpack://SSAUtils/./src/utils/objects/prop.ts","webpack://SSAUtils/./src/utils/objects/propOr.ts","webpack://SSAUtils/./src/utils/objects/index.ts","webpack://SSAUtils/./src/index.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"SSAUtils\"] = factory();\n\telse\n\t\troot[\"SSAUtils\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/* eslint-disable @typescript-eslint/no-explicit-any */\r\nexport const callAll =\r\n (...fns: any[]) =>\r\n (...args: any) =>\r\n fns.forEach((fn) => fn?.(...args));\r\n/* eslint-enable @typescript-eslint/no-explicit-any */\r\n","export const throttle = <T extends unknown[]>(\r\n fn: (...args: T) => unknown,\r\n delayMs: number,\r\n) => {\r\n let isThrottled = false;\r\n let savedArgs: T | null = null;\r\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\r\n\r\n function throttledFn(...args: T) {\r\n if (isThrottled) {\r\n savedArgs = args;\r\n return;\r\n }\r\n\r\n isThrottled = true;\r\n\r\n fn(...args);\r\n\r\n timeoutId = setTimeout(() => {\r\n isThrottled = false;\r\n\r\n // istanbul ignore else\r\n if (savedArgs) {\r\n throttledFn(...savedArgs);\r\n savedArgs = null;\r\n }\r\n }, delayMs);\r\n }\r\n\r\n return [\r\n throttledFn,\r\n function cancel() {\r\n if (timeoutId) {\r\n clearTimeout(timeoutId);\r\n }\r\n },\r\n ] as const;\r\n};\r\n","export const debounce = <T extends unknown[]>(\r\n func: (...args: T) => unknown,\r\n wait = 200,\r\n) => {\r\n let timeoutId: NodeJS.Timeout | null = null;\r\n const executedFunction = (...args: T) => {\r\n const postponedFn = () => {\r\n if (timeoutId) {\r\n clearTimeout(timeoutId);\r\n }\r\n func(...args);\r\n };\r\n if (timeoutId) {\r\n clearTimeout(timeoutId);\r\n }\r\n timeoutId = setTimeout(postponedFn, wait);\r\n };\r\n\r\n const cancel = function () {\r\n if (timeoutId) {\r\n clearTimeout(timeoutId);\r\n }\r\n };\r\n return [executedFunction, cancel] as const;\r\n};\r\n","export { debounce } from './debounce';\r\n","const dayOfWeekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\r\nconst periodValues: Record<string, number> = {\r\n year: 31536000,\r\n month: 2592000,\r\n week: 604800,\r\n day: 86400,\r\n hour: 3600,\r\n min: 60,\r\n};\r\n\r\nexport const formatTime = (timestampMs: number) =>\r\n new Date(timestampMs).toLocaleTimeString('en-US', {\r\n hour: '2-digit',\r\n minute: '2-digit',\r\n });\r\n\r\nexport const formatDayOfWeek = (timestampMs: number) =>\r\n dayOfWeekNames[new Date(timestampMs).getDay()];\r\n\r\nexport const formatDate = (timestampMs: number) =>\r\n new Date(timestampMs).toLocaleDateString('en-US', {\r\n day: '2-digit',\r\n month: 'short',\r\n });\r\n\r\nexport const printDayOfTheWeek = (day: number) => {\r\n switch (day) {\r\n case 0:\r\n return 'Sun';\r\n case 1:\r\n return 'Mon';\r\n case 2:\r\n return 'Tue';\r\n case 3:\r\n return 'Wed';\r\n case 4:\r\n return 'Thu';\r\n case 5:\r\n return 'Fri';\r\n case 6:\r\n return 'Sat';\r\n }\r\n};\r\n\r\nexport const getTimeAgo = (timeValue: string | number) => {\r\n const date = new Date(timeValue).getTime();\r\n if (Number.isNaN(date)) {\r\n throw new Error('Invalid date');\r\n }\r\n const diff = Math.floor((Date.now() - date) / 1000);\r\n let interval;\r\n for (const key in periodValues) {\r\n interval = Math.floor(diff / periodValues[key]);\r\n if (interval >= 1) {\r\n const pluralValue = interval > 1 ? 's' : '';\r\n return `${interval} ${key}${pluralValue} ago`;\r\n }\r\n }\r\n\r\n return 'Just Now';\r\n};\r\n","type MapObjIndexedFn<T, U> = (\r\n value: T,\r\n key: string,\r\n obj: Record<string, T>,\r\n) => U;\r\n\r\nexport const mapObjIndexed = <T, U>(\r\n fn: MapObjIndexedFn<T, U>,\r\n obj: Record<string, T>,\r\n): Record<string, U> => {\r\n return Object.keys(obj).reduce((result: Record<string, U>, key: string) => {\r\n result[key] = fn(obj[key], key, obj);\r\n return result;\r\n }, {});\r\n};\r\n","import { GenerateRangeFn } from './types';\r\n\r\n/**\r\n * The function that returns an array of page numbers to show in the pagination\r\n * component.\r\n *\r\n * Rules:\r\n * - To always show the 1st and the last page.\r\n * - To show one item before and one item after the selected page.\r\n * - To return \"-1\" for the skipped items. This is to be able to display \"...\" in\r\n * the pagination component.\r\n * */\r\nconst SKIPPED_ITEMS_DELTA = 2;\r\n\r\nconst getSelectedRange = (pagesCount: number, selectedPage: number) => {\r\n const range: number[] = [];\r\n\r\n if (selectedPage !== pagesCount) {\r\n range.push(selectedPage);\r\n }\r\n\r\n if (selectedPage > 1) {\r\n range.unshift(selectedPage - 1);\r\n }\r\n\r\n if (selectedPage + 1 < pagesCount) {\r\n range.push(selectedPage + 1);\r\n }\r\n\r\n return range;\r\n};\r\n\r\nconst fill = (range: number[], minValue: number, maxValue: number) => {\r\n for (let i = minValue; i < maxValue; ++i) {\r\n range.push(i);\r\n }\r\n};\r\n\r\nconst generateRange: GenerateRangeFn = (pagesCount, selectedPage) => {\r\n if (pagesCount == null || !Number.isInteger(pagesCount)) {\r\n throw new Error('Pages count should be an integer');\r\n }\r\n\r\n if (pagesCount <= 0) {\r\n return [];\r\n }\r\n\r\n let range = [1];\r\n\r\n if (pagesCount === 1) {\r\n return range;\r\n }\r\n\r\n if (selectedPage != null && !Number.isInteger(selectedPage)) {\r\n throw new Error('Selected page should be an integer');\r\n }\r\n\r\n if (selectedPage != null && (selectedPage < 1 || selectedPage > pagesCount)) {\r\n throw new Error(`Selected page ${selectedPage} is out of range`);\r\n }\r\n\r\n if (selectedPage && selectedPage > 2) {\r\n const selectedRange = getSelectedRange(pagesCount, selectedPage);\r\n\r\n const [minSelectedRange, , maxSelectedRange] = selectedRange;\r\n\r\n if (minSelectedRange - SKIPPED_ITEMS_DELTA > 1) {\r\n range.push(-1);\r\n } else {\r\n fill(range, 2, minSelectedRange);\r\n }\r\n\r\n range = range.concat(selectedRange);\r\n\r\n if (pagesCount - maxSelectedRange > SKIPPED_ITEMS_DELTA) {\r\n range.push(-1);\r\n } else {\r\n fill(range, maxSelectedRange + 1, pagesCount);\r\n }\r\n } else if (pagesCount <= 5) {\r\n fill(range, 2, pagesCount);\r\n } else {\r\n range.push(2, 3, -1);\r\n }\r\n\r\n range.push(pagesCount);\r\n\r\n return range;\r\n};\r\n\r\nexport default generateRange;\r\n","export const assocPath =\r\n <T>([first, ...rest]: string[], value: unknown) =>\r\n (sourceObject: T): T =>\r\n JSON.parse(\r\n JSON.stringify({\r\n ...sourceObject,\r\n [first]: rest.length\r\n ? assocPath(rest, value)(sourceObject[first as keyof T])\r\n : value,\r\n }),\r\n ) as T;\r\n","export const dissocPath =\r\n <T>(path: string[]) =>\r\n (sourceObject: T): T => {\r\n const resultObject = JSON.parse(JSON.stringify(sourceObject));\r\n path.reduce((acc, key, index) => {\r\n if (index === path.length - 1) {\r\n delete acc[key];\r\n }\r\n return acc[key];\r\n }, resultObject);\r\n\r\n return resultObject;\r\n };\r\n","export const path =\r\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\r\n <T extends Record<string | number, any>, R = unknown>(\r\n path: Array<string | number>,\r\n ) =>\r\n (obj: T): R =>\r\n path.reduce(\r\n (prev, curr: string | number) => prev?.[curr],\r\n obj,\r\n ) as unknown as R;\r\n","import { path as originalPath } from './path';\r\n\r\n/* eslint-disable @typescript-eslint/no-explicit-any */\r\nexport const pathOr =\r\n <T extends Record<string | number, any>, R>(\r\n defaultValue: any,\r\n path: Array<string | number>,\r\n ) =>\r\n (obj: T): R => {\r\n const result = originalPath(path)(obj);\r\n return result === null || result === undefined ? defaultValue : result;\r\n };\r\n/* eslint-enable @typescript-eslint/no-explicit-any */\r\n","/* eslint-disable @typescript-eslint/no-explicit-any */\r\nexport const prop =\r\n <T extends Record<string | number, any>, R = any>(propName: string) =>\r\n (obj: T): R =>\r\n obj?.[propName] as R;\r\n","import { prop } from './prop';\r\n\r\n/* eslint-disable @typescript-eslint/no-explicit-any */\r\nexport const propOr =\r\n <T extends Record<string | number, any>, R = any>(\r\n defaultValue: any,\r\n propName: string,\r\n ) =>\r\n (obj: T): R => {\r\n const result = prop(propName)(obj);\r\n return result === null || result === undefined ? defaultValue : result;\r\n };\r\n/* eslint-enable @typescript-eslint/no-explicit-any */\r\n","export * from './mapObjIndexed';\r\nexport * from './assocPath';\r\nexport * from './dissocPath';\r\nexport * from './path';\r\nexport * from './pathOr';\r\nexport * from './prop';\r\nexport * from './propOr';\r\n","export { callAll } from './utils/CallAll';\r\nexport { throttle } from './utils/throttle';\r\nexport * from './utils/debounce';\r\nexport * as dateFormatters from './utils/dates/dateFormatters';\r\nexport { mapObjIndexed } from './utils/objects/mapObjIndexed';\r\nexport { generateRange } from './utils/pagination';\r\nexport * from './utils/objects';\r\nexport * from './utils/types';\r\n"],"names":["callAll","fns","args","forEach","fn","throttle","delayMs","isThrottled","savedArgs","timeoutId","throttledFn","setTimeout","cancel","clearTimeout","debounce","func","wait","executedFunction","postponedFn","dayOfWeekNames","periodValues","year","month","week","day","hour","min","formatTime","timestampMs","Date","toLocaleTimeString","minute","formatDayOfWeek","getDay","formatDate","toLocaleDateString","printDayOfTheWeek","getTimeAgo","timeValue","date","getTime","Number","isNaN","Error","diff","Math","floor","now","interval","key","pluralValue","mapObjIndexed","obj","Object","keys","reduce","result","SKIPPED_ITEMS_DELTA","getSelectedRange","pagesCount","selectedPage","range","push","unshift","fill","minValue","maxValue","i","generateRange","isInteger","selectedRange","minSelectedRange","maxSelectedRange","concat","assocPath","first","rest","value","sourceObject","JSON","parse","stringify","length","dissocPath","path","resultObject","acc","index","prev","curr","originalPath","pathOr","defaultValue","undefined","prop","propName","propOr","_dateFormatters","dateFormatters"],"sourceRoot":""}
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const debounce: (func: UnknownFn, wait?: number) => ((...args: any[]) => void)[];
|
|
3
|
-
export {};
|
|
1
|
+
export declare const debounce: <T extends unknown[]>(func: (...args: T) => unknown, wait?: number) => readonly [(...args: T) => void, () => void];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const assocPath: <T>([first, ...rest]: string[], value:
|
|
1
|
+
export declare const assocPath: <T>([first, ...rest]: string[], value: unknown) => (sourceObject: T) => T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const path: <T extends Record<string | number, any>, R>(path: Array<string | number>) => (obj: T) =>
|
|
1
|
+
export declare const path: <T extends Record<string | number, any>, R = unknown>(path: Array<string | number>) => (obj: T) => R;
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
type ThrottleFn = (fn: UnknownFn, delayMs: number) => [(...args: unknown[]) => void, () => void];
|
|
3
|
-
export declare const throttle: ThrottleFn;
|
|
4
|
-
export {};
|
|
1
|
+
export declare const throttle: <T extends unknown[]>(fn: (...args: T) => unknown, delayMs: number) => readonly [(...args: T) => void, () => void];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ssa-ui-kit/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.55-canary-b1a0b68-20250224",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"private": false,
|
|
@@ -18,13 +18,9 @@
|
|
|
18
18
|
"url": "https://github.com/ssagroup/ui-kit.git",
|
|
19
19
|
"directory": "packages/utils"
|
|
20
20
|
},
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
"resolve-tspaths": "^0.8.16",
|
|
25
|
-
"terser-webpack-plugin": "^5.3.9",
|
|
26
|
-
"webpack": "^5.85.0"
|
|
27
|
-
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
28
24
|
"browserslist": [
|
|
29
25
|
">0.1%",
|
|
30
26
|
"not dead",
|
package/src/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { callAll } from './utils/CallAll';
|
|
2
|
-
export { throttle } from './utils/throttle';
|
|
3
|
-
export * from './utils/debounce';
|
|
4
|
-
export * as dateFormatters from './utils/dates/dateFormatters';
|
|
5
|
-
export { mapObjIndexed } from './utils/objects/mapObjIndexed';
|
|
6
|
-
export { generateRange } from './utils/pagination';
|
|
7
|
-
export * from './utils/objects';
|
|
8
|
-
export * from './utils/types';
|
package/src/utils/CallAll.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
const dayOfWeekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
2
|
-
const periodValues: Record<string, number> = {
|
|
3
|
-
year: 31536000,
|
|
4
|
-
month: 2592000,
|
|
5
|
-
week: 604800,
|
|
6
|
-
day: 86400,
|
|
7
|
-
hour: 3600,
|
|
8
|
-
min: 60,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const formatTime = (timestampMs: number) =>
|
|
12
|
-
new Date(timestampMs).toLocaleTimeString('en-US', {
|
|
13
|
-
hour: '2-digit',
|
|
14
|
-
minute: '2-digit',
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
export const formatDayOfWeek = (timestampMs: number) =>
|
|
18
|
-
dayOfWeekNames[new Date(timestampMs).getDay()];
|
|
19
|
-
|
|
20
|
-
export const formatDate = (timestampMs: number) =>
|
|
21
|
-
new Date(timestampMs).toLocaleDateString('en-US', {
|
|
22
|
-
day: '2-digit',
|
|
23
|
-
month: 'short',
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export const printDayOfTheWeek = (day: number) => {
|
|
27
|
-
switch (day) {
|
|
28
|
-
case 0:
|
|
29
|
-
return 'Sun';
|
|
30
|
-
case 1:
|
|
31
|
-
return 'Mon';
|
|
32
|
-
case 2:
|
|
33
|
-
return 'Tue';
|
|
34
|
-
case 3:
|
|
35
|
-
return 'Wed';
|
|
36
|
-
case 4:
|
|
37
|
-
return 'Thu';
|
|
38
|
-
case 5:
|
|
39
|
-
return 'Fri';
|
|
40
|
-
case 6:
|
|
41
|
-
return 'Sat';
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const getTimeAgo = (timeValue: string | number) => {
|
|
46
|
-
const date = new Date(timeValue).getTime();
|
|
47
|
-
if (Number.isNaN(date)) {
|
|
48
|
-
throw new Error('Invalid date');
|
|
49
|
-
}
|
|
50
|
-
const diff = Math.floor((Date.now() - date) / 1000);
|
|
51
|
-
let interval;
|
|
52
|
-
for (const key in periodValues) {
|
|
53
|
-
interval = Math.floor(diff / periodValues[key]);
|
|
54
|
-
if (interval >= 1) {
|
|
55
|
-
const pluralValue = interval > 1 ? 's' : '';
|
|
56
|
-
return `${interval} ${key}${pluralValue} ago`;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return 'Just Now';
|
|
61
|
-
};
|