@lowentry/utils 1.22.2 → 1.23.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowentry/utils",
3
- "version": "1.22.2",
3
+ "version": "1.23.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/src/LeUtils.js CHANGED
@@ -586,43 +586,42 @@ export const LeUtils = {
586
586
  {
587
587
  return index;
588
588
  }
589
- if(ArrayBuffer.isView(elements) && !(elements instanceof DataView))
589
+ if(typeof elements !== 'string')
590
590
  {
591
- return elements[index];
592
- }
593
- if(typeof elements === 'string')
594
- {
595
- return elements.charAt(index);
596
- }
597
- if(typeof elements?.[Symbol.iterator] === 'function')
598
- {
599
- let i = 0;
600
- for(const value of elements)
591
+ if(ArrayBuffer.isView(elements) && !(elements instanceof DataView))
601
592
  {
602
- if(i === index)
603
- {
604
- return value;
605
- }
606
- i++;
593
+ return elements[index];
607
594
  }
608
- return undefined;
609
- }
610
- if(typeof elements?.forEach === 'function')
611
- {
612
- let result = undefined;
613
- let shouldContinue = true;
614
- elements.forEach((value, i) =>
595
+ if(typeof elements?.[Symbol.iterator] === 'function')
615
596
  {
616
- if(shouldContinue)
597
+ let i = 0;
598
+ for(const value of elements)
617
599
  {
618
600
  if(i === index)
619
601
  {
620
- result = value;
621
- shouldContinue = false;
602
+ return value;
622
603
  }
604
+ i++;
623
605
  }
624
- });
625
- return result;
606
+ return undefined;
607
+ }
608
+ if(typeof elements?.forEach === 'function')
609
+ {
610
+ let result = undefined;
611
+ let shouldContinue = true;
612
+ elements.forEach((value, i) =>
613
+ {
614
+ if(shouldContinue)
615
+ {
616
+ if(i === index)
617
+ {
618
+ result = value;
619
+ shouldContinue = false;
620
+ }
621
+ }
622
+ });
623
+ return result;
624
+ }
626
625
  }
627
626
  if((typeof elements === 'object') || (typeof elements === 'function'))
