2017-03-09 06:23:23 +00:00
|
|
|
export function getKeys (obj, prefix = '') {
|
2017-03-12 05:38:44 +00:00
|
|
|
let allKeys = [];
|
2017-03-09 06:23:23 +00:00
|
|
|
|
|
|
|
if (Array.isArray(obj)) {
|
|
|
|
for (let i = 0; i < obj.length; i++) {
|
2017-03-12 05:38:44 +00:00
|
|
|
allKeys = [...allKeys, ...getKeys(obj[i], `${prefix}[${i}]`)];
|
2017-03-09 06:23:23 +00:00
|
|
|
}
|
|
|
|
} else if (typeof obj === 'object') {
|
|
|
|
for (const key of Object.keys(obj)) {
|
|
|
|
const newPrefix = prefix ? `${prefix}.${key}` : key;
|
2017-03-12 05:38:44 +00:00
|
|
|
allKeys = [...allKeys, ...getKeys(obj[key], newPrefix)];
|
2017-03-09 06:23:23 +00:00
|
|
|
}
|
2017-03-12 00:31:23 +00:00
|
|
|
} else if (typeof obj === 'function') {
|
|
|
|
// Skip functions
|
|
|
|
} else if (prefix) {
|
2017-03-12 05:38:44 +00:00
|
|
|
allKeys.push({name: prefix, value: obj});
|
2017-03-09 06:23:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return allKeys;
|
|
|
|
}
|