@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.
@@ -1543,6 +1543,45 @@
1543
1543
  } else if (value === undefined) {
1544
1544
  return 'undefined'
1545
1545
  }
1546
+ const type = typeof value;
1547
+ if (type === 'string') {
1548
+ return value
1549
+ } else if (type === 'symbol') {
1550
+ return `Symbol(${value.description})`
1551
+ } else if (type === 'function') {
1552
+ return `Function ${value.name}(){}`
1553
+ }
1554
+ if (value instanceof String) {
1555
+ return value.toString()
1556
+ }
1557
+ if (Number.isNaN(value)) {
1558
+ return 'NaN'
1559
+ }
1560
+ if (value === Infinity) {
1561
+ return 'Infinity'
1562
+ }
1563
+ if (value === -Infinity) {
1564
+ return '-Infinity'
1565
+ }
1566
+ if (value instanceof Error) {
1567
+ return `${value.constructor.name}: ${value.message}`
1568
+ }
1569
+ if (value instanceof Promise) {
1570
+ return 'Promise'
1571
+ }
1572
+ if (value instanceof Set) {
1573
+ return `Set: ${safeToString(Array.from(value))}`
1574
+ }
1575
+ if (value instanceof Map) {
1576
+ return `Map: ${safeToString(Array.from(value.entries()))}`
1577
+ }
1578
+ if (value instanceof RegExp) {
1579
+ return value.toString()
1580
+ }
1581
+
1582
+ if (Array.isArray(value)) {
1583
+ return `[${value.map(safeToString).join(', ')}]`
1584
+ }
1546
1585
  let valueStr;
1547
1586
  try {
1548
1587
  valueStr = JSON.stringify(value);
@@ -2052,9 +2091,10 @@
2052
2091
  * * One task failed, it will start next task immediately, Not Wait for the bulk(maxParallel) to complete
2053
2092
  * @param {Array<Function|Promise<any>>} tasks - Array of async functions to execute
2054
2093
  * @param {number} [maxParallel=5] - Maximum number of tasks to run in parallel
2094
+ * @param {string} [failureMessage] - Error message when all tasks failed
2055
2095
  * @returns {Promise<any>} Resolves with the result of the first successfully completed task
2056
2096
  */
2057
- async function parallelAny (tasks, maxParallel = 5) {
2097
+ async function parallelAny (tasks, maxParallel = 5, failureMessage) {
2058
2098
  assertArray(tasks, 'tasks');
2059
2099
  assertNumber(maxParallel);
2060
2100
  if (tasks.length === 0) {
@@ -2099,7 +2139,7 @@
2099
2139
  // No task left, and No successful execution, reject with errors
2100
2140
  if (errors.length >= tasks.length) {
2101
2141
  if (deferred.pending) {
2102
- deferred.reject(new AggregatedError('All Tasks Failed', errors));
2142
+ deferred.reject(new AggregatedError(failureMessage ?? 'All Tasks Failed', errors));
2103
2143
  return
2104
2144
  }
2105
2145
  }