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'
Parameters
str: string
Returns
string
public insert(str: string, i: number, substr: string): string
Insert a string at index.
Parameters
str: string
i: number
substr: string
Returns
string
public isBlank(str: string): boolean
Determine if a string is 'blank.'
Parameters
str: string
Returns
boolean
public join(separator: string, args?: Array<string>): string
Joins strings together with given separator.
(' ', 'foo', 'bar') => 'foo bar'
Parameters
separator: string
args?: Array<string>optional
Returns
string
public levenshtein(str1: string, str2: string): number
Calculates Levenshtein distance between two strings.
('kitten', 'kittah') => 2
Parameters
str1: string
str2: string
Returns
number
public lines(str: string): Array<any>
Split string by newlines character.
('Hello\nWorld') => ['Hello', 'World']
Parameters
str: string
Returns
Array<any>
public ljust(str: string, length: number, padStr?: string): string
Right-pad a string.
Alias for pad(str, length, padStr, 'right')
('1', 8, '0') => '10000000'
Parameters
str: string
length: number
padStr?: stringoptional
Returns
string
public lpad(str: string, length: number, padStr?: string): string
Left-pad a string.
Alias for pad(str, length, padStr, 'left')
('1', 8, '0') => '00000001'
Parameters
str: string
length: number
padStr?: stringoptional
Returns
string
public lrpad(str: string, length: number, padStr?: string): string
Left/right-pad a string.
Alias for pad(str, length, padStr, 'both')
('1', 8, '0') => '00001000'
Parameters
str: string
length: number
padStr?: stringoptional
Returns
string
public lstrip(str: string, characters?: string): string
Left trim. Similar to trim, but only for left side.
Parameters
str: string
characters?: stringoptional
Returns
string
public ltrim(str: string, characters?: string): string
Left trim. Similar to trim, but only for left side.
Parameters
str: string
characters?: stringoptional
Returns
string
public naturalCmp(str1: string, str2: string): number
Naturally sort strings like humans would do.
Caution: this function is charset dependent.
Parameters
str1: string
str2: string
Returns
number
public numberFormat(number: number, dec?: number, dsep?: string, tsep?: string): string
public pad(str: string, length: number, padStr?: string, type?: string): 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'
Parameters
str: string
length: number
padStr?: stringoptional
type?: stringoptional
Returns
string
public prune(str: string, length: number, pruneStr?: string): 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...'
Parameters
str: string
length: number
pruneStr?: stringoptional
Returns
string
public q(str: string, quoteChar?: string): string
Quotes a string.
quoteChar defaults to "
('foo') => '"foo"'
Parameters
str: string
quoteChar?: stringoptional
Returns
string
public quote(str: string, quoteChar?: string): string
Quotes a string.
quoteChar defaults to "
('foo') => '"foo"'
Parameters
str: string
quoteChar?: stringoptional
Returns
string
public repeat(value: string, count: number, separator?: string): string
Repeat a string with an optional separator.
('foo', 3) => 'foofoofoo'
('foo', 3, 'bar') => 'foobarfoobarfoo'
Parameters
value: string
count: number
separator?: stringoptional
Returns
string
public rjust(str: string, length: number, padStr?: string): string
Left-pad a string.
Alias for pad(str, length, padStr, 'left')
('1', 8, '0') => '00000001'
Parameters
str: string
length: number
padStr?: stringoptional
Returns
string
public rpad(str: string, length: number, padStr?: string): string
Right-pad a string.
Alias for pad(str, length, padStr, 'right')
('1', 8, '0') => '10000000'
Parameters
str: string
length: number
padStr?: stringoptional
Returns
string
public rstrip(str: string, characters?: string): string
Right trim. Similar to trim, but only for right side.
Parameters
str: string
characters?: stringoptional
Returns
string
public rtrim(str: string, characters?: string): string
Right trim. Similar to trim, but only for right side.
Parameters
str: string
characters?: stringoptional
Returns
string
public slugify(str: string): 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'
Parameters
str: string
Returns
string
public splice(str: string, i: number, howmany: number, substr?: string): string
Splice a string like an array.
Parameters
str: string
i: number
howmany: number
substr?: stringoptional
Returns
string
public sprintf(format: string, args?: Array<any>): string
C like string formatting.
_.sprintf('%.1f', 1.17) => '1.2'
Parameters
format: string
args?: Array<any>optional
Returns
string
public startsWith(str: string, starts: string): boolean
Checks if string starts with another string.
('image.gif', 'image') => true
Parameters
str: string
starts: string
Returns
boolean
public strLeft(str: string, sep: string): 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 left of the pattern.
If no match found, returns entire string.
('Thisis_a_test_string').strLeft('') => 'This'
Parameters
str: string
sep: string
Returns
string
public strLeftBack(str: string, sep: 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 left of the pattern.
If no match found, returns entire string.
('Thisis_a_test_string').strLeftBack('') => 'This_is_a_test'
Parameters
str: string
sep: string
Returns
string
public strRight(str: string, sep: string): 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'
Parameters
str: string
sep: string
Returns
string
public strRightBack(str: string, sep: 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'
Parameters
str: string
sep: string
Returns
string
public strip(str: string, characters?: string): string
Trims defined characters from begining and ending of the string.
Defaults to whitespace characters.
(' foobar ') => 'foobar'
('-foobar-', '_-') => 'foobar'
Parameters
str: string
characters?: stringoptional
Returns
string
public stripTags(str: string): string
Removes all html tags from string.
Parameters
str: string
Returns
string
public succ(str: string): string
Returns the successor to passed string.
('a') => 'b'
Parameters
str: string
Returns
string
public surround(str: string, wrapper: string): string
Surround a string with another string.
('foo', 'ab') => 'abfooab'
Parameters
str: string
wrapper: string
Returns
string
public swapCase(str: string): string
Returns a copy of the string in which all the case-based characters have had their case swapped.
('hELLO') => 'Hello'
Parameters
str: string
Returns
string
public titleize(str: string): string
Capitalize first letter of every word in the string.
('my name is epeli') => 'My Name Is Epeli'
Parameters
str: string
Returns
string
public toBoolean(str: string, trueValues?: Array<any>, falseValues?: Array<any>): boolean
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
Parameters
str: string
trueValues?: Array<any>optional
falseValues?: Array<any>optional
Returns
boolean
public toNumber(str: string, decimals?: number): number
Parse string to number.
Returns NaN if string can't be parsed to number.
('2.556').toNumber() => 3
('2.556').toNumber(1) => 2.6
Parameters
str: string
decimals?: numberoptional
Returns
number
public toSentence(array: Array<any>, separator?: string, lastSeparator?: string, serial?: boolean): string
Join an array into a human readable sentence.
(['jQuery', 'Mootools', 'Prototype']) => 'jQuery, Mootools and Prototype'
(['jQuery', 'Mootools', 'Prototype'], ', ', ' unt ') => 'jQuery, Mootools unt Prototype'
Parameters
array: Array<any>
separator?: stringoptional
lastSeparator?: stringoptional
serial?: booleanoptional
Returns
string
public toSentenceSerial(array: Array<any>, separator?: string, lastSeparator?: string): string
The same as toSentence, but uses ', ' as default for lastSeparator.
Parameters
array: Array<any>
separator?: stringoptional
lastSeparator?: stringoptional
Returns
string
public trim(str: string, characters?: string): string
Trims defined characters from begining and ending of the string.
Defaults to whitespace characters.
(' foobar ') => 'foobar'
('-foobar-', '_-') => 'foobar'
Parameters
str: string
characters?: stringoptional
Returns
string
public truncate(str: string, length: number, truncateStr?: string): string