Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface UnderscoreStringStaticExports

Functions exported for mixing with underscore object.

Usage: .mixin(.string.exports()); interface UnderscoreStatic extends UnderscoreStringStaticExports { }

Hierarchy

Index

Methods

camelize

  • camelize(str: string): string

capitalize

  • capitalize(str: string): string

center

  • center(str: string, length: number, padStr?: string): string

chars

  • chars(str: string): any[]

chop

  • chop(str: string, step: number): any[]

classify

  • classify(str: string): string

clean

  • clean(str: string): string

count

  • count(str: string, substr: string): number

dasherize

  • dasherize(str: string): string

endsWith

  • endsWith(value: string, starts: string): boolean

escapeHTML

  • escapeHTML(str: string): string

escapeRegExp

  • escapeRegExp(str: string): string

exports

humanize

  • humanize(str: string): 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'

    Parameters

    • str: string

    Returns string

insert

  • insert(str: string, i: number, substr: string): string

isBlank

  • isBlank(str: string): boolean

join

  • join(separator: string, ...args: string[]): string

levenshtein

  • levenshtein(str1: string, str2: string): number

lines

  • lines(str: string): any[]

ljust

  • ljust(str: string, length: number, padStr?: string): string

lpad

  • lpad(str: string, length: number, padStr?: string): string

lrpad

  • lrpad(str: string, length: number, padStr?: string): string

lstrip

  • lstrip(str: string, characters?: string): string

ltrim

  • ltrim(str: string, characters?: string): string

naturalCmp

  • naturalCmp(str1: string, str2: string): number

numberFormat

  • numberFormat(number: number, dec?: number, dsep?: string, tsep?: string): string
  • Formats the numbers. (1000, 2) => '1,000.00' (123456789.123, 5, '.', ',') => '123,456,789.12300'

    Parameters

    • number: number
    • Optional dec: number
    • Optional dsep: string
    • Optional tsep: string

    Returns string

pad

  • 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
    • Optional padStr: string
    • Optional type: string

    Returns string

prune

  • 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
    • Optional pruneStr: string

    Returns string

q

  • q(str: string, quoteChar?: string): string

quote

  • quote(str: string, quoteChar?: string): string

repeat

  • 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
    • Optional separator: string

    Returns string

rjust

  • rjust(str: string, length: number, padStr?: string): string

rpad

  • rpad(str: string, length: number, padStr?: string): string

rstrip

  • rstrip(str: string, characters?: string): string

rtrim

  • rtrim(str: string, characters?: string): string

slugify

  • 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

splice

  • splice(str: string, i: number, howmany: number, substr?: string): string

sprintf

  • sprintf(format: string, ...args: any[]): string

startsWith

  • startsWith(str: string, starts: string): boolean

strLeft

  • 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. ('This_is_a_teststring').strLeft('') => 'This'

    Parameters

    • str: string
    • sep: string

    Returns string

strLeftBack

  • 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. ('This_is_a_teststring').strLeftBack('') => 'This_is_a_test'

    Parameters

    • str: string
    • sep: string

    Returns string

strRight

  • 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. ('This_is_a_teststring').strRight('') => 'is_a_test_string'

    Parameters

    • str: string
    • sep: string

    Returns string

strRightBack

  • 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. ('This_is_a_teststring').strRightBack('') => 'string'

    Parameters

    • str: string
    • sep: string

    Returns string

strip

  • 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
    • Optional characters: string

    Returns string

stripTags

  • stripTags(str: string): string

succ

  • succ(str: string): string

surround

  • surround(str: string, wrapper: string): string

swapCase

  • swapCase(str: string): string

titleize

  • titleize(str: string): string

toBoolean

  • toBoolean(str: string, trueValues?: any[], falseValues?: 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
    • Optional trueValues: any[]
    • Optional falseValues: any[]

    Returns boolean

toNumber

  • 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
    • Optional decimals: number

    Returns number

toSentence

  • toSentence(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: any[]
    • Optional separator: string
    • Optional lastSeparator: string
    • Optional serial: boolean

    Returns string

toSentenceSerial

  • toSentenceSerial(array: any[], separator?: string, lastSeparator?: string): string

trim

  • 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
    • Optional characters: string

    Returns string

truncate

  • truncate(str: string, length: number, truncateStr?: string): string
  • Truncate string to specified length. ('Hello world').truncate(5) => 'Hello...' ('Hello').truncate(10) => 'Hello'

    Parameters

    • str: string
    • length: number
    • Optional truncateStr: string

    Returns string

underscored

  • underscored(str: string): string

unescapeHTML

  • unescapeHTML(str: string): string

unquote

  • unquote(str: string, quoteChar?: string): string

words

  • words(str: string): string[]
  • words(str: string, delimiter: string): string[]
  • words(str: string, delimiter: RegExp): string[]
  • Split string by delimiter (String or RegExp). /\s+/ by default. (' I love you ') => ['I','love','you'] ('I_loveyou', '') => ['I','love','you']

    Parameters

    • str: string

    Returns string[]

  • Split string by delimiter (String or RegExp). /\s+/ by default. (' I love you ') => ['I','love','you'] ('I_loveyou', '') => ['I','love','you']

    Parameters

    • str: string
    • delimiter: string

    Returns string[]

  • Split string by delimiter (String or RegExp). /\s+/ by default. (' I love you ') => ['I','love','you'] ('I_loveyou', '') => ['I','love','you']

    Parameters

    • str: string
    • delimiter: RegExp

    Returns string[]