tiny-essentials 1.28.3 → 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/4.md +4 -0
- 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 +21 -30
- package/dist/v1/basics/objFilter.d.mts +0 -2
- package/dist/v1/basics/objFilter.mjs +21 -30
- 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
|
+
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var objChecker = require('./objChecker.cjs');
|
|
4
4
|
|
|
5
|
+
// @ts-nocheck
|
|
6
|
+
|
|
5
7
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -241,49 +243,48 @@ function getCheckObj() {
|
|
|
241
243
|
extendObjType([
|
|
242
244
|
[
|
|
243
245
|
'undefined',
|
|
244
|
-
/** @param {
|
|
246
|
+
/** @param {unknown} val @returns {val is undefined} */
|
|
245
247
|
(val) => typeof val === 'undefined',
|
|
246
248
|
],
|
|
247
249
|
[
|
|
248
250
|
'null',
|
|
249
|
-
/** @param {
|
|
251
|
+
/** @param {unknown} val @returns {val is null} */
|
|
250
252
|
(val) => val === null,
|
|
251
253
|
],
|
|
252
254
|
[
|
|
253
255
|
'boolean',
|
|
254
|
-
/** @param {
|
|
256
|
+
/** @param {unknown} val @returns {val is boolean} */
|
|
255
257
|
(val) => typeof val === 'boolean',
|
|
256
258
|
],
|
|
257
259
|
[
|
|
258
260
|
'number',
|
|
259
|
-
/** @param {
|
|
261
|
+
/** @param {unknown} val @returns {val is number} */
|
|
260
262
|
(val) => typeof val === 'number' && !Number.isNaN(val),
|
|
261
263
|
],
|
|
262
264
|
[
|
|
263
265
|
'bigint',
|
|
264
|
-
/** @param {
|
|
266
|
+
/** @param {unknown} val @returns {val is bigint} */
|
|
265
267
|
(val) => typeof val === 'bigint',
|
|
266
268
|
],
|
|
267
269
|
[
|
|
268
270
|
'string',
|
|
269
|
-
/** @param {
|
|
271
|
+
/** @param {unknown} val @returns {val is string} */
|
|
270
272
|
(val) => typeof val === 'string',
|
|
271
273
|
],
|
|
272
274
|
[
|
|
273
275
|
'symbol',
|
|
274
|
-
/** @param {
|
|
276
|
+
/** @param {unknown} val @returns {val is symbol} */
|
|
275
277
|
(val) => typeof val === 'symbol',
|
|
276
278
|
],
|
|
277
279
|
[
|
|
278
280
|
'function',
|
|
279
|
-
/** @param {
|
|
281
|
+
/** @param {unknown} val @returns {val is Function} */
|
|
280
282
|
(val) => typeof val === 'function',
|
|
281
283
|
],
|
|
282
284
|
[
|
|
283
285
|
'array',
|
|
284
286
|
/**
|
|
285
|
-
* @
|
|
286
|
-
* @param {*} val @returns {val is Value[]}
|
|
287
|
+
* @param {unknown} val @returns {val is unknown[]}
|
|
287
288
|
*/
|
|
288
289
|
(val) => Array.isArray(val),
|
|
289
290
|
],
|
|
@@ -293,7 +294,7 @@ if (isBrowser) {
|
|
|
293
294
|
extendObjType([
|
|
294
295
|
[
|
|
295
296
|
'file',
|
|
296
|
-
/** @param {
|
|
297
|
+
/** @param {unknown} val @returns {val is File} */
|
|
297
298
|
(val) => typeof File !== 'undefined' && val instanceof File,
|
|
298
299
|
],
|
|
299
300
|
]);
|
|
@@ -302,53 +303,46 @@ if (isBrowser) {
|
|
|
302
303
|
extendObjType([
|
|
303
304
|
[
|
|
304
305
|
'date',
|
|
305
|
-
/** @param {
|
|
306
|
+
/** @param {unknown} val @returns {val is Date} */
|
|
306
307
|
(val) => val instanceof Date,
|
|
307
308
|
],
|
|
308
309
|
[
|
|
309
310
|
'regexp',
|
|
310
|
-
/** @param {
|
|
311
|
+
/** @param {unknown} val @returns {val is RegExp} */
|
|
311
312
|
(val) => val instanceof RegExp,
|
|
312
313
|
],
|
|
313
314
|
[
|
|
314
315
|
'map',
|
|
315
316
|
/**
|
|
316
|
-
* @
|
|
317
|
-
* @template {any} Value
|
|
318
|
-
* @param {*} val @returns {val is Map<Key, Value>}
|
|
317
|
+
* @param {unknown} val @returns {val is Map<unknown, unknown>}
|
|
319
318
|
*/
|
|
320
319
|
(val) => val instanceof Map,
|
|
321
320
|
],
|
|
322
321
|
[
|
|
323
322
|
'set',
|
|
324
323
|
/**
|
|
325
|
-
* @
|
|
326
|
-
* @param {*} val @returns {val is Set<Value>}
|
|
324
|
+
* @param {unknown} val @returns {val is Set<unknown>}
|
|
327
325
|
*/
|
|
328
326
|
(val) => val instanceof Set,
|
|
329
327
|
],
|
|
330
328
|
[
|
|
331
329
|
'weakmap',
|
|
332
330
|
/**
|
|
333
|
-
* @
|
|
334
|
-
* @template {any} Value
|
|
335
|
-
* @param {*} val @returns {val is WeakMap<Key, Value>}
|
|
331
|
+
* @param {unknown} val @returns {val is WeakMap<unknown, unknown>}
|
|
336
332
|
*/
|
|
337
333
|
(val) => val instanceof WeakMap,
|
|
338
334
|
],
|
|
339
335
|
[
|
|
340
336
|
'weakset',
|
|
341
337
|
/**
|
|
342
|
-
* @
|
|
343
|
-
* @param {*} val @returns {val is WeakSet<Value>}
|
|
338
|
+
* @param {unknown} val @returns {val is WeakSet<unknown>}
|
|
344
339
|
*/
|
|
345
340
|
(val) => val instanceof WeakSet,
|
|
346
341
|
],
|
|
347
342
|
[
|
|
348
343
|
'promise',
|
|
349
344
|
/**
|
|
350
|
-
* @
|
|
351
|
-
* @param {*} val @returns {val is Promise<Value>}
|
|
345
|
+
* @param {unknown} val @returns {val is Promise<unknown>}
|
|
352
346
|
*/
|
|
353
347
|
(val) => val instanceof Promise,
|
|
354
348
|
],
|
|
@@ -358,7 +352,7 @@ if (isBrowser) {
|
|
|
358
352
|
extendObjType([
|
|
359
353
|
[
|
|
360
354
|
'htmlelement',
|
|
361
|
-
/** @param {
|
|
355
|
+
/** @param {unknown} val @returns {val is HTMLElement} */
|
|
362
356
|
(val) => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement,
|
|
363
357
|
],
|
|
364
358
|
]);
|
|
@@ -368,15 +362,12 @@ extendObjType([
|
|
|
368
362
|
[
|
|
369
363
|
'object',
|
|
370
364
|
/**
|
|
371
|
-
* @
|
|
372
|
-
* @param {*} val @returns {val is Value}
|
|
365
|
+
* @param {unknown} val @returns {val is Record<string | number | symbol, unknown>}
|
|
373
366
|
*/
|
|
374
367
|
(val) => objChecker.isJsonObject(val),
|
|
375
368
|
],
|
|
376
369
|
]);
|
|
377
370
|
|
|
378
|
-
exports.countObj = objChecker.countObj;
|
|
379
|
-
exports.isJsonObject = objChecker.isJsonObject;
|
|
380
371
|
exports.checkObj = checkObj;
|
|
381
372
|
exports.cloneObjTypeOrder = cloneObjTypeOrder;
|
|
382
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,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { isJsonObject } from './objChecker.mjs';
|
|
3
3
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
4
4
|
/**
|
|
5
5
|
* An object containing type validation functions and their evaluation order.
|
|
@@ -215,49 +215,48 @@ export function getCheckObj() {
|
|
|
215
215
|
extendObjType([
|
|
216
216
|
[
|
|
217
217
|
'undefined',
|
|
218
|
-
/** @param {
|
|
218
|
+
/** @param {unknown} val @returns {val is undefined} */
|
|
219
219
|
(val) => typeof val === 'undefined',
|
|
220
220
|
],
|
|
221
221
|
[
|
|
222
222
|
'null',
|
|
223
|
-
/** @param {
|
|
223
|
+
/** @param {unknown} val @returns {val is null} */
|
|
224
224
|
(val) => val === null,
|
|
225
225
|
],
|
|
226
226
|
[
|
|
227
227
|
'boolean',
|
|
228
|
-
/** @param {
|
|
228
|
+
/** @param {unknown} val @returns {val is boolean} */
|
|
229
229
|
(val) => typeof val === 'boolean',
|
|
230
230
|
],
|
|
231
231
|
[
|
|
232
232
|
'number',
|
|
233
|
-
/** @param {
|
|
233
|
+
/** @param {unknown} val @returns {val is number} */
|
|
234
234
|
(val) => typeof val === 'number' && !Number.isNaN(val),
|
|
235
235
|
],
|
|
236
236
|
[
|
|
237
237
|
'bigint',
|
|
238
|
-
/** @param {
|
|
238
|
+
/** @param {unknown} val @returns {val is bigint} */
|
|
239
239
|
(val) => typeof val === 'bigint',
|
|
240
240
|
],
|
|
241
241
|
[
|
|
242
242
|
'string',
|
|
243
|
-
/** @param {
|
|
243
|
+
/** @param {unknown} val @returns {val is string} */
|
|
244
244
|
(val) => typeof val === 'string',
|
|
245
245
|
],
|
|
246
246
|
[
|
|
247
247
|
'symbol',
|
|
248
|
-
/** @param {
|
|
248
|
+
/** @param {unknown} val @returns {val is symbol} */
|
|
249
249
|
(val) => typeof val === 'symbol',
|
|
250
250
|
],
|
|
251
251
|
[
|
|
252
252
|
'function',
|
|
253
|
-
/** @param {
|
|
253
|
+
/** @param {unknown} val @returns {val is Function} */
|
|
254
254
|
(val) => typeof val === 'function',
|
|
255
255
|
],
|
|
256
256
|
[
|
|
257
257
|
'array',
|
|
258
258
|
/**
|
|
259
|
-
* @
|
|
260
|
-
* @param {*} val @returns {val is Value[]}
|
|
259
|
+
* @param {unknown} val @returns {val is unknown[]}
|
|
261
260
|
*/
|
|
262
261
|
(val) => Array.isArray(val),
|
|
263
262
|
],
|
|
@@ -266,7 +265,7 @@ if (isBrowser) {
|
|
|
266
265
|
extendObjType([
|
|
267
266
|
[
|
|
268
267
|
'file',
|
|
269
|
-
/** @param {
|
|
268
|
+
/** @param {unknown} val @returns {val is File} */
|
|
270
269
|
(val) => typeof File !== 'undefined' && val instanceof File,
|
|
271
270
|
],
|
|
272
271
|
]);
|
|
@@ -274,53 +273,46 @@ if (isBrowser) {
|
|
|
274
273
|
extendObjType([
|
|
275
274
|
[
|
|
276
275
|
'date',
|
|
277
|
-
/** @param {
|
|
276
|
+
/** @param {unknown} val @returns {val is Date} */
|
|
278
277
|
(val) => val instanceof Date,
|
|
279
278
|
],
|
|
280
279
|
[
|
|
281
280
|
'regexp',
|
|
282
|
-
/** @param {
|
|
281
|
+
/** @param {unknown} val @returns {val is RegExp} */
|
|
283
282
|
(val) => val instanceof RegExp,
|
|
284
283
|
],
|
|
285
284
|
[
|
|
286
285
|
'map',
|
|
287
286
|
/**
|
|
288
|
-
* @
|
|
289
|
-
* @template {any} Value
|
|
290
|
-
* @param {*} val @returns {val is Map<Key, Value>}
|
|
287
|
+
* @param {unknown} val @returns {val is Map<unknown, unknown>}
|
|
291
288
|
*/
|
|
292
289
|
(val) => val instanceof Map,
|
|
293
290
|
],
|
|
294
291
|
[
|
|
295
292
|
'set',
|
|
296
293
|
/**
|
|
297
|
-
* @
|
|
298
|
-
* @param {*} val @returns {val is Set<Value>}
|
|
294
|
+
* @param {unknown} val @returns {val is Set<unknown>}
|
|
299
295
|
*/
|
|
300
296
|
(val) => val instanceof Set,
|
|
301
297
|
],
|
|
302
298
|
[
|
|
303
299
|
'weakmap',
|
|
304
300
|
/**
|
|
305
|
-
* @
|
|
306
|
-
* @template {any} Value
|
|
307
|
-
* @param {*} val @returns {val is WeakMap<Key, Value>}
|
|
301
|
+
* @param {unknown} val @returns {val is WeakMap<unknown, unknown>}
|
|
308
302
|
*/
|
|
309
303
|
(val) => val instanceof WeakMap,
|
|
310
304
|
],
|
|
311
305
|
[
|
|
312
306
|
'weakset',
|
|
313
307
|
/**
|
|
314
|
-
* @
|
|
315
|
-
* @param {*} val @returns {val is WeakSet<Value>}
|
|
308
|
+
* @param {unknown} val @returns {val is WeakSet<unknown>}
|
|
316
309
|
*/
|
|
317
310
|
(val) => val instanceof WeakSet,
|
|
318
311
|
],
|
|
319
312
|
[
|
|
320
313
|
'promise',
|
|
321
314
|
/**
|
|
322
|
-
* @
|
|
323
|
-
* @param {*} val @returns {val is Promise<Value>}
|
|
315
|
+
* @param {unknown} val @returns {val is Promise<unknown>}
|
|
324
316
|
*/
|
|
325
317
|
(val) => val instanceof Promise,
|
|
326
318
|
],
|
|
@@ -329,7 +321,7 @@ if (isBrowser) {
|
|
|
329
321
|
extendObjType([
|
|
330
322
|
[
|
|
331
323
|
'htmlelement',
|
|
332
|
-
/** @param {
|
|
324
|
+
/** @param {unknown} val @returns {val is HTMLElement} */
|
|
333
325
|
(val) => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement,
|
|
334
326
|
],
|
|
335
327
|
]);
|
|
@@ -338,8 +330,7 @@ extendObjType([
|
|
|
338
330
|
[
|
|
339
331
|
'object',
|
|
340
332
|
/**
|
|
341
|
-
* @
|
|
342
|
-
* @param {*} val @returns {val is Value}
|
|
333
|
+
* @param {unknown} val @returns {val is Record<string | number | symbol, unknown>}
|
|
343
334
|
*/
|
|
344
335
|
(val) => isJsonObject(val),
|
|
345
336
|
],
|
|
@@ -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
|