insomnia/app/templating/utils.js
Gregory Schier 6d1f3e34ba Autocomplete for more headers (#113)
* Fixed duplication kve bug

* Autocomplete more headers
2017-03-11 21:38:44 -08:00

21 lines
580 B
JavaScript

export function getKeys (obj, prefix = '') {
let allKeys = [];
if (Array.isArray(obj)) {
for (let i = 0; i < obj.length; i++) {
allKeys = [...allKeys, ...getKeys(obj[i], `${prefix}[${i}]`)];
}
} else if (typeof obj === 'object') {
for (const key of Object.keys(obj)) {
const newPrefix = prefix ? `${prefix}.${key}` : key;
allKeys = [...allKeys, ...getKeys(obj[key], newPrefix)];
}
} else if (typeof obj === 'function') {
// Skip functions
} else if (prefix) {
allKeys.push({name: prefix, value: obj});
}
return allKeys;
}