@creejs/commons-lang 2.1.24 → 2.1.26
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/dist/cjs/index-dev.cjs +47 -20
- package/dist/cjs/index-dev.cjs.map +1 -1
- package/dist/cjs/index-min.cjs +1 -1
- package/dist/cjs/index-min.cjs.map +1 -1
- package/dist/esm/index-dev.js +47 -20
- package/dist/esm/index-dev.js.map +1 -1
- package/dist/esm/index-min.js +1 -1
- package/dist/esm/index-min.js.map +1 -1
- package/dist/umd/index.dev.js +47 -20
- package/dist/umd/index.dev.js.map +1 -1
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +1 -1
- package/types/lang-utils.d.ts +9 -9
- package/types/promise-utils.d.ts +3 -0
- package/types/string-utils.d.ts +5 -2
- package/types/time-utils.d.ts +11 -2
package/dist/umd/index.dev.js
CHANGED
|
@@ -164,14 +164,14 @@
|
|
|
164
164
|
|
|
165
165
|
/**
|
|
166
166
|
* Assigns default values from source objects to target object for undefined properties.
|
|
167
|
-
*
|
|
168
|
-
* @param {
|
|
169
|
-
* @
|
|
170
|
-
* @
|
|
167
|
+
* 1. No Deep-Copy, only first level properties are assigned.
|
|
168
|
+
* @param {{[key:string]:any}} target - The target object to assign defaults to
|
|
169
|
+
* @param {...{[key:string]:any}|undefined} sources - Source objects containing default values
|
|
170
|
+
* @returns {{[key:string]:any}} The modified target object with defaults applied
|
|
171
171
|
*/
|
|
172
172
|
function defaults (target, ...sources) {
|
|
173
173
|
if (target == null) {
|
|
174
|
-
throw new TypeError('"target"
|
|
174
|
+
throw new TypeError('"target" Should Not Nil')
|
|
175
175
|
}
|
|
176
176
|
for (const source of sources) {
|
|
177
177
|
if (source == null) {
|
|
@@ -1151,11 +1151,13 @@
|
|
|
1151
1151
|
/**
|
|
1152
1152
|
* Asserts that the given string is not empty.
|
|
1153
1153
|
* @param {string} str - The string to check.
|
|
1154
|
+
* @param {string} [paramName]
|
|
1155
|
+
*
|
|
1154
1156
|
* @throws {Error} Throws an error if the string is empty.
|
|
1155
1157
|
*/
|
|
1156
|
-
function assertNotEmpty (str) {
|
|
1158
|
+
function assertNotEmpty (str, paramName) {
|
|
1157
1159
|
if (isEmpty(str)) {
|
|
1158
|
-
throw new Error(
|
|
1160
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ''}IsEmpty String: ${str}`)
|
|
1159
1161
|
}
|
|
1160
1162
|
}
|
|
1161
1163
|
|
|
@@ -1176,11 +1178,12 @@
|
|
|
1176
1178
|
/**
|
|
1177
1179
|
* Asserts that the given string is not blank.
|
|
1178
1180
|
* @param {string} str - The string to check.
|
|
1181
|
+
* @param {string} [paramName]
|
|
1179
1182
|
* @throws {Error} Throws an error if the string is blank.
|
|
1180
1183
|
*/
|
|
1181
|
-
function assertNotBlank (str) {
|
|
1184
|
+
function assertNotBlank (str, paramName) {
|
|
1182
1185
|
if (isBlank(str)) {
|
|
1183
|
-
throw new Error(
|
|
1186
|
+
throw new Error(`${paramName ? '"' + paramName + '" ' : ''}Is Blank: ${str}`)
|
|
1184
1187
|
}
|
|
1185
1188
|
}
|
|
1186
1189
|
|
|
@@ -2044,6 +2047,9 @@
|
|
|
2044
2047
|
* 2. Maybe multiple tasks are executed as a bulk block, and all of them resolved.
|
|
2045
2048
|
* * only the first fulfilled value is returned
|
|
2046
2049
|
* * other results are dropped
|
|
2050
|
+
* 3. Notice:
|
|
2051
|
+
* * In Beginning, we start bulk(maxParallel) of tasks
|
|
2052
|
+
* * One task failed, it will start next task immediately, Not Wait for the bulk(maxParallel) to complete
|
|
2047
2053
|
* @param {Array<Function|Promise<any>>} tasks - Array of async functions to execute
|
|
2048
2054
|
* @param {number} [maxParallel=5] - Maximum number of tasks to run in parallel
|
|
2049
2055
|
* @returns {Promise<any>} Resolves with the result of the first successfully completed task
|
|
@@ -2081,12 +2087,13 @@
|
|
|
2081
2087
|
// @ts-ignore
|
|
2082
2088
|
taskPromise = returnValuePromised(task);
|
|
2083
2089
|
} else {
|
|
2084
|
-
|
|
2085
|
-
takeTaskAndRun();
|
|
2086
|
-
return
|
|
2090
|
+
taskPromise = Promise.reject(new TypeError(`Invalid task: ${typeof task}, Only Promise or Function allowed`));
|
|
2087
2091
|
}
|
|
2092
|
+
|
|
2088
2093
|
taskPromise.then(/** @type {any} */ rtnVal => {
|
|
2089
|
-
|
|
2094
|
+
runningTasksCount--; // DO Not put in finally
|
|
2095
|
+
// any task resolved, whole parallelAny resolved
|
|
2096
|
+
deferred.resolve(rtnVal); // This may be called many times: In worst case, "maxParallel" times
|
|
2090
2097
|
}).catch(e => {
|
|
2091
2098
|
errors.push(e);
|
|
2092
2099
|
// No task left, and No successful execution, reject with errors
|
|
@@ -2096,13 +2103,13 @@
|
|
|
2096
2103
|
return
|
|
2097
2104
|
}
|
|
2098
2105
|
}
|
|
2099
|
-
takeTaskAndRun()
|
|
2100
|
-
|
|
2101
|
-
runningTasksCount--;
|
|
2106
|
+
runningTasksCount--; // DO Not put in finally, must reduce before takeTaskAndRun()
|
|
2107
|
+
takeTaskAndRun(); // start next task
|
|
2102
2108
|
});
|
|
2103
2109
|
}
|
|
2104
|
-
// start tasks until maxParallel
|
|
2105
|
-
|
|
2110
|
+
// start tasks until maxParallel or no more task
|
|
2111
|
+
const parallelCount = Math.min(tasks.length, maxParallel);
|
|
2112
|
+
for (let i = 0; i < parallelCount; i++) {
|
|
2106
2113
|
takeTaskAndRun();
|
|
2107
2114
|
}
|
|
2108
2115
|
return deferred.promise
|
|
@@ -2530,6 +2537,7 @@
|
|
|
2530
2537
|
var TimeUtils = {
|
|
2531
2538
|
s2ns,
|
|
2532
2539
|
ms2ns,
|
|
2540
|
+
timestamp,
|
|
2533
2541
|
timestamp64,
|
|
2534
2542
|
lapseNano,
|
|
2535
2543
|
lapseMillis,
|
|
@@ -2538,8 +2546,9 @@
|
|
|
2538
2546
|
};
|
|
2539
2547
|
|
|
2540
2548
|
/**
|
|
2541
|
-
* Gets the current timestamp in nanoseconds
|
|
2542
|
-
*
|
|
2549
|
+
* Gets the current timestamp in nanoseconds
|
|
2550
|
+
* * If "performance" API is available, uses performance timeOrigin + now()
|
|
2551
|
+
* * Else fall back to `Date.now()` to get milliseconds and convert to nanoseconds
|
|
2543
2552
|
* @returns {bigint} Current timestamp as a BigInt
|
|
2544
2553
|
*/
|
|
2545
2554
|
function timestamp64 () {
|
|
@@ -2554,6 +2563,24 @@
|
|
|
2554
2563
|
return BigInt(Date.now() * ms2ns)
|
|
2555
2564
|
}
|
|
2556
2565
|
|
|
2566
|
+
/**
|
|
2567
|
+
* Gets the current timestamp in milliseconds
|
|
2568
|
+
* * If "performance" API is available, uses performance timeOrigin + now(), then convert to milliseconds
|
|
2569
|
+
* * Else fall back to `Date.now()`
|
|
2570
|
+
* @returns {number} Current timestamp in milliseconds
|
|
2571
|
+
*/
|
|
2572
|
+
function timestamp () {
|
|
2573
|
+
// sinon can not fake performance.timeOrigin, so we have to check it
|
|
2574
|
+
if (typeof performance !== 'undefined' && typeof performance.timeOrigin === 'number') {
|
|
2575
|
+
// timeOrigin specifies the high resolution millisecond timestamp, eg. 1756350801931.159
|
|
2576
|
+
const base = performance.timeOrigin;
|
|
2577
|
+
// the current high resolution millisecond timestamp, eg.31767926.416357
|
|
2578
|
+
const now = performance.now();
|
|
2579
|
+
return Math.ceil((base + now) / ms2ns)
|
|
2580
|
+
}
|
|
2581
|
+
return Date.now()
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2557
2584
|
/**
|
|
2558
2585
|
* Calculates the time elapsed in nanoseconds between the given timestamp and now.
|
|
2559
2586
|
* @param {bigint} start - start timestamp64, in nanoseconds.
|