@n3okill/utils
Version:
Many javascript helpers
49 lines • 1.95 kB
JavaScript
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.stringsPathToObject = stringsPathToObject;
const NodePath = __importStar(require("path"));
const type_1 = require("../type");
/**
* Transforms an array of strings into an object
* @param str Array of strings to be transformed
* @param separator Separator used in string, default to node "path" sep
* @returns
*/
function stringsPathToObject(str, separator = NodePath.sep) {
const res = {};
str.forEach((s) => {
const parts = s.split(separator);
let o = res;
parts.forEach((p) => {
// eslint-disable-next-line security/detect-object-injection
o[p] = !(0, type_1.isUndefined)(o[p]) ? o[p] : {};
// eslint-disable-next-line security/detect-object-injection
o = o[p];
});
});
return res;
}
//# sourceMappingURL=stringsPathToObject.js.map
;