2017-05-06 23:23:03 +00:00
|
|
|
"use strict";
|
2017-05-25 16:32:53 +00:00
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
2017-05-06 23:23:03 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2017-05-25 16:32:53 +00:00
|
|
|
/**
|
|
|
|
* adds a variable in string dot notation to an already more or less expanded object
|
|
|
|
*/
|
|
|
|
exports.deepAddToObject = (objectArg, varStringArg, valueArg) => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
let varNamesArray = varStringArg.split('.');
|
|
|
|
let referencePointer = objectArg;
|
|
|
|
for (let i = 0; i !== varNamesArray.length; i++) {
|
|
|
|
let varName = varNamesArray[i];
|
|
|
|
// is there a next variable ?
|
|
|
|
let varNameNext = (() => {
|
|
|
|
if (varNamesArray[i + 1]) {
|
|
|
|
return varNamesArray[i + 1];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
})();
|
|
|
|
// build the tree in suppliedVariables
|
|
|
|
if (!referencePointer[varName] && !varNameNext) {
|
|
|
|
referencePointer[varName] = valueArg;
|
2017-05-27 01:21:55 +00:00
|
|
|
referencePointer = null;
|
2017-05-25 16:32:53 +00:00
|
|
|
}
|
|
|
|
else if (!referencePointer[varName] && varNameNext) {
|
|
|
|
referencePointer[varName] = {};
|
|
|
|
referencePointer = referencePointer[varName];
|
|
|
|
}
|
2017-05-27 01:21:55 +00:00
|
|
|
else if (referencePointer[varName] && varNameNext) {
|
|
|
|
referencePointer = referencePointer[varName];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw new Error('Something is strange!');
|
|
|
|
}
|
2017-05-25 16:32:53 +00:00
|
|
|
}
|
|
|
|
});
|
2017-05-27 01:25:42 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzY2FmLmhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNjYWYuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBRUE7O0dBRUc7QUFDUSxRQUFBLGVBQWUsR0FBRyxDQUFPLFNBQVMsRUFBRSxZQUFvQixFQUFFLFFBQWdCO0lBQ25GLElBQUksYUFBYSxHQUFHLFlBQVksQ0FBQyxLQUFLLENBQUMsR0FBRyxDQUFDLENBQUE7SUFDM0MsSUFBSSxnQkFBZ0IsR0FBRyxTQUFTLENBQUE7SUFDaEMsR0FBRyxDQUFDLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxFQUFFLENBQUMsS0FBSyxhQUFhLENBQUMsTUFBTSxFQUFFLENBQUMsRUFBRSxFQUFFLENBQUM7UUFDaEQsSUFBSSxPQUFPLEdBQUcsYUFBYSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBRTlCLDZCQUE2QjtRQUM3QixJQUFJLFdBQVcsR0FBVyxDQUFDO1lBQ3pCLEVBQUUsQ0FBQyxDQUFDLGFBQWEsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO2dCQUN6QixNQUFNLENBQUMsYUFBYSxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQTtZQUM3QixDQUFDO1lBQ0QsTUFBTSxDQUFDLElBQUksQ0FBQTtRQUNiLENBQUMsQ0FBQyxFQUFFLENBQUE7UUFFSixzQ0FBc0M7UUFDdEMsRUFBRSxDQUFDLENBQUMsQ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