tiny-essentials 1.9.2 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import arraySortPositions from '../../legacy/libs/arraySortPositions.mjs';
2
2
  import asyncReplace from '../../legacy/libs/replaceAsync.mjs';
3
3
  import { shuffleArray } from './array.mjs';
4
4
  import { formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration } from './clock.mjs';
5
- import { countObj, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType, } from './objFilter.mjs';
5
+ import { countObj, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType, isJsonObject, } from './objFilter.mjs';
6
6
  import { formatBytes, getAge, getSimplePerc, ruleOfThree } from './simpleMath.mjs';
7
7
  import { addAiMarkerShortcut, toTitleCase, toTitleCaseLowerFirst } from './text.mjs';
8
- export { arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
8
+ export { isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
@@ -214,6 +214,28 @@ function countObj(obj) {
214
214
  return 0;
215
215
  }
216
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<unknown, 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
+
217
239
  // Insert obj types
218
240
 
219
241
  extendObjType([
@@ -297,27 +319,27 @@ extendObjType([
297
319
  ],
298
320
  [
299
321
  'map',
300
- /** @param {*} val @returns {val is Map<any, any>} */
322
+ /** @param {*} val @returns {val is Map<unknown, unknown>} */
301
323
  (val) => val instanceof Map,
302
324
  ],
303
325
  [
304
326
  'set',
305
- /** @param {*} val @returns {val is Set<any>} */
327
+ /** @param {*} val @returns {val is Set<unknown>} */
306
328
  (val) => val instanceof Set,
307
329
  ],
308
330
  [
309
331
  'weakmap',
310
- /** @param {*} val @returns {val is WeakMap<any, any>} */
332
+ /** @param {*} val @returns {val is WeakMap<unknown, unknown>} */
311
333
  (val) => val instanceof WeakMap,
312
334
  ],
313
335
  [
314
336
  'weakset',
315
- /** @param {*} val @returns {val is WeakSet<any>} */
337
+ /** @param {*} val @returns {val is WeakSet<unknown>} */
316
338
  (val) => val instanceof WeakSet,
317
339
  ],
318
340
  [
319
341
  'promise',
320
- /** @param {*} val @returns {val is Promise<any>} */
342
+ /** @param {*} val @returns {val is Promise<unknown>} */
321
343
  (val) => val instanceof Promise,
322
344
  ],
323
345
  ]);
@@ -335,8 +357,8 @@ if (isBrowser) {
335
357
  extendObjType([
336
358
  [
337
359
  'object',
338
- /** @param {*} val @returns {val is object} */
339
- (val) => typeof val === 'object' && val !== null && !Array.isArray(val),
360
+ /** @param {*} val @returns {val is Record<unknown, unknown>} */
361
+ (val) => isJsonObject(val),
340
362
  ],
341
363
  ]);
342
364
 
@@ -345,5 +367,6 @@ exports.cloneObjTypeOrder = cloneObjTypeOrder;
345
367
  exports.countObj = countObj;
346
368
  exports.extendObjType = extendObjType;
347
369
  exports.getCheckObj = getCheckObj;
370
+ exports.isJsonObject = isJsonObject;
348
371
  exports.objType = objType;
349
372
  exports.reorderObjTypeOrder = reorderObjTypeOrder;
@@ -88,6 +88,22 @@ export function getCheckObj(): {
88
88
  * countObj('not an object'); // 0
89
89
  */
90
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<unknown, unknown>} Returns true if the value is a pure object.
105
+ */
106
+ export function isJsonObject(value: unknown): value is Record<unknown, unknown>;
91
107
  export type ExtendObjType = {
92
108
  [x: string]: (val: any) => any;
93
109
  };
@@ -197,6 +197,30 @@ export function countObj(obj) {
197
197
  // Nothing
198
198
  return 0;
199
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<unknown, 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
+ }
200
224
  // Insert obj types
201
225
  extendObjType([
202
226
  [
@@ -276,27 +300,27 @@ extendObjType([
276
300
  ],
277
301
  [
278
302
  'map',
279
- /** @param {*} val @returns {val is Map<any, any>} */
303
+ /** @param {*} val @returns {val is Map<unknown, unknown>} */
280
304
  (val) => val instanceof Map,
281
305
  ],
282
306
  [
283
307
  'set',
284
- /** @param {*} val @returns {val is Set<any>} */
308
+ /** @param {*} val @returns {val is Set<unknown>} */
285
309
  (val) => val instanceof Set,
286
310
  ],
287
311
  [
288
312
  'weakmap',
289
- /** @param {*} val @returns {val is WeakMap<any, any>} */
313
+ /** @param {*} val @returns {val is WeakMap<unknown, unknown>} */
290
314
  (val) => val instanceof WeakMap,
291
315
  ],
292
316
  [
293
317
  'weakset',
294
- /** @param {*} val @returns {val is WeakSet<any>} */
318
+ /** @param {*} val @returns {val is WeakSet<unknown>} */
295
319
  (val) => val instanceof WeakSet,
296
320
  ],
297
321
  [
298
322
  'promise',
299
- /** @param {*} val @returns {val is Promise<any>} */
323
+ /** @param {*} val @returns {val is Promise<unknown>} */
300
324
  (val) => val instanceof Promise,
301
325
  ],
302
326
  ]);
@@ -312,7 +336,7 @@ if (isBrowser) {
312
336
  extendObjType([
313
337
  [
314
338
  'object',
315
- /** @param {*} val @returns {val is object} */
316
- (val) => typeof val === 'object' && val !== null && !Array.isArray(val),
339
+ /** @param {*} val @returns {val is Record<unknown, unknown>} */
340
+ (val) => isJsonObject(val),
317
341
  ],
318
342
  ]);
package/dist/v1/index.cjs CHANGED
@@ -26,6 +26,7 @@ exports.checkObj = objFilter.checkObj;
26
26
  exports.cloneObjTypeOrder = objFilter.cloneObjTypeOrder;
27
27
  exports.countObj = objFilter.countObj;
28
28
  exports.extendObjType = objFilter.extendObjType;
29
+ exports.isJsonObject = objFilter.isJsonObject;
29
30
  exports.objType = objFilter.objType;
30
31
  exports.reorderObjTypeOrder = objFilter.reorderObjTypeOrder;
31
32
  exports.formatBytes = simpleMath.formatBytes;
@@ -2,6 +2,7 @@ import TinyRateLimiter from './libs/TinyRateLimiter.mjs';
2
2
  import ColorSafeStringify from './libs/ColorSafeStringify.mjs';
3
3
  import TinyPromiseQueue from './libs/TinyPromiseQueue.mjs';
4
4
  import TinyLevelUp from '../legacy/libs/userLevel.mjs';
5
+ import { isJsonObject } from './basics/objFilter.mjs';
5
6
  import arraySortPositions from '../legacy/libs/arraySortPositions.mjs';
6
7
  import { formatBytes } from './basics/simpleMath.mjs';
7
8
  import { addAiMarkerShortcut } from './basics/text.mjs';
@@ -22,5 +23,5 @@ import { getTimeDuration } from './basics/clock.mjs';
22
23
  import { shuffleArray } from './basics/array.mjs';
23
24
  import { toTitleCase } from './basics/text.mjs';
24
25
  import { toTitleCaseLowerFirst } from './basics/text.mjs';
25
- export { TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
26
+ export { TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
26
27
  //# sourceMappingURL=index.d.mts.map
package/dist/v1/index.mjs CHANGED
@@ -3,10 +3,10 @@ import TinyLevelUp from '../legacy/libs/userLevel.mjs';
3
3
  import arraySortPositions from '../legacy/libs/arraySortPositions.mjs';
4
4
  import { shuffleArray } from './basics/array.mjs';
5
5
  import { formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, } from './basics/clock.mjs';
6
- import { countObj, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType, checkObj, } from './basics/objFilter.mjs';
6
+ import { countObj, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, objType, checkObj, isJsonObject, } from './basics/objFilter.mjs';
7
7
  import { formatBytes, getAge, getSimplePerc, ruleOfThree } from './basics/simpleMath.mjs';
8
8
  import { addAiMarkerShortcut, toTitleCase, toTitleCaseLowerFirst } from './basics/text.mjs';
9
9
  import ColorSafeStringify from './libs/ColorSafeStringify.mjs';
10
10
  import TinyPromiseQueue from './libs/TinyPromiseQueue.mjs';
11
11
  import TinyRateLimiter from './libs/TinyRateLimiter.mjs';
12
- export { TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
12
+ export { TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };