14 lines
340 B
JavaScript
14 lines
340 B
JavaScript
export const reach = (path, data) => {
|
|
if (!data) return;
|
|
|
|
const parts = path.split('.');
|
|
let part;
|
|
while (part = parts.shift()) {
|
|
data = data instanceof Set || data instanceof Map ? data.get(part) : data[part];
|
|
if (parts.length > 0 && (typeof data !== 'object' || data === null)) {
|
|
return;
|
|
}
|
|
}
|
|
return data;
|
|
}
|