Functions exported for mixing with underscore object.
Usage: .mixin(.string.exports()); interface UnderscoreStatic extends UnderscoreStringStaticExports { }
Converts underscored or dasherized string to a camelized one. ('-moz-transform') => 'MozTransform'
string
Converts first letter of the string to uppercase. ('foo Bar') => 'Foo Bar'
string
Left/right-pad a string. Alias for pad(str, length, padStr, 'both') ('1', 8, '0') => '00001000'
string
Convert string to an array of characters. ('Hello') => ['H','e','l','l','o']
Array<any>
Chop a string into pieces. ('whitespace', 3) => ['whi','tes','pac','e']
String to chop
Size of the pieces
Array<any>
Converts string to camelized class name. ('some_class_name') => 'SomeClassName'
string
Compress some whitespaces to one. (' foo bar ') => 'foo bar'
string
Tests if string contains a substring. ('foobar', 'ob') => true
boolean
Count occurences of a sub string. ('Hello world', 'l') => 3
number
Converts a underscored or camelized string into an dasherized one. ('MozTransform') => '-moz-transform'
string
Checks if string ends with another string. ('image.gif', 'gif') => true
boolean
Converts HTML special characters to their entity equivalents. ('
string
Escape a string for use in a regular expression.
string
Converts an underscored, camelized, or dasherized string into a humanized one. Also removes beginning and ending whitespace, and removes the postfix '_id'. (' capitalize dash-CamelCase_underscore trim ') => 'Capitalize dash camel case underscore trim'
string
Tests if string contains a substring. ('foobar', 'ob') => true
boolean
Insert a string at index.
string
Determine if a string is 'blank.'
boolean
Joins strings together with given separator. (' ', 'foo', 'bar') => 'foo bar'
string
Calculates Levenshtein distance between two strings. ('kitten', 'kittah') => 2
number
Split string by newlines character. ('Hello\nWorld') => ['Hello', 'World']
Array<any>
Right-pad a string. Alias for pad(str, length, padStr, 'right') ('1', 8, '0') => '10000000'
string
Left-pad a string. Alias for pad(str, length, padStr, 'left') ('1', 8, '0') => '00000001'
string
Left/right-pad a string. Alias for pad(str, length, padStr, 'both') ('1', 8, '0') => '00001000'
string
Left trim. Similar to trim, but only for left side.
string
Left trim. Similar to trim, but only for left side.
string
Naturally sort strings like humans would do. Caution: this function is charset dependent.
number
Formats the numbers. (1000, 2) => '1,000.00' (123456789.123, 5, '.', ',') => '123,456,789.12300'
string
Pads a string with characters until the total string length is equal to the passed length parameter. By default, pads on the left with the space char (' '). padStr is truncated to a single character if necessary. ('1', 8) => ' 1' ('1', 8, '0') => '00000001' ('1', 8, '0', 'right') => '10000000' ('1', 8, '0', 'both') => '00001000' ('1', 8, 'bleepblorp', 'both') => 'bbbb1bbb'
string
Elegant version of truncate. Makes sure the pruned string does not exceed the original length. Avoid half-chopped words when truncating. ('Hello, cruel world', 15) => 'Hello, cruel...'
string
Quotes a string. quoteChar defaults to " ('foo') => '"foo"'
string
Quotes a string. quoteChar defaults to " ('foo') => '"foo"'
string
Repeat a string with an optional separator. ('foo', 3) => 'foofoofoo' ('foo', 3, 'bar') => 'foobarfoobarfoo'
string
Return reversed string. ('foobar') => 'raboof'
string
Left-pad a string. Alias for pad(str, length, padStr, 'left') ('1', 8, '0') => '00000001'
string
Right-pad a string. Alias for pad(str, length, padStr, 'right') ('1', 8, '0') => '10000000'
string
Right trim. Similar to trim, but only for right side.
string
Right trim. Similar to trim, but only for right side.
string
Transform text into a URL slug. Replaces whitespaces, accentuated, and special characters with a dash. ('Un éléphant à l'orée du bois') => 'un-elephant-a-loree-du-bois'
string
Splice a string like an array.
string
C like string formatting. _.sprintf('%.1f', 1.17) => '1.2'
string
Checks if string starts with another string. ('image.gif', 'image') => true
boolean
Searches a string from left to right for a pattern. Returns a substring consisting of the characters in the string that are to the left of the pattern. If no match found, returns entire string. ('Thisis_a_test_string').strLeft('') => 'This'
string
Searches a string from right to left for a pattern. Returns a substring consisting of the characters in the string that are to the left of the pattern. If no match found, returns entire string. ('Thisis_a_test_string').strLeftBack('') => 'This_is_a_test'
string
Searches a string from left to right for a pattern. Returns a substring consisting of the characters in the string that are to the right of the pattern. If no match found, returns entire string. ('Thisis_a_test_string').strRight('') => 'is_a_test_string'
string
Searches a string from right to left for a pattern. Returns a substring consisting of the characters in the string that are to the right of the pattern. If no match found, returns entire string. ('Thisis_a_test_string').strRightBack('') => 'string'
string
Trims defined characters from begining and ending of the string. Defaults to whitespace characters. (' foobar ') => 'foobar' ('-foobar-', '_-') => 'foobar'
string
Removes all html tags from string.
string
Returns the successor to passed string. ('a') => 'b'
string
Surround a string with another string. ('foo', 'ab') => 'abfooab'
string
Returns a copy of the string in which all the case-based characters have had their case swapped. ('hELLO') => 'Hello'
string
Capitalize first letter of every word in the string. ('my name is epeli') => 'My Name Is Epeli'
string
Turn strings that can be commonly considered as booleans to real booleans. Such as "true", "false", "1" and "0". This function is case insensitive. ('true') => true ('FALSE') => false ('random') => undefined ('truthy', ['truthy'], ['falsy']) => true ('true only at start', [/^true/]) => true
boolean
Parse string to number. Returns NaN if string can't be parsed to number. ('2.556').toNumber() => 3 ('2.556').toNumber(1) => 2.6
number
Join an array into a human readable sentence. (['jQuery', 'Mootools', 'Prototype']) => 'jQuery, Mootools and Prototype' (['jQuery', 'Mootools', 'Prototype'], ', ', ' unt ') => 'jQuery, Mootools unt Prototype'
string
The same as toSentence, but uses ', ' as default for lastSeparator.
string
Trims defined characters from begining and ending of the string. Defaults to whitespace characters. (' foobar ') => 'foobar' ('-foobar-', '_-') => 'foobar'
string
Truncate string to specified length. ('Hello world').truncate(5) => 'Hello...' ('Hello').truncate(10) => 'Hello'
string
Converts a camelized or dasherized string into an underscored one. ('MozTransform') => 'moz_transform'
string
Converts entity characters to HTML equivalents. ('<div>Blah blah blah</div>') => '
string
Unquotes a string. quoteChar defaults to " ('"foo"') => 'foo' ("'foo'", "'") => 'foo'
string
Split string by delimiter (String or RegExp). /\s+/ by default. (' I love you ') => ['I','love','you'] ('Ilove_you', '') => ['I','love','you']
Array<string>
Split string by delimiter (String or RegExp). /\s+/ by default. (' I love you ') => ['I','love','you'] ('Ilove_you', '') => ['I','love','you']
Array<string>
Split string by delimiter (String or RegExp). /\s+/ by default. (' I love you ') => ['I','love','you'] ('Ilove_you', '') => ['I','love','you']
Array<string>