@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.
@@ -38,6 +38,16 @@
38
38
  return err._type === '_' && typeof err.code === 'number'
39
39
  }
40
40
 
41
+ /**
42
+ *
43
+ * @param {string} message
44
+ * @param {number} time ms
45
+ * @returns {_Error}
46
+ */
47
+ static timeout (message, time) {
48
+ return new _Error(`Timeout ${time}ms: ${message}`, 504)
49
+ }
50
+
41
51
  /**
42
52
  * "412 Precondition Failed" indicates that one or more conditions
43
53
  * given in the request header fields evaluated to false when tested on the server.
@@ -50,8 +60,8 @@
50
60
  * @param {string} message
51
61
  * @returns {_Error}
52
62
  */
53
- static PreconditionFailed (message) {
54
- return new _Error(`Not Found: ${message}`, 412)
63
+ static preconditionFailed (message) {
64
+ return new _Error(`Not Matched: ${message}`, 412)
55
65
  }
56
66
 
57
67
  /**
@@ -158,6 +168,7 @@
158
168
  */
159
169
 
160
170
  var LangUtils = {
171
+ get,
161
172
  constructorName,
162
173
  defaults,
163
174
  extend,
@@ -169,6 +180,31 @@
169
180
  deepCloneToPlainObject
170
181
  };
171
182
 
183
+ /**
184
+ *
185
+ * @param {{[key:string]:any}} obj
186
+ * @param {string} path
187
+ * @param {any} [defaultValue]
188
+ * @returns
189
+ */
190
+ function get (obj, path, defaultValue) {
191
+ if (obj == null) {
192
+ return defaultValue
193
+ }
194
+ if (typeof path !== 'string') {
195
+ throw new Error('"path" must be a string')
196
+ }
197
+ const pathArray = path.split('.');
198
+ let current = obj;
199
+ for (const key of pathArray) {
200
+ if (current[key] === undefined) {
201
+ return defaultValue
202
+ }
203
+ current = current[key];
204
+ }
205
+ return current
206
+ }
207
+
172
208
  /**
173
209
  * Gets the constructor name of a value.
174
210
  * @param {*} value - The value to check.