12 lines
318 B
JavaScript
12 lines
318 B
JavaScript
export const reach = (path, data) => {
|
|
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;
|
|
}
|