@ssa-ui-kit/utils 3.12.0 → 3.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +24 -5
- package/dist/index.js.map +1 -1
- package/dist/utils/isNill.d.ts +13 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -56,6 +56,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
56
56
|
debounce: () => (/* reexport */ debounce),
|
|
57
57
|
dissocPath: () => (/* reexport */ dissocPath),
|
|
58
58
|
generateRange: () => (/* reexport */ pagination_generateRange),
|
|
59
|
+
isNill: () => (/* reexport */ isNill),
|
|
59
60
|
mapObjIndexed: () => (/* reexport */ mapObjIndexed),
|
|
60
61
|
path: () => (/* reexport */ path_path),
|
|
61
62
|
pathOr: () => (/* reexport */ pathOr),
|
|
@@ -80,6 +81,20 @@ __webpack_require__.d(dateFormatters_namespaceObject, {
|
|
|
80
81
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
81
82
|
const callAll = (...fns) => (...args) => fns.forEach(fn => fn?.(...args));
|
|
82
83
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
84
|
+
;// ./src/utils/isNill.ts
|
|
85
|
+
/**
|
|
86
|
+
* Checks whether a value is `null` or `undefined`.
|
|
87
|
+
*
|
|
88
|
+
* Unlike a plain falsy check, this returns `false` for other falsy
|
|
89
|
+
* values such as `0`, `''`, `false` and `NaN`.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* isNill(null); // true
|
|
93
|
+
* isNill(undefined); // true
|
|
94
|
+
* isNill(0); // false
|
|
95
|
+
* isNill(''); // false
|
|
96
|
+
*/
|
|
97
|
+
const isNill = value => value === null || value === undefined;
|
|
83
98
|
;// ./src/utils/throttle/throttle.ts
|
|
84
99
|
const throttle = (fn, delayMs) => {
|
|
85
100
|
let isThrottled = false;
|
|
@@ -193,6 +208,7 @@ const mapObjIndexed = (fn, obj) => {
|
|
|
193
208
|
}, {});
|
|
194
209
|
};
|
|
195
210
|
;// ./src/utils/pagination/generateRange.ts
|
|
211
|
+
|
|
196
212
|
/**
|
|
197
213
|
* The function that returns an array of page numbers to show in the pagination
|
|
198
214
|
* component.
|
|
@@ -223,7 +239,7 @@ const fill = (range, minValue, maxValue) => {
|
|
|
223
239
|
}
|
|
224
240
|
};
|
|
225
241
|
const generateRange = (pagesCount, selectedPage) => {
|
|
226
|
-
if (pagesCount
|
|
242
|
+
if (isNill(pagesCount) || !Number.isInteger(pagesCount)) {
|
|
227
243
|
throw new Error('Pages count should be an integer');
|
|
228
244
|
}
|
|
229
245
|
if (pagesCount <= 0) {
|
|
@@ -233,10 +249,10 @@ const generateRange = (pagesCount, selectedPage) => {
|
|
|
233
249
|
if (pagesCount === 1) {
|
|
234
250
|
return range;
|
|
235
251
|
}
|
|
236
|
-
if (selectedPage
|
|
252
|
+
if (!isNill(selectedPage) && !Number.isInteger(selectedPage)) {
|
|
237
253
|
throw new Error('Selected page should be an integer');
|
|
238
254
|
}
|
|
239
|
-
if (selectedPage
|
|
255
|
+
if (!isNill(selectedPage) && (selectedPage < 1 || selectedPage > pagesCount)) {
|
|
240
256
|
throw new Error(`Selected page ${selectedPage} is out of range`);
|
|
241
257
|
}
|
|
242
258
|
if (selectedPage && selectedPage > 2) {
|
|
@@ -283,10 +299,11 @@ const path_path = path => obj => path.reduce((prev, curr) => prev?.[curr], obj);
|
|
|
283
299
|
;// ./src/utils/objects/pathOr.ts
|
|
284
300
|
|
|
285
301
|
|
|
302
|
+
|
|
286
303
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
287
304
|
const pathOr = (defaultValue, path) => obj => {
|
|
288
305
|
const result = path_path(path)(obj);
|
|
289
|
-
return result
|
|
306
|
+
return isNill(result) ? defaultValue : result;
|
|
290
307
|
};
|
|
291
308
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
292
309
|
;// ./src/utils/objects/prop.ts
|
|
@@ -295,10 +312,11 @@ const prop = propName => obj => obj?.[propName];
|
|
|
295
312
|
;// ./src/utils/objects/propOr.ts
|
|
296
313
|
|
|
297
314
|
|
|
315
|
+
|
|
298
316
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
299
317
|
const propOr = (defaultValue, propName) => obj => {
|
|
300
318
|
const result = prop(propName)(obj);
|
|
301
|
-
return result
|
|
319
|
+
return isNill(result) ? defaultValue : result;
|
|
302
320
|
};
|
|
303
321
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
304
322
|
;// ./src/utils/objects/index.ts
|
|
@@ -350,6 +368,7 @@ class ClassnameArray extends Array {
|
|
|
350
368
|
|
|
351
369
|
|
|
352
370
|
|
|
371
|
+
|
|
353
372
|
/******/ return __webpack_exports__;
|
|
354
373
|
/******/ })()
|
|
355
374
|
;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;;UCVA;UACA;;;;;WCDA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D,E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACNA;AACO,MAAMA,OAAO,GAClBA,CAAC,GAAGC,GAAU,KACd,CAAC,GAAGC,IAAS,KACXD,GAAG,CAACE,OAAO,CAAEC,EAAE,IAAKA,EAAE,GAAG,GAAGF,IAAI,CAAC,CAAC;AACtC,sD;;ACLO,MAAMG,QAAQ,GAAGA,CACtBD,EAA2B,EAC3BE,OAAe,KACZ;EACH,IAAIC,WAAW,GAAG,KAAK;EACvB,IAAIC,SAAmB,GAAG,IAAI;EAC9B,IAAIC,SAA+C,GAAG,IAAI;EAE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AACH,CAAC,C;;ACPM,MAAMC,cAAc,SAASC,KAAK,CAAS;EAChDC,MAAMA,CAACC,SAAiB,EAAEC,SAAkB,EAAE;IAC5C,MAAMhB,KAAK,GAAG,IAAI,CAACiB,OAAO,CAACF,SAAS,CAAC;IACrC,IAAIC,SAAS,EAAE;MACb,IAAIhB,KAAK,KAAK,CAAC,CAAC,EAAE;QAChB,IAAI,CAACzB,IAAI,CAACwC,SAAS,CAAC;MACtB;IACF,CAAC,MAAM;MACL,IAAIf,KAAK,GAAG,CAAC,CAAC,EAAE;QACd,IAAI,CAACkB,MAAM,CAAClB,KAAK,EAAE,CAAC,CAAC;MACvB;IACF;IACA,OAAO,IAAI;EACb;EAEAmB,KAAKA,CAAA,EAAG;IACN,IAAI,CAACxB,MAAM,GAAG,CAAC;IACf,OAAO,IAAI;EACb;AACF,C;;ACnB0C;AACE;AACX;AAC8B;AAArC;AACoC;AACX;AACnB;AACF;AACA","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/utils/story.ts","webpack://SSAUtils/./src/utils/ClassnameArray/ClassnameArray.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 */\nexport const callAll =\n (...fns: any[]) =>\n (...args: any) =>\n fns.forEach((fn) => fn?.(...args));\n/* eslint-enable @typescript-eslint/no-explicit-any */\n","export const throttle = <T extends unknown[]>(\n fn: (...args: T) => unknown,\n delayMs: number,\n) => {\n let isThrottled = false;\n let savedArgs: T | null = null;\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n function throttledFn(...args: T) {\n if (isThrottled) {\n savedArgs = args;\n return;\n }\n\n isThrottled = true;\n\n fn(...args);\n\n timeoutId = setTimeout(() => {\n isThrottled = false;\n\n // istanbul ignore else\n if (savedArgs) {\n throttledFn(...savedArgs);\n savedArgs = null;\n }\n }, delayMs);\n }\n\n return [\n throttledFn,\n function cancel() {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n },\n ] as const;\n};\n","export const debounce = <T extends unknown[]>(\n func: (...args: T) => unknown,\n wait = 200,\n) => {\n let timeoutId: NodeJS.Timeout | null = null;\n const executedFunction = (...args: T) => {\n const postponedFn = () => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n func(...args);\n };\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n timeoutId = setTimeout(postponedFn, wait);\n };\n\n const cancel = function () {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n };\n return [executedFunction, cancel] as const;\n};\n","export { debounce } from './debounce';\n","const dayOfWeekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nconst periodValues: Record<string, number> = {\n year: 31536000,\n month: 2592000,\n week: 604800,\n day: 86400,\n hour: 3600,\n min: 60,\n};\n\nexport const formatTime = (timestampMs: number) =>\n new Date(timestampMs).toLocaleTimeString('en-US', {\n hour: '2-digit',\n minute: '2-digit',\n });\n\nexport const formatDayOfWeek = (timestampMs: number) =>\n dayOfWeekNames[new Date(timestampMs).getDay()];\n\nexport const formatDate = (timestampMs: number) =>\n new Date(timestampMs).toLocaleDateString('en-US', {\n day: '2-digit',\n month: 'short',\n });\n\nexport const printDayOfTheWeek = (day: number) => {\n switch (day) {\n case 0:\n return 'Sun';\n case 1:\n return 'Mon';\n case 2:\n return 'Tue';\n case 3:\n return 'Wed';\n case 4:\n return 'Thu';\n case 5:\n return 'Fri';\n case 6:\n return 'Sat';\n }\n};\n\nexport const getTimeAgo = (timeValue: string | number) => {\n const date = new Date(timeValue).getTime();\n if (Number.isNaN(date)) {\n throw new Error('Invalid date');\n }\n const diff = Math.floor((Date.now() - date) / 1000);\n let interval;\n for (const key in periodValues) {\n interval = Math.floor(diff / periodValues[key]);\n if (interval >= 1) {\n const pluralValue = interval > 1 ? 's' : '';\n return `${interval} ${key}${pluralValue} ago`;\n }\n }\n\n return 'Just Now';\n};\n","type MapObjIndexedFn<T, U> = (\n value: T,\n key: string,\n obj: Record<string, T>,\n) => U;\n\nexport const mapObjIndexed = <T, U>(\n fn: MapObjIndexedFn<T, U>,\n obj: Record<string, T>,\n): Record<string, U> => {\n return Object.keys(obj).reduce((result: Record<string, U>, key: string) => {\n result[key] = fn(obj[key], key, obj);\n return result;\n }, {});\n};\n","import { GenerateRangeFn } from './types';\n\n/**\n * The function that returns an array of page numbers to show in the pagination\n * component.\n *\n * Rules:\n * - To always show the 1st and the last page.\n * - To show one item before and one item after the selected page.\n * - To return \"-1\" for the skipped items. This is to be able to display \"...\" in\n * the pagination component.\n * */\nconst SKIPPED_ITEMS_DELTA = 2;\n\nconst getSelectedRange = (pagesCount: number, selectedPage: number) => {\n const range: number[] = [];\n\n if (selectedPage !== pagesCount) {\n range.push(selectedPage);\n }\n\n if (selectedPage > 1) {\n range.unshift(selectedPage - 1);\n }\n\n if (selectedPage + 1 < pagesCount) {\n range.push(selectedPage + 1);\n }\n\n return range;\n};\n\nconst fill = (range: number[], minValue: number, maxValue: number) => {\n for (let i = minValue; i < maxValue; ++i) {\n range.push(i);\n }\n};\n\nconst generateRange: GenerateRangeFn = (pagesCount, selectedPage) => {\n if (pagesCount == null || !Number.isInteger(pagesCount)) {\n throw new Error('Pages count should be an integer');\n }\n\n if (pagesCount <= 0) {\n return [];\n }\n\n let range = [1];\n\n if (pagesCount === 1) {\n return range;\n }\n\n if (selectedPage != null && !Number.isInteger(selectedPage)) {\n throw new Error('Selected page should be an integer');\n }\n\n if (selectedPage != null && (selectedPage < 1 || selectedPage > pagesCount)) {\n throw new Error(`Selected page ${selectedPage} is out of range`);\n }\n\n if (selectedPage && selectedPage > 2) {\n const selectedRange = getSelectedRange(pagesCount, selectedPage);\n\n const [minSelectedRange, , maxSelectedRange] = selectedRange;\n\n if (minSelectedRange - SKIPPED_ITEMS_DELTA > 1) {\n range.push(-1);\n } else {\n fill(range, 2, minSelectedRange);\n }\n\n range = range.concat(selectedRange);\n\n if (pagesCount - maxSelectedRange > SKIPPED_ITEMS_DELTA) {\n range.push(-1);\n } else {\n fill(range, maxSelectedRange + 1, pagesCount);\n }\n } else if (pagesCount <= 5) {\n fill(range, 2, pagesCount);\n } else {\n range.push(2, 3, -1);\n }\n\n range.push(pagesCount);\n\n return range;\n};\n\nexport default generateRange;\n","export const assocPath =\n <T>([first, ...rest]: string[], value: unknown) =>\n (sourceObject: T): T =>\n JSON.parse(\n JSON.stringify({\n ...sourceObject,\n [first]: rest.length\n ? assocPath(rest, value)(sourceObject[first as keyof T])\n : value,\n }),\n ) as T;\n","export const dissocPath =\n <T>(path: string[]) =>\n (sourceObject: T): T => {\n const resultObject = JSON.parse(JSON.stringify(sourceObject));\n path.reduce((acc, key, index) => {\n if (index === path.length - 1) {\n delete acc[key];\n }\n return acc[key];\n }, resultObject);\n\n return resultObject;\n };\n","export const path =\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n <T extends Record<string | number, any>, R = unknown>(\n path: Array<string | number>,\n ) =>\n (obj: T): R =>\n path.reduce(\n (prev, curr: string | number) => prev?.[curr],\n obj,\n ) as unknown as R;\n","import { path as originalPath } from './path';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const pathOr =\n <T extends Record<string | number, any>, R>(\n defaultValue: any,\n path: Array<string | number>,\n ) =>\n (obj: T): R => {\n const result = originalPath(path)(obj);\n return result === null || result === undefined\n ? defaultValue\n : (result as R);\n };\n/* eslint-enable @typescript-eslint/no-explicit-any */\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const prop =\n <T extends Record<string | number, any>, R = any>(propName: string) =>\n (obj: T): R =>\n obj?.[propName] as R;\n","import { prop } from './prop';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const propOr =\n <T extends Record<string | number, any>, R = any>(\n defaultValue: any,\n propName: string,\n ) =>\n (obj: T): R => {\n const result = prop(propName)(obj);\n return result === null || result === undefined ? defaultValue : result;\n };\n/* eslint-enable @typescript-eslint/no-explicit-any */\n","export * from './mapObjIndexed';\nexport * from './assocPath';\nexport * from './dissocPath';\nexport * from './path';\nexport * from './pathOr';\nexport * from './prop';\nexport * from './propOr';\n","// Useful for generating test datasets for storybook stories\nexport const seededRandom = (seed: number) => {\n return () => {\n // Linear congruential generator\n seed = (seed * 9301 + 49297) % 233280;\n return seed / 233280;\n };\n};\n","export class ClassnameArray extends Array<string> {\n toggle(className: string, condition: boolean) {\n const index = this.indexOf(className);\n if (condition) {\n if (index === -1) {\n this.push(className);\n }\n } else {\n if (index > -1) {\n this.splice(index, 1);\n }\n }\n return this;\n }\n\n clear() {\n this.length = 0;\n return this;\n }\n}\n","export { callAll } from './utils/CallAll';\nexport { throttle } from './utils/throttle';\nexport * from './utils/debounce';\nexport * as dateFormatters from './utils/dates/dateFormatters';\nexport { mapObjIndexed } from './utils/objects/mapObjIndexed';\nexport { generateRange } from './utils/pagination';\nexport * from './utils/objects';\nexport * from './utils/types';\nexport * from './utils/story';\nexport * from './utils/ClassnameArray/ClassnameArray';\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","seededRandom","seed","ClassnameArray","Array","toggle","className","condition","indexOf","splice","clear","_dateFormatters","dateFormatters"],"ignoreList":[],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.js","mappings":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AA,EAAG;IACN,IAAI,CAACvB,MAAM,GAAG,CAAC;IACf,OAAO,IAAI;EACb;AACF,C;;ACnB0C;AACX;AACa;AACX;AAC8B;AAArC;AACoC;AACX;AACnB;AACF;AACA","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/isNill.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/utils/story.ts","webpack://SSAUtils/./src/utils/ClassnameArray/ClassnameArray.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 */\nexport const callAll =\n (...fns: any[]) =>\n (...args: any) =>\n fns.forEach((fn) => fn?.(...args));\n/* eslint-enable @typescript-eslint/no-explicit-any */\n","/**\n * Checks whether a value is `null` or `undefined`.\n *\n * Unlike a plain falsy check, this returns `false` for other falsy\n * values such as `0`, `''`, `false` and `NaN`.\n *\n * @example\n * isNill(null); // true\n * isNill(undefined); // true\n * isNill(0); // false\n * isNill(''); // false\n */\nexport const isNill = (value: unknown): value is null | undefined =>\n value === null || value === undefined;\n","export const throttle = <T extends unknown[]>(\n fn: (...args: T) => unknown,\n delayMs: number,\n) => {\n let isThrottled = false;\n let savedArgs: T | null = null;\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n function throttledFn(...args: T) {\n if (isThrottled) {\n savedArgs = args;\n return;\n }\n\n isThrottled = true;\n\n fn(...args);\n\n timeoutId = setTimeout(() => {\n isThrottled = false;\n\n // istanbul ignore else\n if (savedArgs) {\n throttledFn(...savedArgs);\n savedArgs = null;\n }\n }, delayMs);\n }\n\n return [\n throttledFn,\n function cancel() {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n },\n ] as const;\n};\n","export const debounce = <T extends unknown[]>(\n func: (...args: T) => unknown,\n wait = 200,\n) => {\n let timeoutId: NodeJS.Timeout | null = null;\n const executedFunction = (...args: T) => {\n const postponedFn = () => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n func(...args);\n };\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n timeoutId = setTimeout(postponedFn, wait);\n };\n\n const cancel = function () {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n };\n return [executedFunction, cancel] as const;\n};\n","export { debounce } from './debounce';\n","const dayOfWeekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nconst periodValues: Record<string, number> = {\n year: 31536000,\n month: 2592000,\n week: 604800,\n day: 86400,\n hour: 3600,\n min: 60,\n};\n\nexport const formatTime = (timestampMs: number) =>\n new Date(timestampMs).toLocaleTimeString('en-US', {\n hour: '2-digit',\n minute: '2-digit',\n });\n\nexport const formatDayOfWeek = (timestampMs: number) =>\n dayOfWeekNames[new Date(timestampMs).getDay()];\n\nexport const formatDate = (timestampMs: number) =>\n new Date(timestampMs).toLocaleDateString('en-US', {\n day: '2-digit',\n month: 'short',\n });\n\nexport const printDayOfTheWeek = (day: number) => {\n switch (day) {\n case 0:\n return 'Sun';\n case 1:\n return 'Mon';\n case 2:\n return 'Tue';\n case 3:\n return 'Wed';\n case 4:\n return 'Thu';\n case 5:\n return 'Fri';\n case 6:\n return 'Sat';\n }\n};\n\nexport const getTimeAgo = (timeValue: string | number) => {\n const date = new Date(timeValue).getTime();\n if (Number.isNaN(date)) {\n throw new Error('Invalid date');\n }\n const diff = Math.floor((Date.now() - date) / 1000);\n let interval;\n for (const key in periodValues) {\n interval = Math.floor(diff / periodValues[key]);\n if (interval >= 1) {\n const pluralValue = interval > 1 ? 's' : '';\n return `${interval} ${key}${pluralValue} ago`;\n }\n }\n\n return 'Just Now';\n};\n","type MapObjIndexedFn<T, U> = (\n value: T,\n key: string,\n obj: Record<string, T>,\n) => U;\n\nexport const mapObjIndexed = <T, U>(\n fn: MapObjIndexedFn<T, U>,\n obj: Record<string, T>,\n): Record<string, U> => {\n return Object.keys(obj).reduce((result: Record<string, U>, key: string) => {\n result[key] = fn(obj[key], key, obj);\n return result;\n }, {});\n};\n","import { isNill } from '../isNill';\nimport { GenerateRangeFn } from './types';\n\n/**\n * The function that returns an array of page numbers to show in the pagination\n * component.\n *\n * Rules:\n * - To always show the 1st and the last page.\n * - To show one item before and one item after the selected page.\n * - To return \"-1\" for the skipped items. This is to be able to display \"...\" in\n * the pagination component.\n * */\nconst SKIPPED_ITEMS_DELTA = 2;\n\nconst getSelectedRange = (pagesCount: number, selectedPage: number) => {\n const range: number[] = [];\n\n if (selectedPage !== pagesCount) {\n range.push(selectedPage);\n }\n\n if (selectedPage > 1) {\n range.unshift(selectedPage - 1);\n }\n\n if (selectedPage + 1 < pagesCount) {\n range.push(selectedPage + 1);\n }\n\n return range;\n};\n\nconst fill = (range: number[], minValue: number, maxValue: number) => {\n for (let i = minValue; i < maxValue; ++i) {\n range.push(i);\n }\n};\n\nconst generateRange: GenerateRangeFn = (pagesCount, selectedPage) => {\n if (isNill(pagesCount) || !Number.isInteger(pagesCount)) {\n throw new Error('Pages count should be an integer');\n }\n\n if (pagesCount <= 0) {\n return [];\n }\n\n let range = [1];\n\n if (pagesCount === 1) {\n return range;\n }\n\n if (!isNill(selectedPage) && !Number.isInteger(selectedPage)) {\n throw new Error('Selected page should be an integer');\n }\n\n if (\n !isNill(selectedPage) &&\n (selectedPage < 1 || selectedPage > pagesCount)\n ) {\n throw new Error(`Selected page ${selectedPage} is out of range`);\n }\n\n if (selectedPage && selectedPage > 2) {\n const selectedRange = getSelectedRange(pagesCount, selectedPage);\n\n const [minSelectedRange, , maxSelectedRange] = selectedRange;\n\n if (minSelectedRange - SKIPPED_ITEMS_DELTA > 1) {\n range.push(-1);\n } else {\n fill(range, 2, minSelectedRange);\n }\n\n range = range.concat(selectedRange);\n\n if (pagesCount - maxSelectedRange > SKIPPED_ITEMS_DELTA) {\n range.push(-1);\n } else {\n fill(range, maxSelectedRange + 1, pagesCount);\n }\n } else if (pagesCount <= 5) {\n fill(range, 2, pagesCount);\n } else {\n range.push(2, 3, -1);\n }\n\n range.push(pagesCount);\n\n return range;\n};\n\nexport default generateRange;\n","export const assocPath =\n <T>([first, ...rest]: string[], value: unknown) =>\n (sourceObject: T): T =>\n JSON.parse(\n JSON.stringify({\n ...sourceObject,\n [first]: rest.length\n ? assocPath(rest, value)(sourceObject[first as keyof T])\n : value,\n }),\n ) as T;\n","export const dissocPath =\n <T>(path: string[]) =>\n (sourceObject: T): T => {\n const resultObject = JSON.parse(JSON.stringify(sourceObject));\n path.reduce((acc, key, index) => {\n if (index === path.length - 1) {\n delete acc[key];\n }\n return acc[key];\n }, resultObject);\n\n return resultObject;\n };\n","export const path =\n /* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n <T extends Record<string | number, any>, R = unknown>(\n path: Array<string | number>,\n ) =>\n (obj: T): R =>\n path.reduce(\n (prev, curr: string | number) => prev?.[curr],\n obj,\n ) as unknown as R;\n","import { isNill } from '../isNill';\nimport { path as originalPath } from './path';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const pathOr =\n <T extends Record<string | number, any>, R>(\n defaultValue: any,\n path: Array<string | number>,\n ) =>\n (obj: T): R => {\n const result = originalPath(path)(obj);\n return isNill(result) ? defaultValue : (result as R);\n };\n/* eslint-enable @typescript-eslint/no-explicit-any */\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const prop =\n <T extends Record<string | number, any>, R = any>(propName: string) =>\n (obj: T): R =>\n obj?.[propName] as R;\n","import { isNill } from '../isNill';\nimport { prop } from './prop';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const propOr =\n <T extends Record<string | number, any>, R = any>(\n defaultValue: any,\n propName: string,\n ) =>\n (obj: T): R => {\n const result = prop(propName)(obj);\n return isNill(result) ? defaultValue : result;\n };\n/* eslint-enable @typescript-eslint/no-explicit-any */\n","export * from './mapObjIndexed';\nexport * from './assocPath';\nexport * from './dissocPath';\nexport * from './path';\nexport * from './pathOr';\nexport * from './prop';\nexport * from './propOr';\n","// Useful for generating test datasets for storybook stories\nexport const seededRandom = (seed: number) => {\n return () => {\n // Linear congruential generator\n seed = (seed * 9301 + 49297) % 233280;\n return seed / 233280;\n };\n};\n","export class ClassnameArray extends Array<string> {\n toggle(className: string, condition: boolean) {\n const index = this.indexOf(className);\n if (condition) {\n if (index === -1) {\n this.push(className);\n }\n } else {\n if (index > -1) {\n this.splice(index, 1);\n }\n }\n return this;\n }\n\n clear() {\n this.length = 0;\n return this;\n }\n}\n","export { callAll } from './utils/CallAll';\nexport * from './utils/isNill';\nexport { throttle } from './utils/throttle';\nexport * from './utils/debounce';\nexport * as dateFormatters from './utils/dates/dateFormatters';\nexport { mapObjIndexed } from './utils/objects/mapObjIndexed';\nexport { generateRange } from './utils/pagination';\nexport * from './utils/objects';\nexport * from './utils/types';\nexport * from './utils/story';\nexport * from './utils/ClassnameArray/ClassnameArray';\n"],"names":["callAll","fns","args","forEach","fn","isNill","value","undefined","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","sourceObject","JSON","parse","stringify","length","dissocPath","path","resultObject","acc","index","prev","curr","originalPath","pathOr","defaultValue","prop","propName","propOr","seededRandom","seed","ClassnameArray","Array","toggle","className","condition","indexOf","splice","clear","_dateFormatters","dateFormatters"],"ignoreList":[],"sourceRoot":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether a value is `null` or `undefined`.
|
|
3
|
+
*
|
|
4
|
+
* Unlike a plain falsy check, this returns `false` for other falsy
|
|
5
|
+
* values such as `0`, `''`, `false` and `NaN`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* isNill(null); // true
|
|
9
|
+
* isNill(undefined); // true
|
|
10
|
+
* isNill(0); // false
|
|
11
|
+
* isNill(''); // false
|
|
12
|
+
*/
|
|
13
|
+
export declare const isNill: (value: unknown) => value is null | undefined;
|