Add clone and reach helpers.

This commit is contained in:
2022-04-18 23:07:00 +02:00
parent 6620648bf0
commit 89d66f019f
3 changed files with 64 additions and 1 deletions

11
reach.js Normal file
View File

@ -0,0 +1,11 @@
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;
}