tiny-essentials 1.28.4 → 1.28.5
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/changelog/1/28/5.md +31 -0
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyMediaPlayer.min.js +1 -1
- package/dist/v1/TinyTimeout.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/index.cjs +4 -0
- package/dist/v1/basics/index.d.mts +3 -2
- package/dist/v1/basics/index.mjs +3 -2
- package/dist/v1/basics/mediaContent.cjs +1 -0
- package/dist/v1/basics/mediaContent.d.mts +4 -0
- package/dist/v1/basics/mediaContent.mjs +1 -0
- package/dist/v1/basics/objChecker.cjs +16 -0
- package/dist/v1/basics/objChecker.d.mts +12 -0
- package/dist/v1/basics/objChecker.mjs +14 -0
- package/dist/v1/basics/objFilter.cjs +0 -2
- package/dist/v1/basics/objFilter.d.mts +0 -2
- package/dist/v1/basics/objFilter.mjs +1 -2
- package/dist/v1/basics/promiseUtils.cjs +101 -0
- package/dist/v1/basics/promiseUtils.d.mts +31 -0
- package/dist/v1/basics/promiseUtils.mjs +89 -0
- package/dist/v1/index.cjs +4 -0
- package/dist/v1/index.d.mts +3 -2
- package/dist/v1/index.mjs +3 -2
- package/dist/v1/libs/TinyMediaPlayer/HtmlAudio.cjs +268 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlAudio.d.mts +118 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlAudio.mjs +237 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlVideo.cjs +265 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlVideo.d.mts +118 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlVideo.mjs +234 -0
- package/dist/v1/libs/TinyMediaPlayer/Youtube.cjs +671 -0
- package/dist/v1/libs/TinyMediaPlayer/Youtube.d.mts +259 -0
- package/dist/v1/libs/TinyMediaPlayer/Youtube.mjs +597 -0
- package/dist/v1/libs/TinyMediaPlayer/docs/YouTubePlayer.cjs +546 -0
- package/dist/v1/libs/TinyMediaPlayer/docs/YouTubePlayer.d.mts +657 -0
- package/dist/v1/libs/TinyMediaPlayer/docs/YouTubePlayer.mjs +480 -0
- package/dist/v1/libs/TinyMediaPlayer/index.cjs +165 -0
- package/dist/v1/libs/TinyMediaPlayer/index.d.mts +102 -0
- package/dist/v1/libs/TinyMediaPlayer/index.mjs +144 -0
- package/dist/v1/libs/TinyMediaPlayer.cjs +589 -103
- package/dist/v1/libs/TinyMediaPlayer.d.mts +150 -65
- package/dist/v1/libs/TinyMediaPlayer.mjs +535 -93
- package/dist/v1/libs/TinyTimeout.cjs +4 -14
- package/dist/v1/libs/TinyTimeout.d.mts +1 -0
- package/dist/v1/libs/TinyTimeout.mjs +4 -13
- package/docs/v1/basics/mediaContent.md +1 -1
- package/docs/v1/basics/objChecker.md +13 -0
- package/docs/v1/basics/promiseUtils.md +32 -0
- package/docs/v1/libs/TinyMediaPlayer.md +239 -32
- package/docs/v1/libs/TinyTimeout.md +1 -14
- package/package.json +21 -1
package/dist/v1/basics/index.cjs
CHANGED
|
@@ -10,6 +10,7 @@ var simpleMath = require('./simpleMath.cjs');
|
|
|
10
10
|
var text = require('./text.cjs');
|
|
11
11
|
var collision = require('./collision.cjs');
|
|
12
12
|
var mediaContent = require('./mediaContent.cjs');
|
|
13
|
+
var promiseUtils = require('./promiseUtils.cjs');
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
|
|
@@ -37,6 +38,7 @@ exports.objTypeName = objFilter.objTypeName;
|
|
|
37
38
|
exports.reorderObjTypeOrder = objFilter.reorderObjTypeOrder;
|
|
38
39
|
exports.countObj = objChecker.countObj;
|
|
39
40
|
exports.isJsonObject = objChecker.isJsonObject;
|
|
41
|
+
exports.isValidObj = objChecker.isValidObj;
|
|
40
42
|
exports.documentIsFullScreen = fullScreen.documentIsFullScreen;
|
|
41
43
|
exports.exitFullScreen = fullScreen.exitFullScreen;
|
|
42
44
|
exports.isFullScreenMode = fullScreen.isFullScreenMode;
|
|
@@ -81,3 +83,5 @@ exports.extractMediaId3Tags = mediaContent.extractMediaId3Tags;
|
|
|
81
83
|
exports.parseMediaMetadata = mediaContent.parseMediaMetadata;
|
|
82
84
|
exports.valMediaContentMetadata = mediaContent.valMediaContentMetadata;
|
|
83
85
|
exports.valMediaContentMetadataPartial = mediaContent.valMediaContentMetadataPartial;
|
|
86
|
+
exports.createSingletonTask = promiseUtils.createSingletonTask;
|
|
87
|
+
exports.waitForTrue = promiseUtils.waitForTrue;
|
|
@@ -2,11 +2,12 @@ import { diffArrayList, shuffleArray, arraySortPositions, multiplyArrayBlocks }
|
|
|
2
2
|
import { breakdownDuration, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration } from './clock.mjs';
|
|
3
3
|
import { readJsonBlob, saveJsonFile, fetchJson, installWindowHiddenScript, readFileBlob, readBase64Blob, fetchText } from './html.mjs';
|
|
4
4
|
import { extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType, isObjType, objTypeName } from './objFilter.mjs';
|
|
5
|
-
import { countObj, isJsonObject } from './objChecker.mjs';
|
|
5
|
+
import { countObj, isJsonObject, isValidObj } from './objChecker.mjs';
|
|
6
6
|
import { documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange } from './fullScreen.mjs';
|
|
7
7
|
import { calculateMarketcap, compareMarketcap, formatBytes, genFibonacciSeq, getAge, getPercentage, getSimplePerc, ruleOfThree } from './simpleMath.mjs';
|
|
8
8
|
import { addAiMarkerShortcut, diffStrings, diffObjList, safeTextTrim, toTitleCase, toTitleCaseLowerFirst, asyncReplace } from './text.mjs';
|
|
9
9
|
import { areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails } from './collision.mjs';
|
|
10
10
|
import { extractMediaId3Tags, parseMediaMetadata, valMediaContentMetadata, valMediaContentMetadataPartial } from './mediaContent.mjs';
|
|
11
|
-
|
|
11
|
+
import { createSingletonTask, waitForTrue } from './promiseUtils.mjs';
|
|
12
|
+
export { isValidObj, createSingletonTask, waitForTrue, multiplyArrayBlocks, valMediaContentMetadata, valMediaContentMetadataPartial, parseMediaMetadata, extractMediaId3Tags, diffStrings, diffObjList, diffArrayList, 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, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, isObjType, objTypeName, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
|
|
12
13
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/v1/basics/index.mjs
CHANGED
|
@@ -2,10 +2,11 @@ import { diffArrayList, shuffleArray, arraySortPositions, multiplyArrayBlocks }
|
|
|
2
2
|
import { breakdownDuration, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, } from './clock.mjs';
|
|
3
3
|
import { readJsonBlob, saveJsonFile, fetchJson, installWindowHiddenScript, readFileBlob, readBase64Blob, fetchText, } from './html.mjs';
|
|
4
4
|
import { extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType, isObjType, objTypeName, } from './objFilter.mjs';
|
|
5
|
-
import { countObj, isJsonObject } from './objChecker.mjs';
|
|
5
|
+
import { countObj, isJsonObject, isValidObj } from './objChecker.mjs';
|
|
6
6
|
import { documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, } from './fullScreen.mjs';
|
|
7
7
|
import { calculateMarketcap, compareMarketcap, formatBytes, genFibonacciSeq, getAge, getPercentage, getSimplePerc, ruleOfThree, } from './simpleMath.mjs';
|
|
8
8
|
import { addAiMarkerShortcut, diffStrings, diffObjList, safeTextTrim, toTitleCase, toTitleCaseLowerFirst, asyncReplace, } from './text.mjs';
|
|
9
9
|
import { areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, } from './collision.mjs';
|
|
10
10
|
import { extractMediaId3Tags, parseMediaMetadata, valMediaContentMetadata, valMediaContentMetadataPartial, } from './mediaContent.mjs';
|
|
11
|
-
|
|
11
|
+
import { createSingletonTask, waitForTrue } from './promiseUtils.mjs';
|
|
12
|
+
export { isValidObj, createSingletonTask, waitForTrue, multiplyArrayBlocks, valMediaContentMetadata, valMediaContentMetadataPartial, parseMediaMetadata, extractMediaId3Tags, diffStrings, diffObjList, diffArrayList, 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, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, isObjType, objTypeName, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
* The core properties required for any content item within the media system.
|
|
64
64
|
* @typedef {Object} MediaContentBase
|
|
65
65
|
* @property {string} id - Unique identifier.
|
|
66
|
+
* @property {string} [mediaType] - Media type (e.g., video, audio).
|
|
66
67
|
* @property {string} title - Name of the track/message.
|
|
67
68
|
* @property {string} artist - Artist or speaker name.
|
|
68
69
|
* @property {number} duration - Duration in milliseconds.
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
* The core properties required for any content item within the media system.
|
|
55
55
|
* @typedef {Object} MediaContentBase
|
|
56
56
|
* @property {string} id - Unique identifier.
|
|
57
|
+
* @property {string} [mediaType] - Media type (e.g., video, audio).
|
|
57
58
|
* @property {string} title - Name of the track/message.
|
|
58
59
|
* @property {string} artist - Artist or speaker name.
|
|
59
60
|
* @property {number} duration - Duration in milliseconds.
|
|
@@ -44,5 +44,21 @@ function isJsonObject(value) {
|
|
|
44
44
|
return true;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Determines whether a given value is a JSON object.
|
|
49
|
+
*
|
|
50
|
+
* A pure object satisfies the following:
|
|
51
|
+
* - It is not null.
|
|
52
|
+
* - Its type is "object".
|
|
53
|
+
* - It is not an Array instance.
|
|
54
|
+
*
|
|
55
|
+
* @param {unknown} value - The value to test.
|
|
56
|
+
* @returns {value is Object<string | number | symbol, unknown>} Returns true if the value is a object.
|
|
57
|
+
*/
|
|
58
|
+
function isValidObj(value) {
|
|
59
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
60
|
+
}
|
|
61
|
+
|
|
47
62
|
exports.countObj = countObj;
|
|
48
63
|
exports.isJsonObject = isJsonObject;
|
|
64
|
+
exports.isValidObj = isValidObj;
|
|
@@ -27,4 +27,16 @@ export declare function countObj(obj: Array<any> | Record<string | number | symb
|
|
|
27
27
|
* @returns {value is Record<string | number | symbol, unknown>} Returns true if the value is a pure object.
|
|
28
28
|
*/
|
|
29
29
|
export declare function isJsonObject(value: unknown): value is Record<string | number | symbol, unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* Determines whether a given value is a JSON object.
|
|
32
|
+
*
|
|
33
|
+
* A pure object satisfies the following:
|
|
34
|
+
* - It is not null.
|
|
35
|
+
* - Its type is "object".
|
|
36
|
+
* - It is not an Array instance.
|
|
37
|
+
*
|
|
38
|
+
* @param {unknown} value - The value to test.
|
|
39
|
+
* @returns {value is Object<string | number | symbol, unknown>} Returns true if the value is a object.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isValidObj(value: unknown): value is any;
|
|
30
42
|
//# sourceMappingURL=objChecker.d.mts.map
|
|
@@ -43,3 +43,17 @@ export function isJsonObject(value) {
|
|
|
43
43
|
return false;
|
|
44
44
|
return true;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Determines whether a given value is a JSON object.
|
|
48
|
+
*
|
|
49
|
+
* A pure object satisfies the following:
|
|
50
|
+
* - It is not null.
|
|
51
|
+
* - Its type is "object".
|
|
52
|
+
* - It is not an Array instance.
|
|
53
|
+
*
|
|
54
|
+
* @param {unknown} value - The value to test.
|
|
55
|
+
* @returns {value is Object<string | number | symbol, unknown>} Returns true if the value is a object.
|
|
56
|
+
*/
|
|
57
|
+
export function isValidObj(value) {
|
|
58
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
59
|
+
}
|
|
@@ -368,8 +368,6 @@ extendObjType([
|
|
|
368
368
|
],
|
|
369
369
|
]);
|
|
370
370
|
|
|
371
|
-
exports.countObj = objChecker.countObj;
|
|
372
|
-
exports.isJsonObject = objChecker.isJsonObject;
|
|
373
371
|
exports.checkObj = checkObj;
|
|
374
372
|
exports.cloneObjTypeOrder = cloneObjTypeOrder;
|
|
375
373
|
exports.extendObjType = extendObjType;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { countObj, isJsonObject } from './objChecker.mjs';
|
|
2
|
-
export { countObj, isJsonObject };
|
|
3
1
|
export type ExtendObjType = Object<string, (val: any) => any>;
|
|
4
2
|
export type ExtendObjTypeArray = Array<[string, (val: any) => any]>;
|
|
5
3
|
/** @typedef {Object.<string, (val: any) => *>} ExtendObjType */
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
-
import {
|
|
3
|
-
export { countObj, isJsonObject };
|
|
2
|
+
import { isJsonObject } from './objChecker.mjs';
|
|
4
3
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
5
4
|
/**
|
|
6
5
|
* An object containing type validation functions and their evaluation order.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Waits until a provided function returns `true`, checking repeatedly at the defined interval.
|
|
5
|
+
* Useful for polling asynchronous conditions.
|
|
6
|
+
*
|
|
7
|
+
* @param {() => boolean} getValue - A function that returns `true` when the condition is met.
|
|
8
|
+
* @param {number} [checkInterval=100] - How often (in ms) to check the condition.
|
|
9
|
+
* @returns {Promise<void>} Resolves when the condition is met.
|
|
10
|
+
* @throws {TypeError} If arguments are invalid.
|
|
11
|
+
*/
|
|
12
|
+
const waitForTrue = (getValue, checkInterval = 100) => {
|
|
13
|
+
if (typeof getValue !== 'function') throw new TypeError(`Expected 'getValue' to be a function.`);
|
|
14
|
+
if (!Number.isFinite(checkInterval) || checkInterval <= 0)
|
|
15
|
+
throw new TypeError(`Expected 'checkInterval' to be a positive number.`);
|
|
16
|
+
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
const interval = setInterval(() => {
|
|
19
|
+
if (getValue()) {
|
|
20
|
+
clearInterval(interval);
|
|
21
|
+
resolve();
|
|
22
|
+
}
|
|
23
|
+
}, checkInterval);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates a controller object that manages the execution state of an asynchronous function,
|
|
29
|
+
* ensuring it only executes one instance at a time. If a task is already in progress,
|
|
30
|
+
* subsequent calls to the callback will wait for the existing promise to resolve.
|
|
31
|
+
*
|
|
32
|
+
* @template {any} T
|
|
33
|
+
* @template {any[]} A
|
|
34
|
+
* @param {(...args: A) => Promise<T>} baseFunction - The asynchronous function to be wrapped.
|
|
35
|
+
* @returns {{
|
|
36
|
+
* callback: (...args: A) => Promise<T>,
|
|
37
|
+
* getActivePromise: () => Promise<T> | null,
|
|
38
|
+
* resetActivePromise: () => void
|
|
39
|
+
* }} An object containing the execution controller.
|
|
40
|
+
* @throws {TypeError} If the provided baseFunction is not a function.
|
|
41
|
+
*/
|
|
42
|
+
const createSingletonTask = (baseFunction) => {
|
|
43
|
+
// Validation: Ensure the input is a function before proceeding.
|
|
44
|
+
if (typeof baseFunction !== 'function') {
|
|
45
|
+
throw new TypeError('The argument "baseFunction" must be a function.');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @type {Promise<T> | null}
|
|
50
|
+
* Stores the current active promise to prevent multiple simultaneous executions.
|
|
51
|
+
*/
|
|
52
|
+
let activePromise = null;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The wrapped function returned to the user.
|
|
56
|
+
*
|
|
57
|
+
* @param {A} args - The arguments to pass to the base function.
|
|
58
|
+
* @returns {Promise<T>} The result of the base function or the existing promise.
|
|
59
|
+
*/
|
|
60
|
+
const callback = async (...args) => {
|
|
61
|
+
// If a request is already in progress, return the existing promise.
|
|
62
|
+
if (activePromise !== null) {
|
|
63
|
+
return activePromise;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Create the execution wrapper and ASSIGN it to activePromise
|
|
67
|
+
activePromise = (async () => {
|
|
68
|
+
try {
|
|
69
|
+
const result = await baseFunction(...args);
|
|
70
|
+
// Reset after success so the next call can start a new execution
|
|
71
|
+
activePromise = null;
|
|
72
|
+
return result;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
// Reset on error to allow subsequent retry attempts.
|
|
75
|
+
activePromise = null;
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
})();
|
|
79
|
+
|
|
80
|
+
return activePromise;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns the current active promise, or null if no task is running.
|
|
85
|
+
* @returns {Promise<T> | null}
|
|
86
|
+
*/
|
|
87
|
+
const getActivePromise = () => activePromise;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Resets the active promise state, allowing the next call to the callback to start a new execution.
|
|
91
|
+
* @returns {void}
|
|
92
|
+
*/
|
|
93
|
+
const resetActivePromise = () => {
|
|
94
|
+
activePromise = null;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return { callback, getActivePromise, resetActivePromise };
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
exports.createSingletonTask = createSingletonTask;
|
|
101
|
+
exports.waitForTrue = waitForTrue;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waits until a provided function returns `true`, checking repeatedly at the defined interval.
|
|
3
|
+
* Useful for polling asynchronous conditions.
|
|
4
|
+
*
|
|
5
|
+
* @param {() => boolean} getValue - A function that returns `true` when the condition is met.
|
|
6
|
+
* @param {number} [checkInterval=100] - How often (in ms) to check the condition.
|
|
7
|
+
* @returns {Promise<void>} Resolves when the condition is met.
|
|
8
|
+
* @throws {TypeError} If arguments are invalid.
|
|
9
|
+
*/
|
|
10
|
+
export declare const waitForTrue: (getValue: () => boolean, checkInterval?: number) => Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a controller object that manages the execution state of an asynchronous function,
|
|
13
|
+
* ensuring it only executes one instance at a time. If a task is already in progress,
|
|
14
|
+
* subsequent calls to the callback will wait for the existing promise to resolve.
|
|
15
|
+
*
|
|
16
|
+
* @template {any} T
|
|
17
|
+
* @template {any[]} A
|
|
18
|
+
* @param {(...args: A) => Promise<T>} baseFunction - The asynchronous function to be wrapped.
|
|
19
|
+
* @returns {{
|
|
20
|
+
* callback: (...args: A) => Promise<T>,
|
|
21
|
+
* getActivePromise: () => Promise<T> | null,
|
|
22
|
+
* resetActivePromise: () => void
|
|
23
|
+
* }} An object containing the execution controller.
|
|
24
|
+
* @throws {TypeError} If the provided baseFunction is not a function.
|
|
25
|
+
*/
|
|
26
|
+
export declare const createSingletonTask: <T extends any, A extends any[]>(baseFunction: (...args: A) => Promise<T>) => {
|
|
27
|
+
callback: (...args: A) => Promise<T>;
|
|
28
|
+
getActivePromise: () => Promise<T> | null;
|
|
29
|
+
resetActivePromise: () => void;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=promiseUtils.d.mts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waits until a provided function returns `true`, checking repeatedly at the defined interval.
|
|
3
|
+
* Useful for polling asynchronous conditions.
|
|
4
|
+
*
|
|
5
|
+
* @param {() => boolean} getValue - A function that returns `true` when the condition is met.
|
|
6
|
+
* @param {number} [checkInterval=100] - How often (in ms) to check the condition.
|
|
7
|
+
* @returns {Promise<void>} Resolves when the condition is met.
|
|
8
|
+
* @throws {TypeError} If arguments are invalid.
|
|
9
|
+
*/
|
|
10
|
+
export const waitForTrue = (getValue, checkInterval = 100) => {
|
|
11
|
+
if (typeof getValue !== 'function')
|
|
12
|
+
throw new TypeError(`Expected 'getValue' to be a function.`);
|
|
13
|
+
if (!Number.isFinite(checkInterval) || checkInterval <= 0)
|
|
14
|
+
throw new TypeError(`Expected 'checkInterval' to be a positive number.`);
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
const interval = setInterval(() => {
|
|
17
|
+
if (getValue()) {
|
|
18
|
+
clearInterval(interval);
|
|
19
|
+
resolve();
|
|
20
|
+
}
|
|
21
|
+
}, checkInterval);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Creates a controller object that manages the execution state of an asynchronous function,
|
|
26
|
+
* ensuring it only executes one instance at a time. If a task is already in progress,
|
|
27
|
+
* subsequent calls to the callback will wait for the existing promise to resolve.
|
|
28
|
+
*
|
|
29
|
+
* @template {any} T
|
|
30
|
+
* @template {any[]} A
|
|
31
|
+
* @param {(...args: A) => Promise<T>} baseFunction - The asynchronous function to be wrapped.
|
|
32
|
+
* @returns {{
|
|
33
|
+
* callback: (...args: A) => Promise<T>,
|
|
34
|
+
* getActivePromise: () => Promise<T> | null,
|
|
35
|
+
* resetActivePromise: () => void
|
|
36
|
+
* }} An object containing the execution controller.
|
|
37
|
+
* @throws {TypeError} If the provided baseFunction is not a function.
|
|
38
|
+
*/
|
|
39
|
+
export const createSingletonTask = (baseFunction) => {
|
|
40
|
+
// Validation: Ensure the input is a function before proceeding.
|
|
41
|
+
if (typeof baseFunction !== 'function') {
|
|
42
|
+
throw new TypeError('The argument "baseFunction" must be a function.');
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @type {Promise<T> | null}
|
|
46
|
+
* Stores the current active promise to prevent multiple simultaneous executions.
|
|
47
|
+
*/
|
|
48
|
+
let activePromise = null;
|
|
49
|
+
/**
|
|
50
|
+
* The wrapped function returned to the user.
|
|
51
|
+
*
|
|
52
|
+
* @param {A} args - The arguments to pass to the base function.
|
|
53
|
+
* @returns {Promise<T>} The result of the base function or the existing promise.
|
|
54
|
+
*/
|
|
55
|
+
const callback = async (...args) => {
|
|
56
|
+
// If a request is already in progress, return the existing promise.
|
|
57
|
+
if (activePromise !== null) {
|
|
58
|
+
return activePromise;
|
|
59
|
+
}
|
|
60
|
+
// Create the execution wrapper and ASSIGN it to activePromise
|
|
61
|
+
activePromise = (async () => {
|
|
62
|
+
try {
|
|
63
|
+
const result = await baseFunction(...args);
|
|
64
|
+
// Reset after success so the next call can start a new execution
|
|
65
|
+
activePromise = null;
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
// Reset on error to allow subsequent retry attempts.
|
|
70
|
+
activePromise = null;
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
74
|
+
return activePromise;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Returns the current active promise, or null if no task is running.
|
|
78
|
+
* @returns {Promise<T> | null}
|
|
79
|
+
*/
|
|
80
|
+
const getActivePromise = () => activePromise;
|
|
81
|
+
/**
|
|
82
|
+
* Resets the active promise state, allowing the next call to the callback to start a new execution.
|
|
83
|
+
* @returns {void}
|
|
84
|
+
*/
|
|
85
|
+
const resetActivePromise = () => {
|
|
86
|
+
activePromise = null;
|
|
87
|
+
};
|
|
88
|
+
return { callback, getActivePromise, resetActivePromise };
|
|
89
|
+
};
|
package/dist/v1/index.cjs
CHANGED
|
@@ -55,6 +55,7 @@ var TinyClassManager = require('./libs/TinyClassManager.cjs');
|
|
|
55
55
|
var TinyRadioFm = require('./libs/TinyRadioFm.cjs');
|
|
56
56
|
var TinyMediaPlayer = require('./libs/TinyMediaPlayer.cjs');
|
|
57
57
|
var utils = require('./libs/utils.cjs');
|
|
58
|
+
var promiseUtils = require('./basics/promiseUtils.cjs');
|
|
58
59
|
|
|
59
60
|
|
|
60
61
|
|
|
@@ -77,6 +78,7 @@ exports.objTypeName = objFilter.objTypeName;
|
|
|
77
78
|
exports.reorderObjTypeOrder = objFilter.reorderObjTypeOrder;
|
|
78
79
|
exports.countObj = objChecker.countObj;
|
|
79
80
|
exports.isJsonObject = objChecker.isJsonObject;
|
|
81
|
+
exports.isValidObj = objChecker.isValidObj;
|
|
80
82
|
exports.documentIsFullScreen = fullScreen.documentIsFullScreen;
|
|
81
83
|
exports.exitFullScreen = fullScreen.exitFullScreen;
|
|
82
84
|
exports.isFullScreenMode = fullScreen.isFullScreenMode;
|
|
@@ -201,3 +203,5 @@ exports.TinyClassManager = TinyClassManager;
|
|
|
201
203
|
exports.TinyRadioFm = TinyRadioFm;
|
|
202
204
|
exports.TinyMediaPlayer = TinyMediaPlayer;
|
|
203
205
|
exports.createCheckDestroyed = utils.createCheckDestroyed;
|
|
206
|
+
exports.createSingletonTask = promiseUtils.createSingletonTask;
|
|
207
|
+
exports.waitForTrue = promiseUtils.waitForTrue;
|
package/dist/v1/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import TinyLevelUp from './libs/TinyLevelUp.mjs';
|
|
|
2
2
|
import { diffArrayList, shuffleArray, arraySortPositions, multiplyArrayBlocks } from './basics/array.mjs';
|
|
3
3
|
import { breakdownDuration, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration } from './basics/clock.mjs';
|
|
4
4
|
import { extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType, checkObj, objTypeName, isObjType } from './basics/objFilter.mjs';
|
|
5
|
-
import { countObj, isJsonObject } from './basics/objChecker.mjs';
|
|
5
|
+
import { countObj, isJsonObject, isValidObj } from './basics/objChecker.mjs';
|
|
6
6
|
import { documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange } from './basics/fullScreen.mjs';
|
|
7
7
|
import { calculateMarketcap, compareMarketcap, formatBytes, genFibonacciSeq, getAge, getPercentage, getSimplePerc, ruleOfThree } from './basics/simpleMath.mjs';
|
|
8
8
|
import { addAiMarkerShortcut, diffStrings, diffObjList, safeTextTrim, toTitleCase, toTitleCaseLowerFirst, asyncReplace } from './basics/text.mjs';
|
|
@@ -53,5 +53,6 @@ import TinyClassManager from './libs/TinyClassManager.mjs';
|
|
|
53
53
|
import TinyRadioFm from './libs/TinyRadioFm.mjs';
|
|
54
54
|
import TinyMediaPlayer from './libs/TinyMediaPlayer.mjs';
|
|
55
55
|
import { createCheckDestroyed } from './libs/utils.mjs';
|
|
56
|
-
|
|
56
|
+
import { createSingletonTask, waitForTrue } from './basics/promiseUtils.mjs';
|
|
57
|
+
export { TinyMediaPlayer, TinyRadioFm, TinyClassManager, FuzzySet, MamdaniInferenceSystem, TinyArrayComparator, TinyTextDiffer, TinyAnalogClock, TinyColorValidator, TinyLoadingScreen, TinyElementObserver, TinySimpleDice, TinyNeedBar, TinyI18, TinyCookieConsent, TinyInventory, TinyInventoryTrader, TinyArrayPaginator, TinyAdvancedRaffle, TinyDayNightCycle, TinyGamepad, TinyTextarea, TinyNewWinEvents, TinyIframeEvents, TinyLocalStorage, TinyTimeout, TinyColorConverter, TinyClipboard, TinyTextRangeEditor, TinySmartScroller, UltraRandomMsgGen, TinyAfterScrollWatcher, TinyHtml, TinyNotifications, TinyDomReadyManager, TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, isValidObj, createSingletonTask, waitForTrue, multiplyArrayBlocks, createCheckDestroyed, valMediaContentMetadata, valMediaContentMetadataPartial, parseMediaMetadata, extractMediaId3Tags, defuzzifyCentroid, trapezoid, diffArrayList, diffStrings, diffObjList, 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, objTypeName, isObjType, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
|
|
57
58
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/v1/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import TinyLevelUp from './libs/TinyLevelUp.mjs';
|
|
|
2
2
|
import { diffArrayList, shuffleArray, arraySortPositions, multiplyArrayBlocks, } from './basics/array.mjs';
|
|
3
3
|
import { breakdownDuration, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, } from './basics/clock.mjs';
|
|
4
4
|
import { extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType, checkObj, objTypeName, isObjType, } from './basics/objFilter.mjs';
|
|
5
|
-
import { countObj, isJsonObject } from './basics/objChecker.mjs';
|
|
5
|
+
import { countObj, isJsonObject, isValidObj } from './basics/objChecker.mjs';
|
|
6
6
|
import { documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, } from './basics/fullScreen.mjs';
|
|
7
7
|
import { calculateMarketcap, compareMarketcap, formatBytes, genFibonacciSeq, getAge, getPercentage, getSimplePerc, ruleOfThree, } from './basics/simpleMath.mjs';
|
|
8
8
|
import { addAiMarkerShortcut, diffStrings, diffObjList, safeTextTrim, toTitleCase, toTitleCaseLowerFirst, asyncReplace, } from './basics/text.mjs';
|
|
@@ -53,7 +53,8 @@ import TinyClassManager from './libs/TinyClassManager.mjs';
|
|
|
53
53
|
import TinyRadioFm from './libs/TinyRadioFm.mjs';
|
|
54
54
|
import TinyMediaPlayer from './libs/TinyMediaPlayer.mjs';
|
|
55
55
|
import { createCheckDestroyed } from './libs/utils.mjs';
|
|
56
|
+
import { createSingletonTask, waitForTrue } from './basics/promiseUtils.mjs';
|
|
56
57
|
// import TinyHtmlElems from './libs/TinyHtml/index.mjs';
|
|
57
58
|
export { TinyMediaPlayer, TinyRadioFm, TinyClassManager, FuzzySet, MamdaniInferenceSystem, TinyArrayComparator, TinyTextDiffer, TinyAnalogClock,
|
|
58
59
|
// TinyHtmlElems,
|
|
59
|
-
TinyColorValidator, TinyLoadingScreen, TinyElementObserver, TinySimpleDice, TinyNeedBar, TinyI18, TinyCookieConsent, TinyInventory, TinyInventoryTrader, TinyArrayPaginator, TinyAdvancedRaffle, TinyDayNightCycle, TinyGamepad, TinyTextarea, TinyNewWinEvents, TinyIframeEvents, TinyLocalStorage, TinyTimeout, TinyColorConverter, TinyClipboard, TinyTextRangeEditor, TinySmartScroller, UltraRandomMsgGen, TinyAfterScrollWatcher, TinyHtml, TinyNotifications, TinyDomReadyManager, TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, multiplyArrayBlocks, createCheckDestroyed, valMediaContentMetadata, valMediaContentMetadataPartial, parseMediaMetadata, extractMediaId3Tags, defuzzifyCentroid, trapezoid, diffArrayList, diffStrings, diffObjList, 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, objTypeName, isObjType, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
|
|
60
|
+
TinyColorValidator, TinyLoadingScreen, TinyElementObserver, TinySimpleDice, TinyNeedBar, TinyI18, TinyCookieConsent, TinyInventory, TinyInventoryTrader, TinyArrayPaginator, TinyAdvancedRaffle, TinyDayNightCycle, TinyGamepad, TinyTextarea, TinyNewWinEvents, TinyIframeEvents, TinyLocalStorage, TinyTimeout, TinyColorConverter, TinyClipboard, TinyTextRangeEditor, TinySmartScroller, UltraRandomMsgGen, TinyAfterScrollWatcher, TinyHtml, TinyNotifications, TinyDomReadyManager, TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, isValidObj, createSingletonTask, waitForTrue, multiplyArrayBlocks, createCheckDestroyed, valMediaContentMetadata, valMediaContentMetadataPartial, parseMediaMetadata, extractMediaId3Tags, defuzzifyCentroid, trapezoid, diffArrayList, diffStrings, diffObjList, 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, objTypeName, isObjType, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
|