Add clone and reach helpers.

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

No files matched your search

+11
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;
}