@creejs/commons-lang 2.1.30 → 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.
@@ -168,6 +168,7 @@
168
168
  */
169
169
 
170
170
  var LangUtils = {
171
+ get,
171
172
  constructorName,
172
173
  defaults,
173
174
  extend,
@@ -179,6 +180,31 @@
179
180
  deepCloneToPlainObject
180
181
  };
181
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
+
182
208
  /**
183
209
  * Gets the constructor name of a value.
184
210
  * @param {*} value - The value to check.