@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.
- package/dist/cjs/index-dev.cjs +26 -0
- 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 +26 -0
- 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 +26 -0
- 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/lang-utils.d.ts +11 -0
package/dist/cjs/index-dev.cjs
CHANGED
|
@@ -166,6 +166,7 @@ class AggregatedError extends Error {
|
|
|
166
166
|
*/
|
|
167
167
|
|
|
168
168
|
var LangUtils = {
|
|
169
|
+
get,
|
|
169
170
|
constructorName,
|
|
170
171
|
defaults,
|
|
171
172
|
extend,
|
|
@@ -177,6 +178,31 @@ var LangUtils = {
|
|
|
177
178
|
deepCloneToPlainObject
|
|
178
179
|
};
|
|
179
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
|
+
|
|
180
206
|
/**
|
|
181
207
|
* Gets the constructor name of a value.
|
|
182
208
|
* @param {*} value - The value to check.
|