@creejs/commons-lang 2.1.26 → 2.1.28

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.
@@ -1537,6 +1537,45 @@ function safeToString (value) {
1537
1537
  } else if (value === undefined) {
1538
1538
  return 'undefined'
1539
1539
  }
1540
+ const type = typeof value;
1541
+ if (type === 'string') {
1542
+ return value
1543
+ } else if (type === 'symbol') {
1544
+ return `Symbol(${value.description})`
1545
+ } else if (type === 'function') {
1546
+ return `Function ${value.name}(){}`
1547
+ }
1548
+ if (value instanceof String) {
1549
+ return value.toString()
1550
+ }
1551
+ if (Number.isNaN(value)) {
1552
+ return 'NaN'
1553
+ }
1554
+ if (value === Infinity) {
1555
+ return 'Infinity'
1556
+ }
1557
+ if (value === -Infinity) {
1558
+ return '-Infinity'
1559
+ }
1560
+ if (value instanceof Error) {
1561
+ return `${value.constructor.name}: ${value.message}`
1562
+ }
1563
+ if (value instanceof Promise) {
1564
+ return 'Promise'
1565
+ }
1566
+ if (value instanceof Set) {
1567
+ return `Set: ${safeToString(Array.from(value))}`
1568
+ }
1569
+ if (value instanceof Map) {
1570
+ return `Map: ${safeToString(Array.from(value.entries()))}`
1571
+ }
1572
+ if (value instanceof RegExp) {
1573
+ return value.toString()
1574
+ }
1575
+
1576
+ if (Array.isArray(value)) {
1577
+ return `[${value.map(safeToString).join(', ')}]`
1578
+ }
1540
1579
  let valueStr;
1541
1580
  try {
1542
1581
  valueStr = JSON.stringify(value);
@@ -2046,9 +2085,10 @@ async function parallelAllSettled (tasks, maxParallel = 5) {
2046
2085
  * * One task failed, it will start next task immediately, Not Wait for the bulk(maxParallel) to complete
2047
2086
  * @param {Array<Function|Promise<any>>} tasks - Array of async functions to execute
2048
2087
  * @param {number} [maxParallel=5] - Maximum number of tasks to run in parallel
2088
+ * @param {string} [failureMessage] - Error message when all tasks failed
2049
2089
  * @returns {Promise<any>} Resolves with the result of the first successfully completed task
2050
2090
  */
2051
- async function parallelAny (tasks, maxParallel = 5) {
2091
+ async function parallelAny (tasks, maxParallel = 5, failureMessage) {
2052
2092
  assertArray(tasks, 'tasks');
2053
2093
  assertNumber(maxParallel);
2054
2094
  if (tasks.length === 0) {
@@ -2093,7 +2133,7 @@ async function parallelAny (tasks, maxParallel = 5) {
2093
2133
  // No task left, and No successful execution, reject with errors
2094
2134
  if (errors.length >= tasks.length) {
2095
2135
  if (deferred.pending) {
2096
- deferred.reject(new AggregatedError('All Tasks Failed', errors));
2136
+ deferred.reject(new AggregatedError(failureMessage ?? 'All Tasks Failed', errors));
2097
2137
  return
2098
2138
  }
2099
2139
  }