smartstring/dist/smartstring.indent.js
2016-11-01 00:22:38 +01:00

61 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJpbmcuaW5kZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzdHJpbmcuaW5kZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFFQSxJQUFJLFdBQVcsR0FBRyxDQUFDLFNBQWlCO0lBQ2hDLElBQUksV0FBVyx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