smartstring/dist/smartstring.indent.js
2016-07-17 17:30:26 +02:00

63 lines
4.6 KiB
JavaScript

"use strict";
let splitString = (stringArg) => {
let resultArray = stringArg.split("\n");
return cleanStringArray(resultArray);
};
let joinString = (stringArrayArg) => {
let resultString = "";
for (let line of stringArrayArg) {
resultString = resultString + line + "\n";
}
;
return resultString;
};
let cleanStringArray = (stringArrayArg) => {
let testRegex = /^[\s]*$/;
if (testRegex.test(stringArrayArg[0])) {
stringArrayArg.shift();
}
if (testRegex.test(stringArrayArg[stringArrayArg.length - 1])) {
stringArrayArg.pop();
}
;
return stringArrayArg;
};
exports.indent = (stringArg, spaceAmount) => {
let resultString;
return resultString;
};
exports.indentWithPrefix = (stringArg, prefixArg) => {
let resultString;
let stringArray = splitString(stringArg);
let resultArray = [];
for (let stringItem of stringArray) {
resultArray.push(prefixArg + stringItem);
}
;
resultString = joinString(resultArray);
return resultString;
};
exports.normalize = (stringArg) => {
let resultString;
let splitStringArray = splitString(stringArg);
let minCommonLeftOffset;
let deIndentRegex = /^(\s*)/;
let emptyLineRegex = /^(\s*)$/;
for (let stringItem of splitStringArray) {
let offsetString = deIndentRegex.exec(stringItem)[1];
if ((typeof minCommonLeftOffset == "undefined" || offsetString.length < minCommonLeftOffset)
&& !emptyLineRegex.test(stringItem)) {
minCommonLeftOffset = offsetString.length;
}
;
}
;
let resultSplitStringArray = [];
for (let stringItem of splitStringArray) {
resultSplitStringArray.push(stringItem.substr(minCommonLeftOffset));
}
;
resultString = joinString(resultSplitStringArray);
return resultString;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJpbmcuaW5kZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzdHJpbmcuaW5kZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFFQSxJQUFJLFdBQVcsR0FBRyxDQUFDLFNBQWdCO0lBQy9CLElBQUksV0FBV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