function read(collection, property) {
const isCollectionInvalid = !collection || typeof collection !== 'object';
const isPropertyInvalid =
!property || !property.trim().length || typeof property !== 'string';
if (isCollectionInvalid || isPropertyInvalid) {
return undefined;
}
let path = property.replaceAll('[', '.');
path = path.replaceAll(']', '.');
path = path.split('.').filter(Boolean);
let i;
let currentKey;
let currentItem = collection;
for (i = 0; i < path.length; i++) {
currentKey = path[i];
if (!Object.prototype.hasOwnProperty.call(currentItem, currentKey)) {
currentItem = undefined;
break;
}
currentItem = currentItem[currentKey];
}
return currentItem;
}
Read-only