@lowentry/utils 1.24.1 → 1.25.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.
- package/index.d.ts +4 -0
- package/index.js +80 -19
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/LeTypes.js +67 -0
- package/src/LeUtils.js +13 -6
- package/src/index.js +1 -1
package/package.json
CHANGED
package/src/LeTypes.js
CHANGED
|
@@ -71,6 +71,73 @@ export const STRING_ANY = (...values) =>
|
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Ensures the given value is a boolean.
|
|
76
|
+
*
|
|
77
|
+
* This will work differently than !!value, as it will try to figure out the most logical boolean value from the given value.
|
|
78
|
+
*
|
|
79
|
+
* @param {*} value
|
|
80
|
+
* @returns {boolean}
|
|
81
|
+
*/
|
|
82
|
+
export const BOOL = (value) =>
|
|
83
|
+
{
|
|
84
|
+
return BOOL_ANY(value);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Returns the first non-null non-undefined boolean-castable value as a boolean.
|
|
89
|
+
*
|
|
90
|
+
* @param {*} values
|
|
91
|
+
* @returns {boolean}
|
|
92
|
+
*/
|
|
93
|
+
export const BOOL_ANY = (...values) =>
|
|
94
|
+
{
|
|
95
|
+
for(let value of values)
|
|
96
|
+
{
|
|
97
|
+
if(!ISSET(value))
|
|
98
|
+
{
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if(typeof value === 'boolean')
|
|
102
|
+
{
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
if(typeof value === 'number')
|
|
106
|
+
{
|
|
107
|
+
if(!isNaN(value))
|
|
108
|
+
{
|
|
109
|
+
return (value !== 0);
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if(typeof value === 'string')
|
|
114
|
+
{
|
|
115
|
+
value = value.toLowerCase().trim();
|
|
116
|
+
if((value === '') || (value === 'false') || (value === 'no') || (value === 'off') || (value === '0'))
|
|
117
|
+
{
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if((value === 'true') || (value === 'yes') || (value === 'on') || (value === '1'))
|
|
121
|
+
{
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
const float = +value;
|
|
125
|
+
if(!isNaN(float))
|
|
126
|
+
{
|
|
127
|
+
return (float !== 0);
|
|
128
|
+
}
|
|
129
|
+
// unrecognized string, let's try the next value, else we return false (after the loop)
|
|
130
|
+
}
|
|
131
|
+
if(IS_ARRAY(value) || IS_OBJECT(value))
|
|
132
|
+
{
|
|
133
|
+
return !!value;
|
|
134
|
+
}
|
|
135
|
+
// unrecognized type, let's try the next value, else we return false (after the loop)
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
|
|
74
141
|
/**
|
|
75
142
|
* Ensures the given value is an integer (attempts to cast it to an integer if it's not, null and undefined will return 0).
|
|
76
143
|
*
|
package/src/LeUtils.js
CHANGED
|
@@ -1708,27 +1708,34 @@ export const LeUtils = {
|
|
|
1708
1708
|
|
|
1709
1709
|
let run = true;
|
|
1710
1710
|
let requestAnimationFrameId = null;
|
|
1711
|
-
let
|
|
1711
|
+
let lastTimestamp = 0;
|
|
1712
|
+
let totalTime = 0;
|
|
1712
1713
|
let frames = intervalFrames;
|
|
1713
|
-
const tick = () =>
|
|
1714
|
+
const tick = (timestamp) =>
|
|
1714
1715
|
{
|
|
1715
1716
|
if(run)
|
|
1716
1717
|
{
|
|
1718
|
+
if(lastTimestamp === 0)
|
|
1719
|
+
{
|
|
1720
|
+
lastTimestamp = timestamp;
|
|
1721
|
+
}
|
|
1722
|
+
totalTime += (timestamp - lastTimestamp);
|
|
1723
|
+
lastTimestamp = timestamp;
|
|
1724
|
+
|
|
1725
|
+
frames--;
|
|
1717
1726
|
if(frames <= 0)
|
|
1718
1727
|
{
|
|
1719
|
-
let currentTime = globalThis?.performance?.now?.() ?? 0;
|
|
1720
1728
|
try
|
|
1721
1729
|
{
|
|
1722
|
-
callback(
|
|
1730
|
+
callback(totalTime / 1000);
|
|
1723
1731
|
}
|
|
1724
1732
|
catch(e)
|
|
1725
1733
|
{
|
|
1726
1734
|
console.error(e);
|
|
1727
1735
|
}
|
|
1728
|
-
|
|
1736
|
+
totalTime = 0;
|
|
1729
1737
|
frames = intervalFrames;
|
|
1730
1738
|
}
|
|
1731
|
-
frames--;
|
|
1732
1739
|
|
|
1733
1740
|
if(run)
|
|
1734
1741
|
{
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export {LeUtils} from './LeUtils.js';
|
|
2
|
-
export {ISSET, IS_ARRAY, ARRAY, IS_OBJECT, OBJECT, STRING, STRING_ANY, INT, INT_ANY, FLOAT, FLOAT_ANY, INT_LAX, INT_LAX_ANY, FLOAT_LAX, FLOAT_LAX_ANY} from './LeTypes.js';
|
|
2
|
+
export {ISSET, IS_ARRAY, ARRAY, IS_OBJECT, OBJECT, STRING, STRING_ANY, BOOL, BOOL_ANY, INT, INT_ANY, FLOAT, FLOAT_ANY, INT_LAX, INT_LAX_ANY, FLOAT_LAX, FLOAT_LAX_ANY} from './LeTypes.js';
|
|
3
3
|
export {EventEmitter} from './classes/EventEmitter.js';
|
|
4
4
|
export {LinkedList} from './classes/LinkedList.js';
|
|
5
5
|
export {SerializableMap} from './classes/SerializableMap.js';
|