Texthelper.js is a library of useful texthelper functions for filtering, formatting and transforming strings and manipulating an html view.
texthelper.truncate("This is an example", 5);
returns: "This..."
texthelper.truncate("This is an example", 5, "!");
returns: "This!"
texthelper.excerpt("This is an example", "an", 5);
returns: "s is an exam"
texthelper.excerpt("The quick brown fox jumps over the lazy dog", "fox", 6);
returns: "brown fox jumps"
texthelper.highlight("This is an example. A code example helps learn how to use a function properly.", "example");
returns: "This is an <mark>example</mark>. A code <mark>example</mark> helps learn how to use a function properly."
texthelper.highlight("This is an example.", "example", "highlight");
returns: "This is an <span class='highlight''>example</span>."
texthelper.wordWrap("This is an example.", 5);
returns: "This is<br/> an example."
texthelper.htmlEscape("<div> Example html content <br /> </div>");
returns: "<div> Example html content <br /> </div>"
texthelper.htmlGenerate("div", {class: "content", id: "123", style: "float: left;"}, "<h1> Main Content</h1>");
returns: "<div class='content' id='123' style='float: left;'><h1> Main Content</h1></div>"
texthelper.htmlGenerate("img", {src: "http://t1.gstatic.com/images?q=tbn:ANd9GcRI-OasQdJqJbQqMNLpKa99tlPvLLGyju-Z7nYM0reVe4dnfVkBOg&t=1"});
returns: "<img src='http://t1.gstatic.com/images?q=tbn:ANd9GcRI-OasQdJqJbQqMNLpKa99tlPvLLGyju-Z7nYM0reVe4dnfVkBOg&t=1' />"
Copyright (c) 2012 Bryan Ashley and Mike Bonds, released under the MIT license.