@n3okill/utils
Version:
Many javascript helpers
27 lines • 966 B
JavaScript
import * as NodePath from "path";
import { isObject } from "../type/isObject";
/**
* Transforms an object into an array of strings
* @param obj Object to be transformed into array of strings
* @param separator Separator to be used in string, default to node "path" sep
* @returns
*/
export function objectToPathStrings(obj, separator = NodePath.sep) {
const res = [];
function reduce(path, input) {
Object.keys(input).forEach((key) => {
const p = path ? path + separator + key : key;
// eslint-disable-next-line security/detect-object-injection
if (isObject(input[key]) && Object.keys(input[key]).length > 0) {
// eslint-disable-next-line security/detect-object-injection
reduce(p, input[key]);
}
else {
res.push(p);
}
});
}
reduce("", obj);
return res;
}
//# sourceMappingURL=objectToPathStrings.js.map