628
627
  {
@@ -644,14 +643,13 @@ export const LeUtils = {
644
643
  supportsEach:
645
644
  (elements) =>
646
645
  {
647
- if((elements === null) || (typeof elements === 'undefined'))
646
+ if((elements === null) || (typeof elements === 'undefined') || (typeof elements === 'string'))
648
647
  {
649
648
  return false;
650
649
  }
651
650
  return !!(
652
651
  (Array.isArray(elements))
653
652
  || ((typeof elements === 'object') && (elements?.constructor === Object))
654
- || (typeof elements === 'string')
655
653
  || (typeof elements?.[Symbol.iterator] === 'function')
656
654
  || (typeof elements?.forEach === 'function')
657
655
  || ((typeof elements === 'object') || (typeof elements === 'function'))
@@ -707,36 +705,31 @@ export const LeUtils = {
707
705
  }
708
706
  return;
709
707
  }
710
- if(typeof elements === 'string')
708
+ if(typeof elements !== 'string')
711
709
  {
712
- for(let i = 0; i < elements.length; i++)
710
+ if(typeof elements?.[Symbol.iterator] === 'function')
713
711
  {
714
- yield [elements.charAt(i), i];
712
+ let i = 0;
713
+ for(const value of elements)
714
+ {
715
+ yield [value, i];
716
+ i++;
717
+ }
718
+ return;
715
719
  }
716
- return;
717
- }
718
- if(typeof elements?.[Symbol.iterator] === 'function')
719
- {
720
- let i = 0;
721
- for(const value of elements)
720
+ if(typeof elements?.forEach === 'function')
722
721
  {
723
- yield [value, i];
724
- i++;
725
- }
726
- return;
727
- }
728
- if(typeof elements?.forEach === 'function')
729
- {
730
- const buffer = [];
731
- elements.forEach((value, i) =>
732
- {
733
- buffer.push([value, i]);
734
- });
735
- for(const entry of buffer)
736
- {
737
- yield entry;
722
+ const buffer = [];
723
+ elements.forEach((value, i) =>
724
+ {
725
+ buffer.push([value, i]);
726
+ });
727
+ for(const entry of buffer)
728
+ {
729
+ yield entry;
730
+ }
731
+ return;
738
732
  }
739
- return;
740
733
  }
741
734
  if((typeof elements === 'object') || (typeof elements === 'function'))
742
735
  {
@@ -898,7 +891,7 @@ export const LeUtils = {
898
891
  collection.set(index, value);
899
892
  };
900
893
  }
901
- else if((typeof elements === 'string') || (typeof elements?.[Symbol.iterator] === 'function') || (typeof elements?.forEach === 'function'))
894
+ else if((typeof elements !== 'string') && ((typeof elements?.[Symbol.iterator] === 'function') || (typeof elements?.forEach === 'function')))
902
895
  {
903
896
  collection = [];
904
897
  add = (value, index) =>
@@ -1119,7 +1112,7 @@ export const LeUtils = {
1119
1112
  {
1120
1113
  const flattenToArrayRecursive = (result, elements, optionalSkipHasOwnPropertyCheck) =>
1121
1114
  {
1122
- if(!LeUtils.supportsEach(elements) || (typeof elements === 'string'))
1115
+ if(!LeUtils.supportsEach(elements))
1123
1116
  {
1124
1117
  result.push(elements);
1125
1118
  return;
@@ -1132,7 +1125,7 @@ export const LeUtils = {
1132
1125
 
1133
1126
  return (elements, optionalSkipHasOwnPropertyCheck = false) =>
1134
1127
  {
1135
- if(!LeUtils.supportsEach(elements) || (typeof elements === 'string'))
1128
+ if(!LeUtils.supportsEach(elements))
1136
1129
  {
1137
1130
  return [elements];
1138
1131
  }
@@ -1360,11 +1353,11 @@ export const LeUtils = {
1360
1353
 
1361
1354
  ms = FLOAT_LAX(ms);
1362
1355
 
1363
- let lastTime = performance?.now?.() ?? 0;
1356
+ let lastTime = globalThis?.performance?.now?.() ?? 0;
1364
1357
  /** @type {number|null} */
1365
1358
  let handler = globalThis.setTimeout(() =>
1366
1359
  {
1367
- const currentTime = performance?.now?.() ?? 0;
1360
+ const currentTime = globalThis?.performance?.now?.() ?? 0;
1368
1361
  try
1369
1362
  {
1370
1363
  callback((currentTime - lastTime) / 1000);
@@ -1426,11 +1419,11 @@ export const LeUtils = {
1426
1419
  };
1427
1420
  }
1428
1421
 
1429
- let lastTime = performance?.now?.() ?? 0;
1422
+ let lastTime = globalThis?.performance?.now?.() ?? 0;
1430
1423
  /** @type {number|null} */
1431
1424
  let handler = globalThis.setInterval(() =>
1432
1425
  {
1433
- const currentTime = performance?.now?.() ?? 0;
1426
+ const currentTime = globalThis?.performance?.now?.() ?? 0;
1434
1427
  try
1435
1428
  {
1436
1429
  callback((currentTime - lastTime) / 1000);
@@ -1481,7 +1474,7 @@ export const LeUtils = {
1481
1474
 
1482
1475
  let run = true;
1483
1476
  let requestAnimationFrameId = null;
1484
- let lastTime = performance?.now?.() ?? 0;
1477
+ let lastTime = globalThis?.performance?.now?.() ?? 0;
1485
1478
  const tick = () =>
1486
1479
  {
1487
1480
  if(run)
@@ -1490,7 +1483,7 @@ export const LeUtils = {
1490
1483
  {
1491
1484
  run = false;
1492
1485
  requestAnimationFrameId = null;
1493
- const currentTime = performance?.now?.() ?? 0;
1486
+ const currentTime = globalThis?.performance?.now?.() ?? 0;
1494
1487
  try
1495
1488
  {
1496
1489
  callback((currentTime - lastTime) / 1000);
@@ -1561,7 +1554,7 @@ export const LeUtils = {
1561
1554
 
1562
1555
  let run = true;
1563
1556
  let requestAnimationFrameId = null;
1564
- let lastTime = performance?.now?.() ?? 0;
1557
+ let lastTime = globalThis?.performance?.now?.() ?? 0;
1565
1558
  let frames = intervalFrames;
1566
1559
  const tick = () =>
1567
1560
  {
@@ -1569,7 +1562,7 @@ export const LeUtils = {
1569
1562
  {
1570
1563
  if(frames <= 0)
1571
1564
  {
1572
- let currentTime = performance?.now?.() ?? 0;
1565
+ let currentTime = globalThis?.performance?.now?.() ?? 0;
1573
1566
  try
1574
1567
  {
1575
1568
  callback((currentTime - lastTime) / 1000);
@@ -2055,7 +2048,7 @@ export const LeUtils = {
2055
2048
  generateNamePermutations:
2056
2049
  (...names) =>
2057
2050
  {
2058
- names = LeUtils.flattenArray(names)
2051
+ names = LeUtils.flattenToArray(names)
2059
2052
  .map(name => STRING(name).trim().toLowerCase())
2060
2053
  .filter(name => (name.length > 0));
2061
2054
  let results = [];
@@ -2151,7 +2144,7 @@ export const LeUtils = {
2151
2144
  try
2152
2145
  {
2153
2146
  // noinspection JSDeprecatedSymbols
2154
- now = (performance?.timeOrigin || performance?.timing?.navigationStart || 0) + (performance?.now?.() ?? 0);
2147
+ now = (globalThis?.performance?.timeOrigin || globalThis?.performance?.timing?.navigationStart || 0) + (globalThis?.performance?.now?.() ?? 0);
2155
2148
  }
2156
2149
  catch(e)
2157
2150
  {