@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.
@@ -162,6 +162,7 @@ class AggregatedError extends Error {
162
162
  */
163
163
 
164
164
  var LangUtils = {
165
+ get,
165
166
  constructorName,
166
167
  defaults,
167
168
  extend,
@@ -173,6 +174,31 @@ var LangUtils = {
173
174
  deepCloneToPlainObject
174
175
  };
175
176
 
177
+ /**
178
+ *
179
+ * @param {{[key:string]:any}} obj
180
+ * @param {string} path
181
+ * @param {any} [defaultValue]
182
+ * @returns
183
+ */
184
+ function get (obj, path, defaultValue) {
185
+ if (obj == null) {
186
+ return defaultValue
187
+ }
188
+ if (typeof path !== 'string') {
189
+ throw new Error('"path" must be a string')
190
+ }
191
+ const pathArray = path.split('.');
192
+ let current = obj;
193
+ for (const key of pathArray) {
194
+ if (current[key] === undefined) {
195
+ return defaultValue
196
+ }
197
+ current = current[key];
198
+ }
199
+ return current
200
+ }
201
+
176
202
  /**
177
203
  * Gets the constructor name of a value.
178
204
  * @param {*} value - The value to check.