underscore.string provides string manipulation extensions for JavaScript.
Case and Casing Conversion
s.capitalize("foo bar") //=> "Foo bar"
s.humanize("hey-there foo") //=> "Hey there foo"
s.titleize('my name is hi') //=> "My Name Is Hi"
s.dasherize('MozTransform') //=> "-moz-transform"
s.underscored('MozTransform') //=> "moz_transform"
s.classify('-moz-transform') //=> "MozTransform"
s.camelize('moz_transform') //=> "mozTransform"
s.slugify("hey there") //=> "hey-there"
s.swapCase("hELLO") //=> "Hello"
String Inspections
s.startsWith('image.gif', 'image') //=> true
s.endsWith('image.gif', '.gif') //=> true
s.isBlank(" ") //=> true
HTML Entities and Stripping
s.escapeHTML("<div>") //=> "<div>"
s.unescapeHTML("<div>") //=> "<div>"
s.stripTags("<div>hi</div>") //=> "hi"
Quoting and Splitting
s.quote("hi", '"') //=> '"hi"'
s.unquote('"hi"') //=> "hi"
s.lines("hi\nthere") //=> ["hi", "there"]
s.words("hi there") //=> ["hi", "there"]
Padding and Formatting
s.pad("1", 8) //=> " 1"
s.pad("1", 8, "0") //=> "00000001"
s.pad("1", 8, " ", "right") //=> "1 "
s.pad("1", 8, " ", "both") //=> " 1 "
s.numberFormat(1000, 2) //=> "1,000.00"
s.sprintf("%.1f", 1.17) //=> "1.2"