1 | "use strict";
|
2 |
|
3 | const getValueAt = (obj, selector) => {
|
4 | const selectors = typeof selector === `string` ? selector.split(`.`) : selector;
|
5 | return get(obj, selectors);
|
6 | };
|
7 |
|
8 | const get = (obj, selectors) => {
|
9 | if (Array.isArray(obj)) return getArray(obj, selectors);
|
10 | const [key, ...rest] = selectors;
|
11 | const value = obj[key];
|
12 | if (!rest.length) return value;
|
13 | if (Array.isArray(value)) return getArray(value, rest);
|
14 | if (value && typeof value === `object`) return get(value, rest);
|
15 | return undefined;
|
16 | };
|
17 |
|
18 | const getArray = (arr, selectors) => arr.map(value => Array.isArray(value) ? getArray(value, selectors) : get(value, selectors)).filter(v => v !== undefined);
|
19 |
|
20 | module.exports = {
|
21 | getValueAt
|
22 | };
|
23 |
|
\ | No newline at end of file |