cm-web-modules
Advanced tools
Comparing version 1.18.10 to 1.18.11
{ | ||
"name": "cm-web-modules", | ||
"version": "1.18.10", | ||
"version": "1.18.11", | ||
"description": "Collection of clean and small ES6 modules for the web", | ||
@@ -5,0 +5,0 @@ "main": "src/LibraryManager.js", |
@@ -25,2 +25,19 @@ /** | ||
static wrap(str, maxLength) { | ||
const words = str.split(" ") | ||
let lines = [] | ||
let line = "" | ||
for (let i = 0; i < words.length; i++) { | ||
const word = words[i] | ||
if (line.length + word.length < maxLength) { | ||
line += word + " " | ||
} else { | ||
lines.push(line.trim()) | ||
line = word + " " | ||
} | ||
} | ||
lines.push(line.trim()) | ||
return lines.join("\n") | ||
} | ||
static stripHtml(html) { | ||
@@ -27,0 +44,0 @@ let tmp = document.createElement("div") |
@@ -11,7 +11,7 @@ /** | ||
it("should strip HTML", () => { | ||
const htmlText = "<b>bold</b> <a href='#'>link</a> text"; | ||
const htmlText = "<b>bold</b> <a href='#'>link</a> text" | ||
assert.equal(TextUtils.stripHtml(htmlText), "bold link text") | ||
}) | ||
it("should crop a text", () => { | ||
const longText = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."; | ||
const longText = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur." | ||
assert.equal(TextUtils.crop(longText, 10), "Lorem ipsu…") | ||
@@ -34,2 +34,10 @@ }) | ||
}) | ||
// write a test for TextUtils.wrap() | ||
it("should wrap", () => { | ||
const raw = "Das ist ein langer Text mit vielen Wörtern." | ||
assert.equal(TextUtils.wrap(raw, 12), `Das ist ein | ||
langer Text | ||
mit vielen | ||
Wörtern.`) | ||
}) | ||
}) |
128217
2162