2 title: Underscore-string
3 category: JavaScript libraries
13 _.mixin(_.string.exports());
21 _.truncate("Hello world", 4) // => "Hell..."
22 _.prune("Hello world", 5) // => "Hello..."
24 _.trim(" foo ") // => "foo"
25 _.trim("-foo-", '-') // => "foo"
31 _.numberFormat(1000, 2) // => "1,000.00"
35 _.capitalize("foo bar") // => "Foo Bar"
36 _.humanize("hey-there foo") // => "Hey there foo"
37 _.titleize('My name is hi') // => "My Name Is Hi"
39 _.dasherize('MozTransform') // => "-moz-transform"
40 _.underscored('MozTransform') // => "moz_transform"
41 _.classify('-moz-transform') // => "MozTransform"
42 _.camelize('moz_transform') // => "MozTransform"
44 _.slugify("hey there") // => "hey-there"
46 _.swapCase("hELLO") // => "Hello"
50 _.startsWith('image.gif', 'image') // => true
51 _.endsWith('image.gif', '.gif') // => true
52 _.isBlank(" ") // => true (also for "\n", "")
57 _.unescapeHTML("<div>")
58 _.stripTags("<div>hi</div>")
62 _.quote("hi", '"') // => '"hi"'
63 _.unquote('"hi"') // => "hi"
67 _.lines("hi\nthere") // => ["hi","there"]
68 _.words("hi there you") // => ["hi","there","you"]
72 _.sprintf("%.1f", 1.17)
76 _.pad("1", 8) // => " 1"
77 _.pad("1", 8, "0") // => "00000001"
78 _.pad("1", 8, " ", "right") // => "1 "
79 _.pad("1", 8, " ", "both") // => " 1 "
81 _.lpad(..) // same as _.pad(.., 'left')
82 _.rpad(..) // same as _.pad(.., 'right')
83 _.lrpad(..) // same as _.pad(.., 'both')
87 * https://github.com/epeli/underscore.string