@gustavnikolaj/string-utils
Advanced tools
Comparing version 1.3.1 to 2.0.0
@@ -33,22 +33,18 @@ "use strict"; | ||
if (indentationOfFirstLine === 0) { | ||
// Just remove leading and trailing spaces. | ||
return str.trim(); | ||
var regexp = new RegExp("^[ ]{".concat(indentationOfFirstLine, "}")); | ||
var strippedLines = indentationOfFirstLine === 0 ? lines : lines.map(function (line) { | ||
return line.replace(regexp, ""); | ||
}); | ||
if (strippedLines[0].trim() === "") { | ||
strippedLines = strippedLines.slice(1); | ||
} | ||
var regexp = new RegExp("^[ ]{".concat(indentationOfFirstLine, "}")); | ||
return lines.reduce(function (strs, line, index) { | ||
if (strs.length === 0 && line.trim() === "") { | ||
return strs; | ||
} | ||
if (strippedLines.length > 0 && strippedLines[strippedLines.length - 1].trim() === "") { | ||
strippedLines = strippedLines.slice(0, -1); | ||
} | ||
if (index + 1 === lines.length && line.trim() === "") { | ||
return strs; | ||
} | ||
strs.push(line.replace(regexp, "")); | ||
return strs; | ||
}, []).join("\n"); | ||
return strippedLines.join("\n"); | ||
} | ||
module.exports = exports.default; |
{ | ||
"name": "@gustavnikolaj/string-utils", | ||
"version": "1.3.1", | ||
"version": "2.0.0", | ||
"description": "Template string utilities", | ||
@@ -19,3 +19,6 @@ "main": "index.js", | ||
"lint": "eslint . && prettier --check '**/*.js'", | ||
"postpublish": "git push origin --all && git push origin --tags", | ||
"postversion": "npm publish", | ||
"prepublish": "npm run build", | ||
"preversion": "npm test", | ||
"test": "mocha" | ||
@@ -22,0 +25,0 @@ }, |
13299
205