@creejs/commons-lang 2.1.29 → 2.1.31
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 +38 -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 +38 -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 +38 -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 +8 -1
- package/types/lang-utils.d.ts +11 -0
package/dist/cjs/index-dev.cjs
CHANGED
|
@@ -36,6 +36,16 @@ class _Error extends Error {
|
|
|
36
36
|
return err._type === '_' && typeof err.code === 'number'
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param {string} message
|
|
42
|
+
* @param {number} time ms
|
|
43
|
+
* @returns {_Error}
|
|
44
|
+
*/
|
|
45
|
+
static timeout (message, time) {
|
|
46
|
+
return new _Error(`Timeout ${time}ms: ${message}`, 504)
|
|
47
|
+
}
|
|
48
|
+
|
|
39
49
|
/**
|
|
40
50
|
* "412 Precondition Failed" indicates that one or more conditions
|
|
41
51
|
* given in the request header fields evaluated to false when tested on the server.
|
|
@@ -48,8 +58,8 @@ class _Error extends Error {
|
|
|
48
58
|
* @param {string} message
|
|
49
59
|
* @returns {_Error}
|
|
50
60
|
*/
|
|
51
|
-
static
|
|
52
|
-
return new _Error(`Not
|
|
61
|
+
static preconditionFailed (message) {
|
|
62
|
+
return new _Error(`Not Matched: ${message}`, 412)
|
|
53
63
|
}
|
|
54
64
|
|
|
55
65
|
/**
|
|
@@ -156,6 +166,7 @@ class AggregatedError extends Error {
|
|
|
156
166
|
*/
|
|
157
167
|
|
|
158
168
|
var LangUtils = {
|
|
169
|
+
get,
|
|
159
170
|
constructorName,
|
|
160
171
|
defaults,
|
|
161
172
|
extend,
|
|
@@ -167,6 +178,31 @@ var LangUtils = {
|
|
|
167
178
|
deepCloneToPlainObject
|
|
168
179
|
};
|
|
169
180
|
|
|
181
|
+
/**
|
|
182
|
+
*
|
|
183
|
+
* @param {{[key:string]:any}} obj
|
|
184
|
+
* @param {string} path
|
|
185
|
+
* @param {any} [defaultValue]
|
|
186
|
+
* @returns
|
|
187
|
+
*/
|
|
188
|
+
function get (obj, path, defaultValue) {
|
|
189
|
+
if (obj == null) {
|
|
190
|
+
return defaultValue
|
|
191
|
+
}
|
|
192
|
+
if (typeof path !== 'string') {
|
|
193
|
+
throw new Error('"path" must be a string')
|
|
194
|
+
}
|
|
195
|
+
const pathArray = path.split('.');
|
|
196
|
+
let current = obj;
|
|
197
|
+
for (const key of pathArray) {
|
|
198
|
+
if (current[key] === undefined) {
|
|
199
|
+
return defaultValue
|
|
200
|
+
}
|
|
201
|
+
current = current[key];
|
|
202
|
+
}
|
|
203
|
+
return current
|
|
204
|
+
}
|
|
205
|
+
|
|
170
206
|
/**
|
|
171
207
|
* Gets the constructor name of a value.
|
|
172
208
|
* @param {*} value - The value to check.
|