tiny-essentials 1.18.0 → 1.19.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/README.md +17 -3
- package/dist/legacy/get/countObj.cjs +2 -2
- package/dist/legacy/get/countObj.d.mts +1 -1
- package/dist/legacy/get/countObj.mjs +1 -1
- package/dist/legacy/index.cjs +2 -1
- package/dist/node_modules/firebase-functions/lib/common/trace.cjs +0 -1
- package/dist/node_modules/firebase-functions/lib/logger/index.cjs +1 -0
- package/dist/v1/ColorSafeStringify.min.js +1 -1
- package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
- package/dist/v1/TinyBasicsEs.js +402 -390
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyClipboard.min.js +1 -1
- package/dist/v1/TinyColorConverter.js +617 -0
- package/dist/v1/TinyColorConverter.min.js +1 -0
- package/dist/v1/TinyDomReadyManager.min.js +1 -1
- package/dist/v1/TinyDragger.js +6 -2433
- package/dist/v1/TinyDragger.min.js +1 -2
- package/dist/v1/TinyEssentials.js +3546 -1388
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyEvents.js +402 -0
- package/dist/v1/TinyEvents.min.js +1 -0
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinyLocalStorage.js +1292 -0
- package/dist/v1/TinyLocalStorage.min.js +1 -0
- 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/TinyRateLimiter.js +2 -1
- package/dist/v1/TinyRateLimiter.min.js +1 -1
- package/dist/v1/TinySmartScroller.js +570 -52
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyTextRangeEditor.min.js +1 -1
- package/dist/v1/TinyTimeout.js +233 -0
- package/dist/v1/TinyTimeout.min.js +1 -0
- package/dist/v1/TinyToastNotify.min.js +1 -1
- package/dist/v1/TinyUploadClicker.js +2087 -1129
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/UltraRandomMsgGen.min.js +1 -1
- package/dist/v1/basics/html.cjs +16 -9
- package/dist/v1/basics/html.d.mts +12 -4
- package/dist/v1/basics/html.mjs +14 -7
- package/dist/v1/basics/index.cjs +3 -2
- package/dist/v1/basics/index.d.mts +2 -2
- package/dist/v1/basics/index.mjs +2 -1
- package/dist/v1/basics/objChecker.cjs +46 -0
- package/dist/v1/basics/objChecker.d.mts +29 -0
- package/dist/v1/basics/objChecker.mjs +45 -0
- package/dist/v1/basics/objFilter.cjs +4 -45
- package/dist/v1/basics/objFilter.d.mts +3 -28
- package/dist/v1/basics/objFilter.mjs +2 -45
- package/dist/v1/build/TinyColorConverter.cjs +7 -0
- package/dist/v1/build/TinyColorConverter.d.mts +3 -0
- package/dist/v1/build/TinyColorConverter.mjs +2 -0
- package/dist/v1/build/TinyEvents.cjs +7 -0
- package/dist/v1/build/TinyEvents.d.mts +3 -0
- package/dist/v1/build/TinyEvents.mjs +2 -0
- package/dist/v1/build/TinyLocalStorage.cjs +7 -0
- package/dist/v1/build/TinyLocalStorage.d.mts +3 -0
- package/dist/v1/build/TinyLocalStorage.mjs +2 -0
- package/dist/v1/build/TinyTimeout.cjs +7 -0
- package/dist/v1/build/TinyTimeout.d.mts +3 -0
- package/dist/v1/build/TinyTimeout.mjs +2 -0
- package/dist/v1/index.cjs +11 -2
- package/dist/v1/index.d.mts +7 -3
- package/dist/v1/index.mjs +7 -2
- package/dist/v1/libs/TinyColorConverter.cjs +578 -0
- package/dist/v1/libs/TinyColorConverter.d.mts +396 -0
- package/dist/v1/libs/TinyColorConverter.mjs +520 -0
- package/dist/v1/libs/TinyDragger.cjs +3 -3
- package/dist/v1/libs/TinyDragger.mjs +1 -1
- package/dist/v1/libs/TinyEvents.cjs +363 -0
- package/dist/v1/libs/TinyEvents.d.mts +160 -0
- package/dist/v1/libs/TinyEvents.mjs +328 -0
- package/dist/v1/libs/TinyLocalStorage.cjs +847 -0
- package/dist/v1/libs/TinyLocalStorage.d.mts +407 -0
- package/dist/v1/libs/TinyLocalStorage.mjs +740 -0
- package/dist/v1/libs/TinySmartScroller.cjs +207 -52
- package/dist/v1/libs/TinySmartScroller.d.mts +164 -16
- package/dist/v1/libs/TinySmartScroller.mjs +181 -52
- package/dist/v1/libs/TinyTimeout.cjs +194 -0
- package/dist/v1/libs/TinyTimeout.d.mts +89 -0
- package/dist/v1/libs/TinyTimeout.mjs +179 -0
- package/dist/v1/libs/TinyUploadClicker.cjs +6 -4
- package/docs/v1/README.md +5 -0
- package/docs/v1/basics/objChecker.md +47 -0
- package/docs/v1/basics/objFilter.md +0 -40
- package/docs/v1/libs/TinyColorConverter.md +220 -0
- package/docs/v1/libs/TinyEvents.md +199 -0
- package/docs/v1/libs/TinyLocalStorage.md +350 -0
- package/docs/v1/libs/TinyRateLimiter.md +0 -3
- package/docs/v1/libs/TinyTimeout.md +190 -0
- package/package.json +28 -5
- package/dist/v1/TinyDragger.min.js.LICENSE.txt +0 -8
package/dist/v1/basics/html.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var objChecker = require('./objChecker.cjs');
|
|
4
4
|
|
|
5
5
|
/////////////////////////////////////////////////////////////////
|
|
6
6
|
|
|
@@ -194,7 +194,7 @@ async function fetchTemplate(
|
|
|
194
194
|
Accept: 'application/json',
|
|
195
195
|
...headers,
|
|
196
196
|
},
|
|
197
|
-
body: body !== undefined ? (
|
|
197
|
+
body: body !== undefined ? (objChecker.isJsonObject(body) ? JSON.stringify(body) : body) : undefined,
|
|
198
198
|
signal: localSignal,
|
|
199
199
|
});
|
|
200
200
|
|
|
@@ -233,7 +233,7 @@ async function fetchJson(url, options) {
|
|
|
233
233
|
|
|
234
234
|
const data = await res.json();
|
|
235
235
|
|
|
236
|
-
if (!Array.isArray(data) && !
|
|
236
|
+
if (!Array.isArray(data) && !objChecker.isJsonObject(data))
|
|
237
237
|
throw new Error('Received invalid data instead of valid JSON.');
|
|
238
238
|
|
|
239
239
|
return resolve(data);
|
|
@@ -283,8 +283,8 @@ async function fetchBlob(url, allowedMimeTypes, options) {
|
|
|
283
283
|
* @param {Element} [settings.element=document.body] - The element to receive visibility classes.
|
|
284
284
|
* @param {string} [settings.hiddenClass='windowHidden'] - CSS class applied when the page is hidden.
|
|
285
285
|
* @param {string} [settings.visibleClass='windowVisible'] - CSS class applied when the page is visible.
|
|
286
|
-
* @param {() => void} [settings.onVisible] - Callback called when page becomes visible.
|
|
287
|
-
* @param {() => void} [settings.onHidden] - Callback called when page becomes hidden.
|
|
286
|
+
* @param {(data: { type: string; oldType: string; oldClass: string; }) => void} [settings.onVisible] - Callback called when page becomes visible.
|
|
287
|
+
* @param {(data: { type: string; oldType: string; oldClass: string; }) => void} [settings.onHidden] - Callback called when page becomes hidden.
|
|
288
288
|
* @returns {() => void} Function that removes all installed event listeners.
|
|
289
289
|
* @throws {TypeError} If any provided setting is invalid.
|
|
290
290
|
*/
|
|
@@ -304,6 +304,8 @@ function installWindowHiddenScript({
|
|
|
304
304
|
if (onHidden !== undefined && typeof onHidden !== 'function')
|
|
305
305
|
throw new TypeError(`"onHidden" must be a function if provided.`);
|
|
306
306
|
|
|
307
|
+
let oldType = '';
|
|
308
|
+
let oldClass = '';
|
|
307
309
|
const removeClass = () => {
|
|
308
310
|
element.classList.remove(hiddenClass);
|
|
309
311
|
element.classList.remove(visibleClass);
|
|
@@ -341,19 +343,24 @@ function installWindowHiddenScript({
|
|
|
341
343
|
|
|
342
344
|
if (visibleEvents.includes(type)) {
|
|
343
345
|
element.classList.add(visibleClass);
|
|
344
|
-
onVisible?.();
|
|
346
|
+
onVisible?.({ type, oldClass, oldType });
|
|
347
|
+
oldClass = visibleClass;
|
|
345
348
|
} else if (hiddenEvents.includes(type)) {
|
|
346
349
|
element.classList.add(hiddenClass);
|
|
347
|
-
onHidden?.();
|
|
350
|
+
onHidden?.({ type, oldClass, oldType });
|
|
351
|
+
oldClass = hiddenClass;
|
|
348
352
|
} else {
|
|
349
353
|
if (isHidden) {
|
|
350
354
|
element.classList.add(hiddenClass);
|
|
351
|
-
onHidden?.();
|
|
355
|
+
onHidden?.({ type, oldClass, oldType });
|
|
356
|
+
oldClass = hiddenClass;
|
|
352
357
|
} else {
|
|
353
358
|
element.classList.add(visibleClass);
|
|
354
|
-
onVisible?.();
|
|
359
|
+
onVisible?.({ type, oldClass, oldType });
|
|
360
|
+
oldClass = visibleClass;
|
|
355
361
|
}
|
|
356
362
|
}
|
|
363
|
+
oldType = type;
|
|
357
364
|
};
|
|
358
365
|
|
|
359
366
|
/** @type {() => void} */
|
|
@@ -73,8 +73,8 @@ export function fetchBlob(url: string, allowedMimeTypes?: string[], options?: Ob
|
|
|
73
73
|
* @param {Element} [settings.element=document.body] - The element to receive visibility classes.
|
|
74
74
|
* @param {string} [settings.hiddenClass='windowHidden'] - CSS class applied when the page is hidden.
|
|
75
75
|
* @param {string} [settings.visibleClass='windowVisible'] - CSS class applied when the page is visible.
|
|
76
|
-
* @param {() => void} [settings.onVisible] - Callback called when page becomes visible.
|
|
77
|
-
* @param {() => void} [settings.onHidden] - Callback called when page becomes hidden.
|
|
76
|
+
* @param {(data: { type: string; oldType: string; oldClass: string; }) => void} [settings.onVisible] - Callback called when page becomes visible.
|
|
77
|
+
* @param {(data: { type: string; oldType: string; oldClass: string; }) => void} [settings.onHidden] - Callback called when page becomes hidden.
|
|
78
78
|
* @returns {() => void} Function that removes all installed event listeners.
|
|
79
79
|
* @throws {TypeError} If any provided setting is invalid.
|
|
80
80
|
*/
|
|
@@ -82,8 +82,16 @@ export function installWindowHiddenScript({ element, hiddenClass, visibleClass,
|
|
|
82
82
|
element?: Element | undefined;
|
|
83
83
|
hiddenClass?: string | undefined;
|
|
84
84
|
visibleClass?: string | undefined;
|
|
85
|
-
onVisible?: ((
|
|
86
|
-
|
|
85
|
+
onVisible?: ((data: {
|
|
86
|
+
type: string;
|
|
87
|
+
oldType: string;
|
|
88
|
+
oldClass: string;
|
|
89
|
+
}) => void) | undefined;
|
|
90
|
+
onHidden?: ((data: {
|
|
91
|
+
type: string;
|
|
92
|
+
oldType: string;
|
|
93
|
+
oldClass: string;
|
|
94
|
+
}) => void) | undefined;
|
|
87
95
|
}): () => void;
|
|
88
96
|
export type FetchTemplateOptions = {
|
|
89
97
|
/**
|
package/dist/v1/basics/html.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isJsonObject } from './
|
|
1
|
+
import { isJsonObject } from './objChecker.mjs';
|
|
2
2
|
/////////////////////////////////////////////////////////////////
|
|
3
3
|
/**
|
|
4
4
|
* Reads the contents of a file using the specified FileReader method.
|
|
@@ -242,8 +242,8 @@ export async function fetchBlob(url, allowedMimeTypes, options) {
|
|
|
242
242
|
* @param {Element} [settings.element=document.body] - The element to receive visibility classes.
|
|
243
243
|
* @param {string} [settings.hiddenClass='windowHidden'] - CSS class applied when the page is hidden.
|
|
244
244
|
* @param {string} [settings.visibleClass='windowVisible'] - CSS class applied when the page is visible.
|
|
245
|
-
* @param {() => void} [settings.onVisible] - Callback called when page becomes visible.
|
|
246
|
-
* @param {() => void} [settings.onHidden] - Callback called when page becomes hidden.
|
|
245
|
+
* @param {(data: { type: string; oldType: string; oldClass: string; }) => void} [settings.onVisible] - Callback called when page becomes visible.
|
|
246
|
+
* @param {(data: { type: string; oldType: string; oldClass: string; }) => void} [settings.onHidden] - Callback called when page becomes hidden.
|
|
247
247
|
* @returns {() => void} Function that removes all installed event listeners.
|
|
248
248
|
* @throws {TypeError} If any provided setting is invalid.
|
|
249
249
|
*/
|
|
@@ -258,6 +258,8 @@ export function installWindowHiddenScript({ element = document.body, hiddenClass
|
|
|
258
258
|
throw new TypeError(`"onVisible" must be a function if provided.`);
|
|
259
259
|
if (onHidden !== undefined && typeof onHidden !== 'function')
|
|
260
260
|
throw new TypeError(`"onHidden" must be a function if provided.`);
|
|
261
|
+
let oldType = '';
|
|
262
|
+
let oldClass = '';
|
|
261
263
|
const removeClass = () => {
|
|
262
264
|
element.classList.remove(hiddenClass);
|
|
263
265
|
element.classList.remove(visibleClass);
|
|
@@ -287,22 +289,27 @@ export function installWindowHiddenScript({ element = document.body, hiddenClass
|
|
|
287
289
|
const hiddenEvents = ['blur', 'focusout', 'pagehide'];
|
|
288
290
|
if (visibleEvents.includes(type)) {
|
|
289
291
|
element.classList.add(visibleClass);
|
|
290
|
-
onVisible?.();
|
|
292
|
+
onVisible?.({ type, oldClass, oldType });
|
|
293
|
+
oldClass = visibleClass;
|
|
291
294
|
}
|
|
292
295
|
else if (hiddenEvents.includes(type)) {
|
|
293
296
|
element.classList.add(hiddenClass);
|
|
294
|
-
onHidden?.();
|
|
297
|
+
onHidden?.({ type, oldClass, oldType });
|
|
298
|
+
oldClass = hiddenClass;
|
|
295
299
|
}
|
|
296
300
|
else {
|
|
297
301
|
if (isHidden) {
|
|
298
302
|
element.classList.add(hiddenClass);
|
|
299
|
-
onHidden?.();
|
|
303
|
+
onHidden?.({ type, oldClass, oldType });
|
|
304
|
+
oldClass = hiddenClass;
|
|
300
305
|
}
|
|
301
306
|
else {
|
|
302
307
|
element.classList.add(visibleClass);
|
|
303
|
-
onVisible?.();
|
|
308
|
+
onVisible?.({ type, oldClass, oldType });
|
|
309
|
+
oldClass = visibleClass;
|
|
304
310
|
}
|
|
305
311
|
}
|
|
312
|
+
oldType = type;
|
|
306
313
|
};
|
|
307
314
|
/** @type {() => void} */
|
|
308
315
|
let uninstall = () => { };
|
package/dist/v1/basics/index.cjs
CHANGED
|
@@ -7,6 +7,7 @@ var clock = require('./clock.cjs');
|
|
|
7
7
|
var html = require('./html.cjs');
|
|
8
8
|
var html_deprecated = require('./html_deprecated.cjs');
|
|
9
9
|
var objFilter = require('./objFilter.cjs');
|
|
10
|
+
var objChecker = require('./objChecker.cjs');
|
|
10
11
|
var fullScreen = require('./fullScreen.cjs');
|
|
11
12
|
var simpleMath = require('./simpleMath.cjs');
|
|
12
13
|
var text = require('./text.cjs');
|
|
@@ -35,11 +36,11 @@ exports.getHtmlElPadding = html_deprecated.getHtmlElPadding;
|
|
|
35
36
|
exports.isInViewport = html_deprecated.isInViewport;
|
|
36
37
|
exports.isScrolledIntoView = html_deprecated.isScrolledIntoView;
|
|
37
38
|
exports.cloneObjTypeOrder = objFilter.cloneObjTypeOrder;
|
|
38
|
-
exports.countObj = objFilter.countObj;
|
|
39
39
|
exports.extendObjType = objFilter.extendObjType;
|
|
40
|
-
exports.isJsonObject = objFilter.isJsonObject;
|
|
41
40
|
exports.objType = objFilter.objType;
|
|
42
41
|
exports.reorderObjTypeOrder = objFilter.reorderObjTypeOrder;
|
|
42
|
+
exports.countObj = objChecker.countObj;
|
|
43
|
+
exports.isJsonObject = objChecker.isJsonObject;
|
|
43
44
|
exports.documentIsFullScreen = fullScreen.documentIsFullScreen;
|
|
44
45
|
exports.exitFullScreen = fullScreen.exitFullScreen;
|
|
45
46
|
exports.isFullScreenMode = fullScreen.isFullScreenMode;
|
|
@@ -38,14 +38,14 @@ import { isFullScreenMode } from './fullScreen.mjs';
|
|
|
38
38
|
import { onFullScreenChange } from './fullScreen.mjs';
|
|
39
39
|
import { offFullScreenChange } from './fullScreen.mjs';
|
|
40
40
|
import { areHtmlElsColliding } from './html_deprecated.mjs';
|
|
41
|
-
import { isJsonObject } from './
|
|
41
|
+
import { isJsonObject } from './objChecker.mjs';
|
|
42
42
|
import arraySortPositions from '../../legacy/libs/arraySortPositions.mjs';
|
|
43
43
|
import { formatBytes } from './simpleMath.mjs';
|
|
44
44
|
import { addAiMarkerShortcut } from './text.mjs';
|
|
45
45
|
import { extendObjType } from './objFilter.mjs';
|
|
46
46
|
import { reorderObjTypeOrder } from './objFilter.mjs';
|
|
47
47
|
import { cloneObjTypeOrder } from './objFilter.mjs';
|
|
48
|
-
import { countObj } from './
|
|
48
|
+
import { countObj } from './objChecker.mjs';
|
|
49
49
|
import { objType } from './objFilter.mjs';
|
|
50
50
|
import { ruleOfThree } from './simpleMath.mjs';
|
|
51
51
|
import { getSimplePerc } from './simpleMath.mjs';
|
package/dist/v1/basics/index.mjs
CHANGED
|
@@ -4,7 +4,8 @@ import { shuffleArray } from './array.mjs';
|
|
|
4
4
|
import { formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration } from './clock.mjs';
|
|
5
5
|
import { readJsonBlob, saveJsonFile, fetchJson, installWindowHiddenScript, readFileBlob, readBase64Blob, } from './html.mjs';
|
|
6
6
|
import { areHtmlElsColliding, getHtmlElBorders, getHtmlElBordersWidth, getHtmlElMargin, getHtmlElPadding, isInViewport, isScrolledIntoView, } from './html_deprecated.mjs';
|
|
7
|
-
import {
|
|
7
|
+
import { extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType } from './objFilter.mjs';
|
|
8
|
+
import { countObj, isJsonObject } from './objChecker.mjs';
|
|
8
9
|
import { documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, } from './fullScreen.mjs';
|
|
9
10
|
import { formatBytes, genFibonacciSeq, getAge, getSimplePerc, ruleOfThree } from './simpleMath.mjs';
|
|
10
11
|
import { addAiMarkerShortcut, safeTextTrim, toTitleCase, toTitleCaseLowerFirst } from './text.mjs';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Counts the number of elements in an array or the number of properties in an object.
|
|
5
|
+
*
|
|
6
|
+
* @param {Array<*>|Record<string | number | symbol, any>} obj - The array or object to count.
|
|
7
|
+
* @returns {number} - The count of items (array elements or object keys), or `0` if the input is neither an array nor an object.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* countObj([1, 2, 3]); // 3
|
|
11
|
+
* countObj({ a: 1, b: 2 }); // 2
|
|
12
|
+
* countObj('not an object'); // 0
|
|
13
|
+
*/
|
|
14
|
+
function countObj(obj) {
|
|
15
|
+
// Is Array
|
|
16
|
+
if (Array.isArray(obj)) return obj.length;
|
|
17
|
+
// Object
|
|
18
|
+
if (isJsonObject(obj)) return Object.keys(obj).length;
|
|
19
|
+
// Nothing
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Determines whether a given value is a pure JSON object (plain object).
|
|
25
|
+
*
|
|
26
|
+
* A pure object satisfies the following:
|
|
27
|
+
* - It is not null.
|
|
28
|
+
* - Its type is "object".
|
|
29
|
+
* - Its internal [[Class]] is "[object Object]".
|
|
30
|
+
* - It is not an instance of built-in types like Array, Date, Map, Set, etc.
|
|
31
|
+
*
|
|
32
|
+
* This function is useful for strict data validation when you want to ensure
|
|
33
|
+
* a value is a clean JSON-compatible object, free of class instances or special types.
|
|
34
|
+
*
|
|
35
|
+
* @param {unknown} value - The value to test.
|
|
36
|
+
* @returns {value is Record<string | number | symbol, unknown>} Returns true if the value is a pure object.
|
|
37
|
+
*/
|
|
38
|
+
function isJsonObject(value) {
|
|
39
|
+
if (value === null || typeof value !== 'object') return false;
|
|
40
|
+
if (Array.isArray(value)) return false;
|
|
41
|
+
if (Object.prototype.toString.call(value) !== '[object Object]') return false;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
exports.countObj = countObj;
|
|
46
|
+
exports.isJsonObject = isJsonObject;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Counts the number of elements in an array or the number of properties in an object.
|
|
3
|
+
*
|
|
4
|
+
* @param {Array<*>|Record<string | number | symbol, any>} obj - The array or object to count.
|
|
5
|
+
* @returns {number} - The count of items (array elements or object keys), or `0` if the input is neither an array nor an object.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* countObj([1, 2, 3]); // 3
|
|
9
|
+
* countObj({ a: 1, b: 2 }); // 2
|
|
10
|
+
* countObj('not an object'); // 0
|
|
11
|
+
*/
|
|
12
|
+
export function countObj(obj: Array<any> | Record<string | number | symbol, any>): number;
|
|
13
|
+
/**
|
|
14
|
+
* Determines whether a given value is a pure JSON object (plain object).
|
|
15
|
+
*
|
|
16
|
+
* A pure object satisfies the following:
|
|
17
|
+
* - It is not null.
|
|
18
|
+
* - Its type is "object".
|
|
19
|
+
* - Its internal [[Class]] is "[object Object]".
|
|
20
|
+
* - It is not an instance of built-in types like Array, Date, Map, Set, etc.
|
|
21
|
+
*
|
|
22
|
+
* This function is useful for strict data validation when you want to ensure
|
|
23
|
+
* a value is a clean JSON-compatible object, free of class instances or special types.
|
|
24
|
+
*
|
|
25
|
+
* @param {unknown} value - The value to test.
|
|
26
|
+
* @returns {value is Record<string | number | symbol, unknown>} Returns true if the value is a pure object.
|
|
27
|
+
*/
|
|
28
|
+
export function isJsonObject(value: unknown): value is Record<string | number | symbol, unknown>;
|
|
29
|
+
//# sourceMappingURL=objChecker.d.mts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Counts the number of elements in an array or the number of properties in an object.
|
|
3
|
+
*
|
|
4
|
+
* @param {Array<*>|Record<string | number | symbol, any>} obj - The array or object to count.
|
|
5
|
+
* @returns {number} - The count of items (array elements or object keys), or `0` if the input is neither an array nor an object.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* countObj([1, 2, 3]); // 3
|
|
9
|
+
* countObj({ a: 1, b: 2 }); // 2
|
|
10
|
+
* countObj('not an object'); // 0
|
|
11
|
+
*/
|
|
12
|
+
export function countObj(obj) {
|
|
13
|
+
// Is Array
|
|
14
|
+
if (Array.isArray(obj))
|
|
15
|
+
return obj.length;
|
|
16
|
+
// Object
|
|
17
|
+
if (isJsonObject(obj))
|
|
18
|
+
return Object.keys(obj).length;
|
|
19
|
+
// Nothing
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Determines whether a given value is a pure JSON object (plain object).
|
|
24
|
+
*
|
|
25
|
+
* A pure object satisfies the following:
|
|
26
|
+
* - It is not null.
|
|
27
|
+
* - Its type is "object".
|
|
28
|
+
* - Its internal [[Class]] is "[object Object]".
|
|
29
|
+
* - It is not an instance of built-in types like Array, Date, Map, Set, etc.
|
|
30
|
+
*
|
|
31
|
+
* This function is useful for strict data validation when you want to ensure
|
|
32
|
+
* a value is a clean JSON-compatible object, free of class instances or special types.
|
|
33
|
+
*
|
|
34
|
+
* @param {unknown} value - The value to test.
|
|
35
|
+
* @returns {value is Record<string | number | symbol, unknown>} Returns true if the value is a pure object.
|
|
36
|
+
*/
|
|
37
|
+
export function isJsonObject(value) {
|
|
38
|
+
if (value === null || typeof value !== 'object')
|
|
39
|
+
return false;
|
|
40
|
+
if (Array.isArray(value))
|
|
41
|
+
return false;
|
|
42
|
+
if (Object.prototype.toString.call(value) !== '[object Object]')
|
|
43
|
+
return false;
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var buffer = require('buffer');
|
|
4
|
+
var objChecker = require('./objChecker.cjs');
|
|
4
5
|
|
|
5
6
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
6
7
|
|
|
@@ -194,48 +195,6 @@ function getCheckObj() {
|
|
|
194
195
|
return Object.fromEntries(Object.entries(typeValidator.items).map(([key, fn]) => [key, fn]));
|
|
195
196
|
}
|
|
196
197
|
|
|
197
|
-
/**
|
|
198
|
-
* Counts the number of elements in an array or the number of properties in an object.
|
|
199
|
-
*
|
|
200
|
-
* @param {Array<*>|Record<string|number, any>} obj - The array or object to count.
|
|
201
|
-
* @returns {number} - The count of items (array elements or object keys), or `0` if the input is neither an array nor an object.
|
|
202
|
-
*
|
|
203
|
-
* @example
|
|
204
|
-
* countObj([1, 2, 3]); // 3
|
|
205
|
-
* countObj({ a: 1, b: 2 }); // 2
|
|
206
|
-
* countObj('not an object'); // 0
|
|
207
|
-
*/
|
|
208
|
-
function countObj(obj) {
|
|
209
|
-
// Is Array
|
|
210
|
-
if (Array.isArray(obj)) return obj.length;
|
|
211
|
-
// Object
|
|
212
|
-
if (objType(obj, 'object')) return Object.keys(obj).length;
|
|
213
|
-
// Nothing
|
|
214
|
-
return 0;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Determines whether a given value is a pure JSON object (plain object).
|
|
219
|
-
*
|
|
220
|
-
* A pure object satisfies the following:
|
|
221
|
-
* - It is not null.
|
|
222
|
-
* - Its type is "object".
|
|
223
|
-
* - Its internal [[Class]] is "[object Object]".
|
|
224
|
-
* - It is not an instance of built-in types like Array, Date, Map, Set, etc.
|
|
225
|
-
*
|
|
226
|
-
* This function is useful for strict data validation when you want to ensure
|
|
227
|
-
* a value is a clean JSON-compatible object, free of class instances or special types.
|
|
228
|
-
*
|
|
229
|
-
* @param {unknown} value - The value to test.
|
|
230
|
-
* @returns {value is Record<string | number | symbol, unknown>} Returns true if the value is a pure object.
|
|
231
|
-
*/
|
|
232
|
-
function isJsonObject(value) {
|
|
233
|
-
if (value === null || typeof value !== 'object') return false;
|
|
234
|
-
if (Array.isArray(value)) return false;
|
|
235
|
-
if (Object.prototype.toString.call(value) !== '[object Object]') return false;
|
|
236
|
-
return true;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
198
|
// Insert obj types
|
|
240
199
|
|
|
241
200
|
extendObjType([
|
|
@@ -358,15 +317,15 @@ extendObjType([
|
|
|
358
317
|
[
|
|
359
318
|
'object',
|
|
360
319
|
/** @param {*} val @returns {val is Record<string | number | symbol, unknown>} */
|
|
361
|
-
(val) => isJsonObject(val),
|
|
320
|
+
(val) => objChecker.isJsonObject(val),
|
|
362
321
|
],
|
|
363
322
|
]);
|
|
364
323
|
|
|
324
|
+
exports.countObj = objChecker.countObj;
|
|
325
|
+
exports.isJsonObject = objChecker.isJsonObject;
|
|
365
326
|
exports.checkObj = checkObj;
|
|
366
327
|
exports.cloneObjTypeOrder = cloneObjTypeOrder;
|
|
367
|
-
exports.countObj = countObj;
|
|
368
328
|
exports.extendObjType = extendObjType;
|
|
369
329
|
exports.getCheckObj = getCheckObj;
|
|
370
|
-
exports.isJsonObject = isJsonObject;
|
|
371
330
|
exports.objType = objType;
|
|
372
331
|
exports.reorderObjTypeOrder = reorderObjTypeOrder;
|
|
@@ -76,36 +76,11 @@ export function checkObj(obj: any): {
|
|
|
76
76
|
export function getCheckObj(): {
|
|
77
77
|
[k: string]: any;
|
|
78
78
|
};
|
|
79
|
-
/**
|
|
80
|
-
* Counts the number of elements in an array or the number of properties in an object.
|
|
81
|
-
*
|
|
82
|
-
* @param {Array<*>|Record<string|number, any>} obj - The array or object to count.
|
|
83
|
-
* @returns {number} - The count of items (array elements or object keys), or `0` if the input is neither an array nor an object.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* countObj([1, 2, 3]); // 3
|
|
87
|
-
* countObj({ a: 1, b: 2 }); // 2
|
|
88
|
-
* countObj('not an object'); // 0
|
|
89
|
-
*/
|
|
90
|
-
export function countObj(obj: Array<any> | Record<string | number, any>): number;
|
|
91
|
-
/**
|
|
92
|
-
* Determines whether a given value is a pure JSON object (plain object).
|
|
93
|
-
*
|
|
94
|
-
* A pure object satisfies the following:
|
|
95
|
-
* - It is not null.
|
|
96
|
-
* - Its type is "object".
|
|
97
|
-
* - Its internal [[Class]] is "[object Object]".
|
|
98
|
-
* - It is not an instance of built-in types like Array, Date, Map, Set, etc.
|
|
99
|
-
*
|
|
100
|
-
* This function is useful for strict data validation when you want to ensure
|
|
101
|
-
* a value is a clean JSON-compatible object, free of class instances or special types.
|
|
102
|
-
*
|
|
103
|
-
* @param {unknown} value - The value to test.
|
|
104
|
-
* @returns {value is Record<string | number | symbol, unknown>} Returns true if the value is a pure object.
|
|
105
|
-
*/
|
|
106
|
-
export function isJsonObject(value: unknown): value is Record<string | number | symbol, unknown>;
|
|
107
79
|
export type ExtendObjType = {
|
|
108
80
|
[x: string]: (val: any) => any;
|
|
109
81
|
};
|
|
110
82
|
export type ExtendObjTypeArray = Array<[string, (val: any) => any]>;
|
|
83
|
+
import { countObj } from './objChecker.mjs';
|
|
84
|
+
import { isJsonObject } from './objChecker.mjs';
|
|
85
|
+
export { countObj, isJsonObject };
|
|
111
86
|
//# sourceMappingURL=objFilter.d.mts.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
+
import { countObj, isJsonObject } from './objChecker.mjs';
|
|
3
|
+
export { countObj, isJsonObject };
|
|
2
4
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
3
5
|
/**
|
|
4
6
|
* An object containing type validation functions and their evaluation order.
|
|
@@ -176,51 +178,6 @@ export function checkObj(obj) {
|
|
|
176
178
|
export function getCheckObj() {
|
|
177
179
|
return Object.fromEntries(Object.entries(typeValidator.items).map(([key, fn]) => [key, fn]));
|
|
178
180
|
}
|
|
179
|
-
/**
|
|
180
|
-
* Counts the number of elements in an array or the number of properties in an object.
|
|
181
|
-
*
|
|
182
|
-
* @param {Array<*>|Record<string|number, any>} obj - The array or object to count.
|
|
183
|
-
* @returns {number} - The count of items (array elements or object keys), or `0` if the input is neither an array nor an object.
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* countObj([1, 2, 3]); // 3
|
|
187
|
-
* countObj({ a: 1, b: 2 }); // 2
|
|
188
|
-
* countObj('not an object'); // 0
|
|
189
|
-
*/
|
|
190
|
-
export function countObj(obj) {
|
|
191
|
-
// Is Array
|
|
192
|
-
if (Array.isArray(obj))
|
|
193
|
-
return obj.length;
|
|
194
|
-
// Object
|
|
195
|
-
if (objType(obj, 'object'))
|
|
196
|
-
return Object.keys(obj).length;
|
|
197
|
-
// Nothing
|
|
198
|
-
return 0;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Determines whether a given value is a pure JSON object (plain object).
|
|
202
|
-
*
|
|
203
|
-
* A pure object satisfies the following:
|
|
204
|
-
* - It is not null.
|
|
205
|
-
* - Its type is "object".
|
|
206
|
-
* - Its internal [[Class]] is "[object Object]".
|
|
207
|
-
* - It is not an instance of built-in types like Array, Date, Map, Set, etc.
|
|
208
|
-
*
|
|
209
|
-
* This function is useful for strict data validation when you want to ensure
|
|
210
|
-
* a value is a clean JSON-compatible object, free of class instances or special types.
|
|
211
|
-
*
|
|
212
|
-
* @param {unknown} value - The value to test.
|
|
213
|
-
* @returns {value is Record<string | number | symbol, unknown>} Returns true if the value is a pure object.
|
|
214
|
-
*/
|
|
215
|
-
export function isJsonObject(value) {
|
|
216
|
-
if (value === null || typeof value !== 'object')
|
|
217
|
-
return false;
|
|
218
|
-
if (Array.isArray(value))
|
|
219
|
-
return false;
|
|
220
|
-
if (Object.prototype.toString.call(value) !== '[object Object]')
|
|
221
|
-
return false;
|
|
222
|
-
return true;
|
|
223
|
-
}
|
|
224
181
|
// Insert obj types
|
|
225
182
|
extendObjType([
|
|
226
183
|
[
|
package/dist/v1/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ var arraySortPositions = require('../legacy/libs/arraySortPositions.cjs');
|
|
|
6
6
|
var array = require('./basics/array.cjs');
|
|
7
7
|
var clock = require('./basics/clock.cjs');
|
|
8
8
|
var objFilter = require('./basics/objFilter.cjs');
|
|
9
|
+
var objChecker = require('./basics/objChecker.cjs');
|
|
9
10
|
var fullScreen = require('./basics/fullScreen.cjs');
|
|
10
11
|
var simpleMath = require('./basics/simpleMath.cjs');
|
|
11
12
|
var text = require('./basics/text.cjs');
|
|
@@ -29,6 +30,10 @@ var UltraRandomMsgGen = require('./libs/UltraRandomMsgGen.cjs');
|
|
|
29
30
|
var TinySmartScroller = require('./libs/TinySmartScroller.cjs');
|
|
30
31
|
var TinyTextRangeEditor = require('./libs/TinyTextRangeEditor.cjs');
|
|
31
32
|
var TinyClipboard = require('./libs/TinyClipboard.cjs');
|
|
33
|
+
var TinyColorConverter = require('./libs/TinyColorConverter.cjs');
|
|
34
|
+
var TinyTimeout = require('./libs/TinyTimeout.cjs');
|
|
35
|
+
var TinyEvents = require('./libs/TinyEvents.cjs');
|
|
36
|
+
var TinyLocalStorage = require('./libs/TinyLocalStorage.cjs');
|
|
32
37
|
|
|
33
38
|
|
|
34
39
|
|
|
@@ -42,11 +47,11 @@ exports.formatTimer = clock.formatTimer;
|
|
|
42
47
|
exports.getTimeDuration = clock.getTimeDuration;
|
|
43
48
|
exports.checkObj = objFilter.checkObj;
|
|
44
49
|
exports.cloneObjTypeOrder = objFilter.cloneObjTypeOrder;
|
|
45
|
-
exports.countObj = objFilter.countObj;
|
|
46
50
|
exports.extendObjType = objFilter.extendObjType;
|
|
47
|
-
exports.isJsonObject = objFilter.isJsonObject;
|
|
48
51
|
exports.objType = objFilter.objType;
|
|
49
52
|
exports.reorderObjTypeOrder = objFilter.reorderObjTypeOrder;
|
|
53
|
+
exports.countObj = objChecker.countObj;
|
|
54
|
+
exports.isJsonObject = objChecker.isJsonObject;
|
|
50
55
|
exports.documentIsFullScreen = fullScreen.documentIsFullScreen;
|
|
51
56
|
exports.exitFullScreen = fullScreen.exitFullScreen;
|
|
52
57
|
exports.isFullScreenMode = fullScreen.isFullScreenMode;
|
|
@@ -137,3 +142,7 @@ exports.UltraRandomMsgGen = UltraRandomMsgGen;
|
|
|
137
142
|
exports.TinySmartScroller = TinySmartScroller;
|
|
138
143
|
exports.TinyTextRangeEditor = TinyTextRangeEditor;
|
|
139
144
|
exports.TinyClipboard = TinyClipboard;
|
|
145
|
+
exports.TinyColorConverter = TinyColorConverter;
|
|
146
|
+
exports.TinyTimeout = TinyTimeout;
|
|
147
|
+
exports.TinyEvents = TinyEvents;
|
|
148
|
+
exports.TinyLocalStorage = TinyLocalStorage;
|