tiny-essentials 1.26.4 → 1.27.0
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/.github/workflows/node.js.yml +1 -1
- package/README.md +0 -1
- package/changelog/1/27/0.md +24 -0
- package/dist/v1/ColorSafeStringify.min.js +1 -1
- package/dist/v1/TinyAdvancedRaffle.min.js +1 -1
- package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
- package/dist/v1/TinyAnalogClock.min.js +1 -1
- package/dist/v1/TinyArrayComparator.min.js +1 -1
- package/dist/v1/TinyArrayPaginator.min.js +1 -1
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyClassManager.min.js +1 -1
- package/dist/v1/TinyClipboard.min.js +1 -1
- package/dist/v1/TinyColorConverter.min.js +1 -1
- package/dist/v1/TinyColorValidator.min.js +1 -1
- package/dist/v1/TinyCookieConsent.min.js +1 -1
- package/dist/v1/TinyDayNightCycle.min.js +1 -1
- package/dist/v1/TinyDomReadyManager.min.js +1 -1
- package/dist/v1/TinyDragDropDetector.min.js +1 -1
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyElementObserver.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyEvents.min.js +1 -1
- package/dist/v1/TinyGamepad.min.js +1 -1
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinyI18.min.js +1 -1
- package/dist/v1/TinyIframeEvents.min.js +1 -1
- package/dist/v1/TinyInventory.min.js +1 -1
- package/dist/v1/TinyInventoryTrader.min.js +1 -1
- package/dist/v1/TinyLevelUp.min.js +1 -1
- package/dist/v1/TinyLoadingScreen.min.js +1 -1
- package/dist/v1/TinyLocalStorage.min.js +1 -1
- package/dist/v1/TinyMaInSys.min.js +1 -1
- package/dist/v1/TinyMediaPlayer.min.js +1 -0
- package/dist/v1/TinyNeedBar.min.js +1 -1
- package/dist/v1/TinyNewWinEvents.min.js +1 -1
- package/dist/v1/TinyNotifications.min.js +1 -1
- package/dist/v1/TinyNotifyCenter.min.js +1 -1
- package/dist/v1/TinyPromiseQueue.min.js +1 -1
- package/dist/v1/TinyRadioFm.min.js +1 -0
- package/dist/v1/TinyRateLimiter.min.js +1 -1
- package/dist/v1/TinySimpleDice.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyTextDiffer.min.js +1 -1
- package/dist/v1/TinyTextRangeEditor.min.js +1 -1
- package/dist/v1/TinyTextarea.min.js +1 -1
- package/dist/v1/TinyTimeout.min.js +1 -1
- package/dist/v1/TinyToastNotify.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/UltraRandomMsgGen.min.js +1 -1
- package/dist/v1/basics/index.cjs +5 -0
- package/dist/v1/basics/index.d.mts +5 -1
- package/dist/v1/basics/index.mjs +2 -1
- package/dist/v1/basics/mediaContent.cjs +644 -0
- package/dist/v1/basics/mediaContent.d.mts +296 -0
- package/dist/v1/basics/mediaContent.mjs +557 -0
- package/dist/v1/build/TinyMediaPlayer.cjs +7 -0
- package/dist/v1/build/TinyMediaPlayer.d.mts +3 -0
- package/dist/v1/build/TinyMediaPlayer.mjs +2 -0
- package/dist/v1/build/TinyRadioFm.cjs +7 -0
- package/dist/v1/build/TinyRadioFm.d.mts +3 -0
- package/dist/v1/build/TinyRadioFm.mjs +2 -0
- package/dist/v1/index.cjs +9 -0
- package/dist/v1/index.d.mts +7 -1
- package/dist/v1/index.mjs +5 -2
- package/dist/v1/libs/ColorSafeStringify.d.mts +1 -1
- package/dist/v1/libs/TinyAfterScrollWatcher.cjs +16 -3
- package/dist/v1/libs/TinyAfterScrollWatcher.d.mts +7 -3
- package/dist/v1/libs/TinyAfterScrollWatcher.mjs +13 -3
- package/dist/v1/libs/TinyArrayComparator.cjs +14 -11
- package/dist/v1/libs/TinyArrayComparator.d.mts +22 -19
- package/dist/v1/libs/TinyArrayComparator.mjs +14 -11
- package/dist/v1/libs/TinyArrayPaginator.cjs +23 -16
- package/dist/v1/libs/TinyArrayPaginator.d.mts +57 -30
- package/dist/v1/libs/TinyArrayPaginator.mjs +22 -16
- package/dist/v1/libs/TinyClassManager/TinyPluginInliner.cjs +265 -0
- package/dist/v1/libs/TinyClassManager/TinyPluginInliner.d.mts +92 -0
- package/dist/v1/libs/TinyClassManager/TinyPluginInliner.mjs +223 -0
- package/dist/v1/libs/TinyClassManager.cjs +52 -22
- package/dist/v1/libs/TinyClassManager.d.mts +26 -16
- package/dist/v1/libs/TinyClassManager.mjs +50 -21
- package/dist/v1/libs/TinyColorValidator.d.mts +16 -16
- package/dist/v1/libs/TinyDragDropDetector.cjs +9 -34
- package/dist/v1/libs/TinyDragDropDetector.d.mts +7 -21
- package/dist/v1/libs/TinyDragDropDetector.mjs +9 -24
- package/dist/v1/libs/TinyDragger.cjs +5 -5
- package/dist/v1/libs/TinyDragger.d.mts +4 -3
- package/dist/v1/libs/TinyDragger.mjs +5 -5
- package/dist/v1/libs/TinyElementObserver.cjs +6 -21
- package/dist/v1/libs/TinyElementObserver.d.mts +6 -15
- package/dist/v1/libs/TinyElementObserver.mjs +6 -20
- package/dist/v1/libs/TinyGamepad.cjs +4 -6
- package/dist/v1/libs/TinyGamepad.d.mts +1 -1
- package/dist/v1/libs/TinyHtml/TinyHtmlIcon.d.mts +1 -1
- package/dist/v1/libs/TinyHtml/TinyHtmlTemplate.d.mts +1 -1
- package/dist/v1/libs/TinyHtml/TinyHtmlTextarea.d.mts +1 -1
- package/dist/v1/libs/TinyHtml/index.d.mts +1 -1
- package/dist/v1/libs/TinyHtml.cjs +72 -98
- package/dist/v1/libs/TinyHtml.d.mts +15 -32
- package/dist/v1/libs/TinyHtml.mjs +53 -77
- package/dist/v1/libs/TinyInventory.d.mts +1 -1
- package/dist/v1/libs/TinyMediaPlayer.cjs +844 -0
- package/dist/v1/libs/TinyMediaPlayer.d.mts +306 -0
- package/dist/v1/libs/TinyMediaPlayer.mjs +755 -0
- package/dist/v1/libs/TinyRadioFm.cjs +1378 -0
- package/dist/v1/libs/TinyRadioFm.d.mts +554 -0
- package/dist/v1/libs/TinyRadioFm.mjs +1137 -0
- package/dist/v1/libs/TinySmartScroller.cjs +39 -26
- package/dist/v1/libs/TinySmartScroller.d.mts +16 -62
- package/dist/v1/libs/TinySmartScroller.mjs +35 -26
- package/dist/v1/libs/UltraRandomMsgGen.d.mts +7 -7
- package/docs/v1/README.md +6 -0
- package/docs/v1/basics/mediaContent.md +131 -0
- package/docs/v1/libs/TinyClassManager/TinyPluginInliner.md +107 -0
- package/docs/v1/libs/TinyDragDropDetector.md +5 -9
- package/docs/v1/libs/TinyElementObserver.md +3 -6
- package/docs/v1/libs/TinyHtml.md +0 -29
- package/docs/v1/libs/TinyMediaPlayer.md +100 -0
- package/docs/v1/libs/TinyRadioFm.md +141 -0
- package/docs/v1/libs/TinySmartScroller.md +3 -3
- package/package.json +40 -22
package/dist/v1/index.mjs
CHANGED
|
@@ -19,6 +19,7 @@ import TinyDragger from './libs/TinyDragger.mjs';
|
|
|
19
19
|
import TinyDomReadyManager from './libs/TinyDomReadyManager.mjs';
|
|
20
20
|
import TinyNotifications from './libs/TinyNotifications.mjs';
|
|
21
21
|
import { areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, } from './basics/collision.mjs';
|
|
22
|
+
import { extractMediaId3Tags, parseMediaMetadata, valMediaContentMetadata, valMediaContentMetadataPartial, } from './basics/mediaContent.mjs';
|
|
22
23
|
import TinyHtml from './libs/TinyHtml.mjs';
|
|
23
24
|
import TinyAfterScrollWatcher from './libs/TinyAfterScrollWatcher.mjs';
|
|
24
25
|
import UltraRandomMsgGen from './libs/UltraRandomMsgGen.mjs';
|
|
@@ -50,7 +51,9 @@ import TinyTextDiffer from './libs/TinyTextDiffer.mjs';
|
|
|
50
51
|
import TinyArrayComparator from './libs/TinyArrayComparator.mjs';
|
|
51
52
|
import { FuzzySet, MamdaniInferenceSystem, trapezoid, defuzzifyCentroid, } from './libs/TinyMamdaniInferenceSystem.mjs';
|
|
52
53
|
import TinyClassManager from './libs/TinyClassManager.mjs';
|
|
54
|
+
import TinyRadioFm from './libs/TinyRadioFm.mjs';
|
|
55
|
+
import TinyMediaPlayer from './libs/TinyMediaPlayer.mjs';
|
|
53
56
|
// import TinyHtmlElems from './libs/TinyHtml/index.mjs';
|
|
54
|
-
export { TinyClassManager, FuzzySet, MamdaniInferenceSystem, TinyArrayComparator, TinyTextDiffer, TinyAnalogClock,
|
|
57
|
+
export { TinyMediaPlayer, TinyRadioFm, TinyClassManager, FuzzySet, MamdaniInferenceSystem, TinyArrayComparator, TinyTextDiffer, TinyAnalogClock,
|
|
55
58
|
// TinyHtmlElems,
|
|
56
|
-
TinyColorValidator, TinyLoadingScreen, TinyElementObserver, TinySimpleDice, TinyNeedBar, TinyI18, TinyCookieConsent, TinyInventory, TinyInventoryTrader, TinyArrayPaginator, TinyAdvancedRaffle, TinyDayNightCycle, TinyGamepad, TinyTextarea, TinyNewWinEvents, TinyIframeEvents, TinyLocalStorage, TinyEvents, TinyTimeout, TinyColorConverter, TinyClipboard, TinyTextRangeEditor, TinySmartScroller, UltraRandomMsgGen, TinyAfterScrollWatcher, TinyHtml, TinyNotifications, TinyDomReadyManager, TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, defuzzifyCentroid, trapezoid, diffArrayList, diffStrings, breakdownDuration, calculateMarketcap, compareMarketcap, getPercentage, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, safeTextTrim, installWindowHiddenScript, genFibonacciSeq, isDirEmptyAsync, fileSizeAsync, dirSizeAsync, listFilesAsync, listDirsAsync, getLatestBackupPath, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, readJsonFile, writeJsonFile, ensureDirectory, clearDirectoryAsync, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
|
|
59
|
+
TinyColorValidator, TinyLoadingScreen, TinyElementObserver, TinySimpleDice, TinyNeedBar, TinyI18, TinyCookieConsent, TinyInventory, TinyInventoryTrader, TinyArrayPaginator, TinyAdvancedRaffle, TinyDayNightCycle, TinyGamepad, TinyTextarea, TinyNewWinEvents, TinyIframeEvents, TinyLocalStorage, TinyEvents, TinyTimeout, TinyColorConverter, TinyClipboard, TinyTextRangeEditor, TinySmartScroller, UltraRandomMsgGen, TinyAfterScrollWatcher, TinyHtml, TinyNotifications, TinyDomReadyManager, TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, valMediaContentMetadata, valMediaContentMetadataPartial, parseMediaMetadata, extractMediaId3Tags, defuzzifyCentroid, trapezoid, diffArrayList, diffStrings, breakdownDuration, calculateMarketcap, compareMarketcap, getPercentage, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, safeTextTrim, installWindowHiddenScript, genFibonacciSeq, isDirEmptyAsync, fileSizeAsync, dirSizeAsync, listFilesAsync, listDirsAsync, getLatestBackupPath, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, readJsonFile, writeJsonFile, ensureDirectory, clearDirectoryAsync, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
|
|
@@ -13,7 +13,7 @@ declare class ColorSafeStringify {
|
|
|
13
13
|
* @type {Record<string, ColorsList>}
|
|
14
14
|
* @static
|
|
15
15
|
*/
|
|
16
|
-
static
|
|
16
|
+
static #PRESETS: Record<string, ColorsList>;
|
|
17
17
|
/**
|
|
18
18
|
* Constructs a new instance with an optional base preset or custom override.
|
|
19
19
|
* @param {ColorsList} [defaultColors] - Optional override for the default color scheme.
|
|
@@ -14,17 +14,26 @@
|
|
|
14
14
|
/**
|
|
15
15
|
* A scroll tracker that queues functions to be executed
|
|
16
16
|
* after the user stops scrolling a specific element or the window.
|
|
17
|
+
* @template {Element|Window} ScrollElement
|
|
17
18
|
*/
|
|
18
19
|
class TinyAfterScrollWatcher {
|
|
19
|
-
/** @type {
|
|
20
|
+
/** @type {ScrollElement} */
|
|
20
21
|
#scrollTarget;
|
|
21
22
|
|
|
23
|
+
get scrollTarget() {
|
|
24
|
+
return this.#scrollTarget;
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
/** @type {null|NodeJS.Timeout} */
|
|
23
28
|
#lastScrollTime = null;
|
|
24
29
|
|
|
25
30
|
/** @type {FnData[]} */
|
|
26
31
|
#afterScrollQueue = [];
|
|
27
32
|
|
|
33
|
+
get afterScrollQueueSize() {
|
|
34
|
+
return this.#afterScrollQueue.length;
|
|
35
|
+
}
|
|
36
|
+
|
|
28
37
|
/** @type {number} */
|
|
29
38
|
#inactivityTime = 100;
|
|
30
39
|
|
|
@@ -37,13 +46,17 @@ class TinyAfterScrollWatcher {
|
|
|
37
46
|
/** @type {boolean} */
|
|
38
47
|
#destroyed = false;
|
|
39
48
|
|
|
49
|
+
get destroyed() {
|
|
50
|
+
return this.#destroyed;
|
|
51
|
+
}
|
|
52
|
+
|
|
40
53
|
/**
|
|
41
|
-
* @param {
|
|
54
|
+
* @param {ScrollElement} scrollTarget - The element or window to track scrolling on
|
|
42
55
|
* @param {number} [inactivityTime=100] - Time in milliseconds to wait after scroll ends before executing the queue
|
|
43
56
|
* @throws {TypeError} If scrollTarget is not a valid Element or Window
|
|
44
57
|
* @throws {TypeError} If inactivityTime is not a positive number
|
|
45
58
|
*/
|
|
46
|
-
constructor(scrollTarget
|
|
59
|
+
constructor(scrollTarget, inactivityTime = 100) {
|
|
47
60
|
if (!(scrollTarget instanceof Element) && !(scrollTarget instanceof Window))
|
|
48
61
|
throw new TypeError('scrollTarget must be an Element or the Window object.');
|
|
49
62
|
this.#scrollTarget = scrollTarget;
|
|
@@ -20,15 +20,19 @@ export type OnScrollFunc = (ev: Event) => void;
|
|
|
20
20
|
/**
|
|
21
21
|
* A scroll tracker that queues functions to be executed
|
|
22
22
|
* after the user stops scrolling a specific element or the window.
|
|
23
|
+
* @template {Element|Window} ScrollElement
|
|
23
24
|
*/
|
|
24
|
-
declare class TinyAfterScrollWatcher {
|
|
25
|
+
declare class TinyAfterScrollWatcher<ScrollElement extends Element | Window> {
|
|
25
26
|
/**
|
|
26
|
-
* @param {
|
|
27
|
+
* @param {ScrollElement} scrollTarget - The element or window to track scrolling on
|
|
27
28
|
* @param {number} [inactivityTime=100] - Time in milliseconds to wait after scroll ends before executing the queue
|
|
28
29
|
* @throws {TypeError} If scrollTarget is not a valid Element or Window
|
|
29
30
|
* @throws {TypeError} If inactivityTime is not a positive number
|
|
30
31
|
*/
|
|
31
|
-
constructor(scrollTarget
|
|
32
|
+
constructor(scrollTarget: ScrollElement, inactivityTime?: number);
|
|
33
|
+
get scrollTarget(): ScrollElement;
|
|
34
|
+
get afterScrollQueueSize(): number;
|
|
35
|
+
get destroyed(): boolean;
|
|
32
36
|
_checkTimer: () => void;
|
|
33
37
|
/**
|
|
34
38
|
* Sets a new inactivity time.
|
|
@@ -10,14 +10,21 @@
|
|
|
10
10
|
/**
|
|
11
11
|
* A scroll tracker that queues functions to be executed
|
|
12
12
|
* after the user stops scrolling a specific element or the window.
|
|
13
|
+
* @template {Element|Window} ScrollElement
|
|
13
14
|
*/
|
|
14
15
|
class TinyAfterScrollWatcher {
|
|
15
|
-
/** @type {
|
|
16
|
+
/** @type {ScrollElement} */
|
|
16
17
|
#scrollTarget;
|
|
18
|
+
get scrollTarget() {
|
|
19
|
+
return this.#scrollTarget;
|
|
20
|
+
}
|
|
17
21
|
/** @type {null|NodeJS.Timeout} */
|
|
18
22
|
#lastScrollTime = null;
|
|
19
23
|
/** @type {FnData[]} */
|
|
20
24
|
#afterScrollQueue = [];
|
|
25
|
+
get afterScrollQueueSize() {
|
|
26
|
+
return this.#afterScrollQueue.length;
|
|
27
|
+
}
|
|
21
28
|
/** @type {number} */
|
|
22
29
|
#inactivityTime = 100;
|
|
23
30
|
/** @type {Set<OnScrollFunc>} */
|
|
@@ -26,13 +33,16 @@ class TinyAfterScrollWatcher {
|
|
|
26
33
|
#onStopListeners = new Set();
|
|
27
34
|
/** @type {boolean} */
|
|
28
35
|
#destroyed = false;
|
|
36
|
+
get destroyed() {
|
|
37
|
+
return this.#destroyed;
|
|
38
|
+
}
|
|
29
39
|
/**
|
|
30
|
-
* @param {
|
|
40
|
+
* @param {ScrollElement} scrollTarget - The element or window to track scrolling on
|
|
31
41
|
* @param {number} [inactivityTime=100] - Time in milliseconds to wait after scroll ends before executing the queue
|
|
32
42
|
* @throws {TypeError} If scrollTarget is not a valid Element or Window
|
|
33
43
|
* @throws {TypeError} If inactivityTime is not a positive number
|
|
34
44
|
*/
|
|
35
|
-
constructor(scrollTarget
|
|
45
|
+
constructor(scrollTarget, inactivityTime = 100) {
|
|
36
46
|
if (!(scrollTarget instanceof Element) && !(scrollTarget instanceof Window))
|
|
37
47
|
throw new TypeError('scrollTarget must be an Element or the Window object.');
|
|
38
48
|
this.#scrollTarget = scrollTarget;
|
|
@@ -6,19 +6,22 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
+
* @template {any} ArrayItem
|
|
9
10
|
* @typedef {Object} InternalState
|
|
10
11
|
* Holds the internal tracking variables during the comparison process.
|
|
11
|
-
* @property {Map<string,
|
|
12
|
-
* @property {AffectedItems} affectedItems - The final array that collects added or deleted items.
|
|
12
|
+
* @property {Map<string, ArrayItem>} oldItemsMap - A map storing the hash as the key and the original item as the value.
|
|
13
|
+
* @property {AffectedItems<ArrayItem>} affectedItems - The final array that collects added or deleted items.
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* The final array that collects added or deleted items.
|
|
17
|
-
* @
|
|
18
|
+
* @template {any} ArrayItem
|
|
19
|
+
* @typedef {Array<{item: ArrayItem, status: 'added'|'deleted'}>} AffectedItems
|
|
18
20
|
*/
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Compares two arrays efficiently by hashing their items to detect additions and deletions.
|
|
24
|
+
* @template {any} ArrayItem
|
|
22
25
|
*/
|
|
23
26
|
class TinyArrayComparator {
|
|
24
27
|
/**
|
|
@@ -41,13 +44,13 @@ class TinyArrayComparator {
|
|
|
41
44
|
|
|
42
45
|
/**
|
|
43
46
|
* Internal storage for the base array.
|
|
44
|
-
* @type {
|
|
47
|
+
* @type {ArrayItem[]}
|
|
45
48
|
*/
|
|
46
49
|
#oldArray = [];
|
|
47
50
|
|
|
48
51
|
/**
|
|
49
52
|
* Gets the current base array used for comparisons.
|
|
50
|
-
* @returns {
|
|
53
|
+
* @returns {ArrayItem[]} The current initial state of the array.
|
|
51
54
|
*/
|
|
52
55
|
get oldArray() {
|
|
53
56
|
return this.#oldArray;
|
|
@@ -55,7 +58,7 @@ class TinyArrayComparator {
|
|
|
55
58
|
|
|
56
59
|
/**
|
|
57
60
|
* Sets a new base array for future comparisons.
|
|
58
|
-
* @param {
|
|
61
|
+
* @param {ArrayItem[]} oldArray - The initial state of the array.
|
|
59
62
|
* @throws {TypeError} Throws an error if the provided value is not an array.
|
|
60
63
|
*/
|
|
61
64
|
set oldArray(oldArray) {
|
|
@@ -66,7 +69,7 @@ class TinyArrayComparator {
|
|
|
66
69
|
|
|
67
70
|
/**
|
|
68
71
|
* Initializes the comparator with an optional base array.
|
|
69
|
-
* @param {
|
|
72
|
+
* @param {ArrayItem[]} [oldArray] - The initial state of the array to be stored.
|
|
70
73
|
*/
|
|
71
74
|
constructor(oldArray) {
|
|
72
75
|
if (typeof oldArray !== 'undefined') this.oldArray = oldArray;
|
|
@@ -74,7 +77,7 @@ class TinyArrayComparator {
|
|
|
74
77
|
|
|
75
78
|
/**
|
|
76
79
|
* Proxy to generates a hash converted to a string.
|
|
77
|
-
* @param {
|
|
80
|
+
* @param {ArrayItem} item - The item to be hashed (can be an object, array, string, or number).
|
|
78
81
|
* @returns {string} The unique hash representing the item's value.
|
|
79
82
|
* @private
|
|
80
83
|
*/
|
|
@@ -85,15 +88,15 @@ class TinyArrayComparator {
|
|
|
85
88
|
/**
|
|
86
89
|
* Compares the stored older array with a newer array and identifies missing or new items.
|
|
87
90
|
*
|
|
88
|
-
* @param {
|
|
89
|
-
* @returns {AffectedItems} An array containing the affected items and their status.
|
|
91
|
+
* @param {ArrayItem[]} newArray - The modified state of the array.
|
|
92
|
+
* @returns {AffectedItems<ArrayItem>} An array containing the affected items and their status.
|
|
90
93
|
* @throws {TypeError} Throws an error if the provided value is not an array.
|
|
91
94
|
*/
|
|
92
95
|
compare(newArray) {
|
|
93
96
|
if (!Array.isArray(newArray))
|
|
94
97
|
throw new TypeError('The provided newArray must be a valid Array.');
|
|
95
98
|
|
|
96
|
-
/** @type {InternalState} */
|
|
99
|
+
/** @type {InternalState<ArrayItem>} */
|
|
97
100
|
const state = {
|
|
98
101
|
oldItemsMap: new Map(),
|
|
99
102
|
affectedItems: [],
|
|
@@ -2,21 +2,21 @@ export default TinyArrayComparator;
|
|
|
2
2
|
/**
|
|
3
3
|
* Holds the internal tracking variables during the comparison process.
|
|
4
4
|
*/
|
|
5
|
-
export type InternalState = {
|
|
5
|
+
export type InternalState<ArrayItem extends unknown> = {
|
|
6
6
|
/**
|
|
7
7
|
* - A map storing the hash as the key and the original item as the value.
|
|
8
8
|
*/
|
|
9
|
-
oldItemsMap: Map<string,
|
|
9
|
+
oldItemsMap: Map<string, ArrayItem>;
|
|
10
10
|
/**
|
|
11
11
|
* - The final array that collects added or deleted items.
|
|
12
12
|
*/
|
|
13
|
-
affectedItems: AffectedItems
|
|
13
|
+
affectedItems: AffectedItems<ArrayItem>;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* The final array that collects added or deleted items.
|
|
17
17
|
*/
|
|
18
|
-
export type AffectedItems = Array<{
|
|
19
|
-
item:
|
|
18
|
+
export type AffectedItems<ArrayItem extends unknown> = Array<{
|
|
19
|
+
item: ArrayItem;
|
|
20
20
|
status: "added" | "deleted";
|
|
21
21
|
}>;
|
|
22
22
|
/**
|
|
@@ -24,19 +24,22 @@ export type AffectedItems = Array<{
|
|
|
24
24
|
* @module TinyArrayComparator
|
|
25
25
|
*/
|
|
26
26
|
/**
|
|
27
|
+
* @template {any} ArrayItem
|
|
27
28
|
* @typedef {Object} InternalState
|
|
28
29
|
* Holds the internal tracking variables during the comparison process.
|
|
29
|
-
* @property {Map<string,
|
|
30
|
-
* @property {AffectedItems} affectedItems - The final array that collects added or deleted items.
|
|
30
|
+
* @property {Map<string, ArrayItem>} oldItemsMap - A map storing the hash as the key and the original item as the value.
|
|
31
|
+
* @property {AffectedItems<ArrayItem>} affectedItems - The final array that collects added or deleted items.
|
|
31
32
|
*/
|
|
32
33
|
/**
|
|
33
34
|
* The final array that collects added or deleted items.
|
|
34
|
-
* @
|
|
35
|
+
* @template {any} ArrayItem
|
|
36
|
+
* @typedef {Array<{item: ArrayItem, status: 'added'|'deleted'}>} AffectedItems
|
|
35
37
|
*/
|
|
36
38
|
/**
|
|
37
39
|
* Compares two arrays efficiently by hashing their items to detect additions and deletions.
|
|
40
|
+
* @template {any} ArrayItem
|
|
38
41
|
*/
|
|
39
|
-
declare class TinyArrayComparator {
|
|
42
|
+
declare class TinyArrayComparator<ArrayItem extends unknown> {
|
|
40
43
|
/**
|
|
41
44
|
* Generates a simple 32-bit integer hash converted to a base36 string.
|
|
42
45
|
* @param {any} item - The item to be hashed (can be an object, array, string, or number).
|
|
@@ -45,23 +48,23 @@ declare class TinyArrayComparator {
|
|
|
45
48
|
static generateHash(item: any): string;
|
|
46
49
|
/**
|
|
47
50
|
* Initializes the comparator with an optional base array.
|
|
48
|
-
* @param {
|
|
51
|
+
* @param {ArrayItem[]} [oldArray] - The initial state of the array to be stored.
|
|
49
52
|
*/
|
|
50
|
-
constructor(oldArray?:
|
|
53
|
+
constructor(oldArray?: ArrayItem[]);
|
|
51
54
|
/**
|
|
52
55
|
* Sets a new base array for future comparisons.
|
|
53
|
-
* @param {
|
|
56
|
+
* @param {ArrayItem[]} oldArray - The initial state of the array.
|
|
54
57
|
* @throws {TypeError} Throws an error if the provided value is not an array.
|
|
55
58
|
*/
|
|
56
|
-
set oldArray(oldArray:
|
|
59
|
+
set oldArray(oldArray: ArrayItem[]);
|
|
57
60
|
/**
|
|
58
61
|
* Gets the current base array used for comparisons.
|
|
59
|
-
* @returns {
|
|
62
|
+
* @returns {ArrayItem[]} The current initial state of the array.
|
|
60
63
|
*/
|
|
61
|
-
get oldArray():
|
|
64
|
+
get oldArray(): ArrayItem[];
|
|
62
65
|
/**
|
|
63
66
|
* Proxy to generates a hash converted to a string.
|
|
64
|
-
* @param {
|
|
67
|
+
* @param {ArrayItem} item - The item to be hashed (can be an object, array, string, or number).
|
|
65
68
|
* @returns {string} The unique hash representing the item's value.
|
|
66
69
|
* @private
|
|
67
70
|
*/
|
|
@@ -69,11 +72,11 @@ declare class TinyArrayComparator {
|
|
|
69
72
|
/**
|
|
70
73
|
* Compares the stored older array with a newer array and identifies missing or new items.
|
|
71
74
|
*
|
|
72
|
-
* @param {
|
|
73
|
-
* @returns {AffectedItems} An array containing the affected items and their status.
|
|
75
|
+
* @param {ArrayItem[]} newArray - The modified state of the array.
|
|
76
|
+
* @returns {AffectedItems<ArrayItem>} An array containing the affected items and their status.
|
|
74
77
|
* @throws {TypeError} Throws an error if the provided value is not an array.
|
|
75
78
|
*/
|
|
76
|
-
compare(newArray:
|
|
79
|
+
compare(newArray: ArrayItem[]): AffectedItems<ArrayItem>;
|
|
77
80
|
#private;
|
|
78
81
|
}
|
|
79
82
|
//# sourceMappingURL=TinyArrayComparator.d.mts.map
|
|
@@ -3,17 +3,20 @@
|
|
|
3
3
|
* @module TinyArrayComparator
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
+
* @template {any} ArrayItem
|
|
6
7
|
* @typedef {Object} InternalState
|
|
7
8
|
* Holds the internal tracking variables during the comparison process.
|
|
8
|
-
* @property {Map<string,
|
|
9
|
-
* @property {AffectedItems} affectedItems - The final array that collects added or deleted items.
|
|
9
|
+
* @property {Map<string, ArrayItem>} oldItemsMap - A map storing the hash as the key and the original item as the value.
|
|
10
|
+
* @property {AffectedItems<ArrayItem>} affectedItems - The final array that collects added or deleted items.
|
|
10
11
|
*/
|
|
11
12
|
/**
|
|
12
13
|
* The final array that collects added or deleted items.
|
|
13
|
-
* @
|
|
14
|
+
* @template {any} ArrayItem
|
|
15
|
+
* @typedef {Array<{item: ArrayItem, status: 'added'|'deleted'}>} AffectedItems
|
|
14
16
|
*/
|
|
15
17
|
/**
|
|
16
18
|
* Compares two arrays efficiently by hashing their items to detect additions and deletions.
|
|
19
|
+
* @template {any} ArrayItem
|
|
17
20
|
*/
|
|
18
21
|
class TinyArrayComparator {
|
|
19
22
|
/**
|
|
@@ -33,19 +36,19 @@ class TinyArrayComparator {
|
|
|
33
36
|
}
|
|
34
37
|
/**
|
|
35
38
|
* Internal storage for the base array.
|
|
36
|
-
* @type {
|
|
39
|
+
* @type {ArrayItem[]}
|
|
37
40
|
*/
|
|
38
41
|
#oldArray = [];
|
|
39
42
|
/**
|
|
40
43
|
* Gets the current base array used for comparisons.
|
|
41
|
-
* @returns {
|
|
44
|
+
* @returns {ArrayItem[]} The current initial state of the array.
|
|
42
45
|
*/
|
|
43
46
|
get oldArray() {
|
|
44
47
|
return this.#oldArray;
|
|
45
48
|
}
|
|
46
49
|
/**
|
|
47
50
|
* Sets a new base array for future comparisons.
|
|
48
|
-
* @param {
|
|
51
|
+
* @param {ArrayItem[]} oldArray - The initial state of the array.
|
|
49
52
|
* @throws {TypeError} Throws an error if the provided value is not an array.
|
|
50
53
|
*/
|
|
51
54
|
set oldArray(oldArray) {
|
|
@@ -55,7 +58,7 @@ class TinyArrayComparator {
|
|
|
55
58
|
}
|
|
56
59
|
/**
|
|
57
60
|
* Initializes the comparator with an optional base array.
|
|
58
|
-
* @param {
|
|
61
|
+
* @param {ArrayItem[]} [oldArray] - The initial state of the array to be stored.
|
|
59
62
|
*/
|
|
60
63
|
constructor(oldArray) {
|
|
61
64
|
if (typeof oldArray !== 'undefined')
|
|
@@ -63,7 +66,7 @@ class TinyArrayComparator {
|
|
|
63
66
|
}
|
|
64
67
|
/**
|
|
65
68
|
* Proxy to generates a hash converted to a string.
|
|
66
|
-
* @param {
|
|
69
|
+
* @param {ArrayItem} item - The item to be hashed (can be an object, array, string, or number).
|
|
67
70
|
* @returns {string} The unique hash representing the item's value.
|
|
68
71
|
* @private
|
|
69
72
|
*/
|
|
@@ -73,14 +76,14 @@ class TinyArrayComparator {
|
|
|
73
76
|
/**
|
|
74
77
|
* Compares the stored older array with a newer array and identifies missing or new items.
|
|
75
78
|
*
|
|
76
|
-
* @param {
|
|
77
|
-
* @returns {AffectedItems} An array containing the affected items and their status.
|
|
79
|
+
* @param {ArrayItem[]} newArray - The modified state of the array.
|
|
80
|
+
* @returns {AffectedItems<ArrayItem>} An array containing the affected items and their status.
|
|
78
81
|
* @throws {TypeError} Throws an error if the provided value is not an array.
|
|
79
82
|
*/
|
|
80
83
|
compare(newArray) {
|
|
81
84
|
if (!Array.isArray(newArray))
|
|
82
85
|
throw new TypeError('The provided newArray must be a valid Array.');
|
|
83
|
-
/** @type {InternalState} */
|
|
86
|
+
/** @type {InternalState<ArrayItem>} */
|
|
84
87
|
const state = {
|
|
85
88
|
oldItemsMap: new Map(),
|
|
86
89
|
affectedItems: [],
|
|
@@ -4,28 +4,42 @@
|
|
|
4
4
|
* A predicate function used to determine whether an item should be included in the filtered results.
|
|
5
5
|
* Works similarly to the callback function of `Array.prototype.filter`.
|
|
6
6
|
*
|
|
7
|
+
* @template {any} ArrayItem
|
|
7
8
|
* @callback GetFilter
|
|
8
|
-
* @param {
|
|
9
|
+
* @param {ArrayItem} value - The current element being processed in the array.
|
|
9
10
|
* @param {number} index - The index of the current element within the array.
|
|
10
|
-
* @param {
|
|
11
|
+
* @param {ArrayItem[]} array - The full array being processed.
|
|
11
12
|
* @returns {boolean} Returns `true` to include the element in the results, or `false` to exclude it.
|
|
12
13
|
*/
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @template {any} ArrayItem
|
|
17
|
+
* @typedef {Object} GetterResult
|
|
18
|
+
* @property {ArrayItem[]} items - The subset of items for the requested page.
|
|
19
|
+
* @property {number} page - The current (validated) page number.
|
|
20
|
+
* @property {number} perPage - Number of items per page used in the calculation.
|
|
21
|
+
* @property {number} totalItems - Total number of items in the filtered data.
|
|
22
|
+
* @property {number} totalPages - Total number of pages available.
|
|
23
|
+
* @property {boolean} hasPrev - Whether a previous page exists.
|
|
24
|
+
* @property {boolean} hasNext - Whether a next page exists.
|
|
25
|
+
*/
|
|
26
|
+
|
|
14
27
|
/**
|
|
15
28
|
* A encapsulated wrapper for array pagination.
|
|
16
29
|
* Provides methods to retrieve paginated results with metadata,
|
|
17
30
|
* while keeping the source array safe from direct modifications.
|
|
31
|
+
* @template {any} ArrayItem
|
|
18
32
|
*/
|
|
19
33
|
class TinyArrayPaginator {
|
|
20
34
|
/**
|
|
21
35
|
* Internal storage for the paginated data source.
|
|
22
|
-
* @type {
|
|
36
|
+
* @type {ArrayItem[]|Set<ArrayItem>}
|
|
23
37
|
*/
|
|
24
38
|
#data;
|
|
25
39
|
|
|
26
40
|
/**
|
|
27
41
|
* Gets current stored array.
|
|
28
|
-
* @returns {
|
|
42
|
+
* @returns {ArrayItem[]|Set<ArrayItem>}
|
|
29
43
|
*/
|
|
30
44
|
get data() {
|
|
31
45
|
return this.#data;
|
|
@@ -33,7 +47,7 @@ class TinyArrayPaginator {
|
|
|
33
47
|
|
|
34
48
|
/**
|
|
35
49
|
* Replaces the current data array.
|
|
36
|
-
* @param {
|
|
50
|
+
* @param {ArrayItem[]|Set<ArrayItem>} value - The new array to be used as the data source.
|
|
37
51
|
* @throws {TypeError} If the provided value is not an array.
|
|
38
52
|
*/
|
|
39
53
|
set data(value) {
|
|
@@ -52,7 +66,7 @@ class TinyArrayPaginator {
|
|
|
52
66
|
|
|
53
67
|
/**
|
|
54
68
|
* Creates a new paginator instance for the given data array.
|
|
55
|
-
* @param {
|
|
69
|
+
* @param {ArrayItem[]|Set<ArrayItem>} data - The array to be paginated.
|
|
56
70
|
* @throws {TypeError} If the provided data is not an array.
|
|
57
71
|
*/
|
|
58
72
|
constructor(data) {
|
|
@@ -66,18 +80,10 @@ class TinyArrayPaginator {
|
|
|
66
80
|
* @param {Object} settings
|
|
67
81
|
* @param {number} settings.page - The page number (1-based index).
|
|
68
82
|
* @param {number} settings.perPage - Items per page.
|
|
69
|
-
* @param {Record<string,
|
|
83
|
+
* @param {Record<string, ArrayItem|RegExp> | GetFilter<ArrayItem>} [settings.filter=null] - Filtering criteria:
|
|
70
84
|
* - Object: key-value pairs for exact match, substring match, or RegExp
|
|
71
85
|
* - Function: custom filter function returning true for items to include
|
|
72
|
-
* @returns {
|
|
73
|
-
* items: any[], // The subset of items for the requested page.
|
|
74
|
-
* page: number, // The current (validated) page number.
|
|
75
|
-
* perPage: number, // Number of items per page used in the calculation.
|
|
76
|
-
* totalItems: number, // Total number of items in the filtered data.
|
|
77
|
-
* totalPages: number, // Total number of pages available.
|
|
78
|
-
* hasPrev: boolean, // Whether a previous page exists.
|
|
79
|
-
* hasNext: boolean // Whether a next page exists.
|
|
80
|
-
* }}
|
|
86
|
+
* @returns {GetterResult<ArrayItem>}
|
|
81
87
|
*/
|
|
82
88
|
get({ page, perPage, filter }) {
|
|
83
89
|
if (!Number.isInteger(page) || page < 1)
|
|
@@ -94,6 +100,7 @@ class TinyArrayPaginator {
|
|
|
94
100
|
} else if (typeof filter === 'object') {
|
|
95
101
|
dataToUse = data.filter((item) =>
|
|
96
102
|
Object.entries(filter).every(([key, value]) => {
|
|
103
|
+
// @ts-ignore
|
|
97
104
|
const v = item[key];
|
|
98
105
|
if (value instanceof RegExp) return value.test(v);
|
|
99
106
|
return v === value;
|
|
@@ -3,40 +3,83 @@ export default TinyArrayPaginator;
|
|
|
3
3
|
* A predicate function used to determine whether an item should be included in the filtered results.
|
|
4
4
|
* Works similarly to the callback function of `Array.prototype.filter`.
|
|
5
5
|
*/
|
|
6
|
-
export type GetFilter = (value:
|
|
6
|
+
export type GetFilter<ArrayItem extends unknown> = (value: ArrayItem, index: number, array: ArrayItem[]) => boolean;
|
|
7
|
+
export type GetterResult<ArrayItem extends unknown> = {
|
|
8
|
+
/**
|
|
9
|
+
* - The subset of items for the requested page.
|
|
10
|
+
*/
|
|
11
|
+
items: ArrayItem[];
|
|
12
|
+
/**
|
|
13
|
+
* - The current (validated) page number.
|
|
14
|
+
*/
|
|
15
|
+
page: number;
|
|
16
|
+
/**
|
|
17
|
+
* - Number of items per page used in the calculation.
|
|
18
|
+
*/
|
|
19
|
+
perPage: number;
|
|
20
|
+
/**
|
|
21
|
+
* - Total number of items in the filtered data.
|
|
22
|
+
*/
|
|
23
|
+
totalItems: number;
|
|
24
|
+
/**
|
|
25
|
+
* - Total number of pages available.
|
|
26
|
+
*/
|
|
27
|
+
totalPages: number;
|
|
28
|
+
/**
|
|
29
|
+
* - Whether a previous page exists.
|
|
30
|
+
*/
|
|
31
|
+
hasPrev: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* - Whether a next page exists.
|
|
34
|
+
*/
|
|
35
|
+
hasNext: boolean;
|
|
36
|
+
};
|
|
7
37
|
/**
|
|
8
38
|
* A predicate function used to determine whether an item should be included in the filtered results.
|
|
9
39
|
* Works similarly to the callback function of `Array.prototype.filter`.
|
|
10
40
|
*
|
|
41
|
+
* @template {any} ArrayItem
|
|
11
42
|
* @callback GetFilter
|
|
12
|
-
* @param {
|
|
43
|
+
* @param {ArrayItem} value - The current element being processed in the array.
|
|
13
44
|
* @param {number} index - The index of the current element within the array.
|
|
14
|
-
* @param {
|
|
45
|
+
* @param {ArrayItem[]} array - The full array being processed.
|
|
15
46
|
* @returns {boolean} Returns `true` to include the element in the results, or `false` to exclude it.
|
|
16
47
|
*/
|
|
48
|
+
/**
|
|
49
|
+
* @template {any} ArrayItem
|
|
50
|
+
* @typedef {Object} GetterResult
|
|
51
|
+
* @property {ArrayItem[]} items - The subset of items for the requested page.
|
|
52
|
+
* @property {number} page - The current (validated) page number.
|
|
53
|
+
* @property {number} perPage - Number of items per page used in the calculation.
|
|
54
|
+
* @property {number} totalItems - Total number of items in the filtered data.
|
|
55
|
+
* @property {number} totalPages - Total number of pages available.
|
|
56
|
+
* @property {boolean} hasPrev - Whether a previous page exists.
|
|
57
|
+
* @property {boolean} hasNext - Whether a next page exists.
|
|
58
|
+
*/
|
|
17
59
|
/**
|
|
18
60
|
* A encapsulated wrapper for array pagination.
|
|
19
61
|
* Provides methods to retrieve paginated results with metadata,
|
|
20
62
|
* while keeping the source array safe from direct modifications.
|
|
63
|
+
* @template {any} ArrayItem
|
|
21
64
|
*/
|
|
22
|
-
declare class TinyArrayPaginator {
|
|
65
|
+
declare class TinyArrayPaginator<ArrayItem extends unknown> {
|
|
23
66
|
/**
|
|
24
67
|
* Creates a new paginator instance for the given data array.
|
|
25
|
-
* @param {
|
|
68
|
+
* @param {ArrayItem[]|Set<ArrayItem>} data - The array to be paginated.
|
|
26
69
|
* @throws {TypeError} If the provided data is not an array.
|
|
27
70
|
*/
|
|
28
|
-
constructor(data:
|
|
71
|
+
constructor(data: ArrayItem[] | Set<ArrayItem>);
|
|
29
72
|
/**
|
|
30
73
|
* Replaces the current data array.
|
|
31
|
-
* @param {
|
|
74
|
+
* @param {ArrayItem[]|Set<ArrayItem>} value - The new array to be used as the data source.
|
|
32
75
|
* @throws {TypeError} If the provided value is not an array.
|
|
33
76
|
*/
|
|
34
|
-
set data(value:
|
|
77
|
+
set data(value: ArrayItem[] | Set<ArrayItem>);
|
|
35
78
|
/**
|
|
36
79
|
* Gets current stored array.
|
|
37
|
-
* @returns {
|
|
80
|
+
* @returns {ArrayItem[]|Set<ArrayItem>}
|
|
38
81
|
*/
|
|
39
|
-
get data():
|
|
82
|
+
get data(): ArrayItem[] | Set<ArrayItem>;
|
|
40
83
|
/**
|
|
41
84
|
* Gets the total number of items in the current data array.
|
|
42
85
|
* @returns {number} Total number of stored items.
|
|
@@ -47,32 +90,16 @@ declare class TinyArrayPaginator {
|
|
|
47
90
|
* @param {Object} settings
|
|
48
91
|
* @param {number} settings.page - The page number (1-based index).
|
|
49
92
|
* @param {number} settings.perPage - Items per page.
|
|
50
|
-
* @param {Record<string,
|
|
93
|
+
* @param {Record<string, ArrayItem|RegExp> | GetFilter<ArrayItem>} [settings.filter=null] - Filtering criteria:
|
|
51
94
|
* - Object: key-value pairs for exact match, substring match, or RegExp
|
|
52
95
|
* - Function: custom filter function returning true for items to include
|
|
53
|
-
* @returns {
|
|
54
|
-
* items: any[], // The subset of items for the requested page.
|
|
55
|
-
* page: number, // The current (validated) page number.
|
|
56
|
-
* perPage: number, // Number of items per page used in the calculation.
|
|
57
|
-
* totalItems: number, // Total number of items in the filtered data.
|
|
58
|
-
* totalPages: number, // Total number of pages available.
|
|
59
|
-
* hasPrev: boolean, // Whether a previous page exists.
|
|
60
|
-
* hasNext: boolean // Whether a next page exists.
|
|
61
|
-
* }}
|
|
96
|
+
* @returns {GetterResult<ArrayItem>}
|
|
62
97
|
*/
|
|
63
98
|
get({ page, perPage, filter }: {
|
|
64
99
|
page: number;
|
|
65
100
|
perPage: number;
|
|
66
|
-
filter?: Record<string,
|
|
67
|
-
}):
|
|
68
|
-
items: any[];
|
|
69
|
-
page: number;
|
|
70
|
-
perPage: number;
|
|
71
|
-
totalItems: number;
|
|
72
|
-
totalPages: number;
|
|
73
|
-
hasPrev: boolean;
|
|
74
|
-
hasNext: boolean;
|
|
75
|
-
};
|
|
101
|
+
filter?: Record<string, RegExp | ArrayItem> | GetFilter<ArrayItem> | undefined;
|
|
102
|
+
}): GetterResult<ArrayItem>;
|
|
76
103
|
#private;
|
|
77
104
|
}
|
|
78
105
|
//# sourceMappingURL=TinyArrayPaginator.d.mts.map
|