UNPKG

@n3okill/utils

Version:
53 lines 2.15 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.objectToPathStrings = objectToPathStrings; const NodePath = __importStar(require("path")); const isObject_1 = require("../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 */ 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 ((0, isObject_1.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