@creejs/commons-lang 2.1.27 → 2.1.29
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 +60 -2
- 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 +60 -2
- 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 +60 -2
- 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/_error.d.ts +13 -0
- package/types/array-buffer-utils.d.ts +3 -3
- package/types/promise-utils.d.ts +3 -0
package/dist/cjs/index-dev.cjs
CHANGED
|
@@ -36,6 +36,22 @@ class _Error extends Error {
|
|
|
36
36
|
return err._type === '_' && typeof err.code === 'number'
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* "412 Precondition Failed" indicates that one or more conditions
|
|
41
|
+
* given in the request header fields evaluated to false when tested on the server.
|
|
42
|
+
* * Header Purpose
|
|
43
|
+
* * If-Match Only proceed if the resource's ETag matches the given value
|
|
44
|
+
* * If-None-Match Only proceed if the resource's ETag doesn't match the given value
|
|
45
|
+
* * If-Modified-Since Only proceed if the resource was modified after the given date
|
|
46
|
+
* * If-Unmodified-Since Only proceed if the resource wasn't modified after the given date
|
|
47
|
+
|
|
48
|
+
* @param {string} message
|
|
49
|
+
* @returns {_Error}
|
|
50
|
+
*/
|
|
51
|
+
static PreconditionFailed (message) {
|
|
52
|
+
return new _Error(`Not Found: ${message}`, 412)
|
|
53
|
+
}
|
|
54
|
+
|
|
39
55
|
/**
|
|
40
56
|
* Creates and returns a 404 Not Found error instance with the given message.
|
|
41
57
|
* @param {string} message - The error message to include.
|
|
@@ -1541,6 +1557,45 @@ function safeToString (value) {
|
|
|
1541
1557
|
} else if (value === undefined) {
|
|
1542
1558
|
return 'undefined'
|
|
1543
1559
|
}
|
|
1560
|
+
const type = typeof value;
|
|
1561
|
+
if (type === 'string') {
|
|
1562
|
+
return value
|
|
1563
|
+
} else if (type === 'symbol') {
|
|
1564
|
+
return `Symbol(${value.description})`
|
|
1565
|
+
} else if (type === 'function') {
|
|
1566
|
+
return `Function ${value.name}(){}`
|
|
1567
|
+
}
|
|
1568
|
+
if (value instanceof String) {
|
|
1569
|
+
return value.toString()
|
|
1570
|
+
}
|
|
1571
|
+
if (Number.isNaN(value)) {
|
|
1572
|
+
return 'NaN'
|
|
1573
|
+
}
|
|
1574
|
+
if (value === Infinity) {
|
|
1575
|
+
return 'Infinity'
|
|
1576
|
+
}
|
|
1577
|
+
if (value === -Infinity) {
|
|
1578
|
+
return '-Infinity'
|
|
1579
|
+
}
|
|
1580
|
+
if (value instanceof Error) {
|
|
1581
|
+
return `${value.constructor.name}: ${value.message}`
|
|
1582
|
+
}
|
|
1583
|
+
if (value instanceof Promise) {
|
|
1584
|
+
return 'Promise'
|
|
1585
|
+
}
|
|
1586
|
+
if (value instanceof Set) {
|
|
1587
|
+
return `Set: ${safeToString(Array.from(value))}`
|
|
1588
|
+
}
|
|
1589
|
+
if (value instanceof Map) {
|
|
1590
|
+
return `Map: ${safeToString(Array.from(value.entries()))}`
|
|
1591
|
+
}
|
|
1592
|
+
if (value instanceof RegExp) {
|
|
1593
|
+
return value.toString()
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
if (Array.isArray(value)) {
|
|
1597
|
+
return `[${value.map(safeToString).join(', ')}]`
|
|
1598
|
+
}
|
|
1544
1599
|
let valueStr;
|
|
1545
1600
|
try {
|
|
1546
1601
|
valueStr = JSON.stringify(value);
|
|
@@ -2048,6 +2103,9 @@ async function parallelAllSettled (tasks, maxParallel = 5) {
|
|
|
2048
2103
|
* 3. Notice:
|
|
2049
2104
|
* * In Beginning, we start bulk(maxParallel) of tasks
|
|
2050
2105
|
* * One task failed, it will start next task immediately, Not Wait for the bulk(maxParallel) to complete
|
|
2106
|
+
* * DO NOT ensure all tasks are executed.
|
|
2107
|
+
* * Tasks are NOT stoped immediately when a Task succeeds
|
|
2108
|
+
* * will be stopped when A bulk(maxParallel) is executed.
|
|
2051
2109
|
* @param {Array<Function|Promise<any>>} tasks - Array of async functions to execute
|
|
2052
2110
|
* @param {number} [maxParallel=5] - Maximum number of tasks to run in parallel
|
|
2053
2111
|
* @param {string} [failureMessage] - Error message when all tasks failed
|
|
@@ -2484,8 +2542,8 @@ function writeString (buffer, str, offset = 0) {
|
|
|
2484
2542
|
* * if dataLength <= 0, throw "Not Positive" Error
|
|
2485
2543
|
* * if dataLength is omitted, read all bytes from dataOffset to the end of dataArrayBuffer
|
|
2486
2544
|
* * if dataLength + dataOffset > dataArrayBuffer.length, read all bytes from dataOffset to the end of dataArrayBuffer
|
|
2487
|
-
* @param {ArrayBuffer} target - The target buffer to write into.
|
|
2488
|
-
* @param {ArrayBuffer} dataArrayBuffer - The data ArrayBuffer to write.
|
|
2545
|
+
* @param {ArrayBuffer|SharedArrayBuffer} target - The target buffer to write into.
|
|
2546
|
+
* @param {ArrayBuffer|SharedArrayBuffer} dataArrayBuffer - The data ArrayBuffer to write.
|
|
2489
2547
|
* @param {number} [targetOffset=0] - Zero-based index at which to start write.
|
|
2490
2548
|
* @param {number} [dataOffset=0] - The offset in the dataArrayBuffer
|
|
2491
2549
|
* @param {number} [dataLength] - how many bytes extract from dataArrayBuffer
|