• Array
  • Date
  • Function
  • Number
  • Object
  • Range
  • RegExp
  • String
  • Sugar
Type Name Module
All Default Bookmarked
  • range ( [ start ] , [ end ] )

    Creates a new string range between start and end. See ranges for more.

    Returns: Range

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    String.range('a', 'z')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    String.range('t', 'm')

    Source

  • at ( index , [ loop ]  = false )

    Gets the character(s) at a given index. When loop is true, overshooting the end of the string will begin counting from the other end. index may be negative. If index is an array, multiple elements will be returned.

    Returns: Mixed

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.at(0)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.at(2)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.at(5)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.at(5, true)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.at(-1)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'lucky charms'.at([2, 4])

    Source

  • camelize ( [ upper ]  = true )

    Converts underscores and hyphens to camel case. If upper is true, the string will be UpperCamelCase. If the inflections module is included, acronyms can also be defined that will be used when camelizing.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'caps_lock'.camelize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'moz-border-radius'.camelize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'moz-border-radius'.camelize(false)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'http-method'.camelize()

    Source

  • capitalize ( [ lower ]  = false , [ all ]  = false )

    Capitalizes the first character of the string. If lower is true, the remainder of the string will be downcased. If all is true, all words in the string will be capitalized.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'hello'.capitalize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'HELLO'.capitalize(true)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'hello kitty'.capitalize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'hEllO kItTy'.capitalize(true, true)

    Source

  • chars ( [ eachCharFn ] )

    Runs eachCharFn against each character in the string, and returns an array.

    • Callback: eachCharFn

      char The current character.
      i The current index.
      arr An array of all characters.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.chars()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.chars(function(c) {
      // Called 5 times: "j","u","m","p","y"
    });

    Source

  • codes ( [ eachCodeFn ] )

    Runs callback eachCodeFn against each character code in the string. Returns an array of character codes.

    • Callback: eachCodeFn

      code The current character code.
      i The current index.
      str The string being operated on.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.codes()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.codes(function(c) {
      // Called 5 times: 106, 117, 109, 112, 121
    });

    Source

  • compact ( )

    Compacts whitespace in the string to a single space and trims the ends.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'too \n much \n space'.compact()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'enough \n '.compact()

    Source

  • dasherize ( )

    Converts underscores and camel casing to hypens.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'a_farewell_to_arms'.dasherize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'capsLock'.dasherize()

    Source

  • decodeBase64 ( )

    Decodes the string from base64 encoding. This method wraps native methods when available, and uses a custom implementation when not available. It can also handle Unicode string encodings.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'aHR0cDovL3R3aXR0ZXIuY29tLw=='.decodeBase64()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'anVzdCBnb3QgZGVjb2RlZA=='.decodeBase64()

    Source

  • encodeBase64 ( )

    Encodes the string into base64 encoding. This method wraps native methods when available, and uses a custom implementation when not available. It can also handle Unicode string encodings.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'gonna get encoded!'.encodeBase64()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'http://twitter.com/'.encodeBase64()

    Source

  • endsWith ( search , [ pos ]  = length )

    Returns true if the string ends with substring search. Search ends at pos, which defaults to the entire string length. This method is provided as a polyfill.

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.endsWith('py')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.endsWith('MPY')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.endsWith('mp', 4)

    Source

  • escapeHTML ( )

    Converts HTML characters to their entity equivalents.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '<p>some text</p>'.escapeHTML()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'one & two'.escapeHTML()

    Source

  • escapeURL ( [ param ]  = false )

    Escapes characters in a string to make a valid URL. If param is true, it will also escape valid URL characters. Use this when the entire string is meant for use in a query string.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'a, b, and c'.escapeURL()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'http://foo.com/'.escapeURL(true)

    Source

  • first ( [ n ]  = 1 )

    Returns the first n characters of the string.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'lucky charms'.first()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'lucky charms'.first(3)

    Source

  • forEach ( [ search ] , [ eachFn ] )

    Runs callback eachFn against every character in the string, or every every occurence of search if it is provided. Returns an array of matches. search may be either a string or regex, and defaults to every character in the string. If eachFn returns false at any time it will break out of the loop.

    • Callback: eachFn

      match The current match.
      i The current index.
      arr An array of all matches.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.forEach(log)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.forEach(/[r-z]/)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.forEach(/mp/)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.forEach(/[r-z]/, function(m) {
      // Called twice: "u", "y"
    });

    Source

  • format ( obj1 , [ obj2 ] , [ ... )

    Replaces {} tokens in the string with arguments or properties. Tokens support deep properties. If a single object is passed, its properties can be accessed by keywords such as {name}. If multiple objects or a non-object are passed, they can be accessed by the argument position like {0}. Literal braces in the string can be escaped by repeating them.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'Welcome, {name}.'.format({ name: 'Bill' })

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'You are {0} years old today.'.format(5)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '{0.name} and {1.name}'.format(users)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '${currencies.usd.balance}'.format(Harry)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '{{Hello}}'.format('Hello')

    Source

  • from ( [ index ]  = 0 )

    Returns a section of the string starting from index.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'lucky charms'.from()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'lucky charms'.from(7)

    Source

  • hankaku ( [ mode ]  = 'all' )

    Converts full-width characters (zenkaku) to half-width (hankaku). mode accepts all, alphabet, numbers, katakana, spaces, punctuation, or any combination of a, n, k, s, p, respectively.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'タロウ YAMADAです!'.hankaku()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'タロウ YAMADAです!'.hankaku('a')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'タロウ YAMADAです!'.hankaku('alphabet')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'タロウです! 25歳です!'.hankaku('katakana')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'タロウです! 25歳です!'.hankaku('kn')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'タロウです! 25歳です!'.hankaku('sp')

    Source

  • hasScript ( )

    Returns true if the string contains any characters in that script.

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'أتكلم'.hasArabic()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'визит'.hasCyrillic()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '잘 먹겠습니다!'.hasHangul()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'ミックスです'.hasKatakana()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    "l'année".hasLatin()

    Methods

    • hasArabic
    • hasCyrillic
    • hasGreek
    • hasHangul
    • hasHan
    • hasKanji
    • hasHebrew
    • hasHiragana
    • hasKana
    • hasKatakana
    • hasLatin
    • hasThai
    • hasDevanagari

    Source

  • hiragana ( [ all ]  = true )

    Converts katakana into hiragana. If all is false, only full-width katakana will be converted.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'カタカナ'.hiragana()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'コンニチハ'.hiragana()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'カタカナ'.hiragana()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'カタカナ'.hiragana(false)

    Source

  • humanize ( )

    Creates a human readable string. Capitalizes the first word and turns underscores into spaces and strips a trailing '_id', if any. Like titleize, this is meant for creating pretty output. Rules for special cases can be added using addHuman.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'employee_salary'.humanize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'author_id'.humanize()

    Source

  • includes ( search , [ pos ]  = 0 )

    Returns true if search is contained within the string. Search begins at pos, which defaults to the beginning of the string. Sugar enhances this method to allow matching a regex. This method is provided as a polyfill.

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.includes('py')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'broken'.includes('ken', 3)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'broken'.includes('bro', 3)

    Source

  • insert ( str , [ index ]  = length )

    Adds str at index. Allows negative values.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'dopamine'.insert('e', 3)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'spelling eror'.insert('r', -3)

    Source

  • isBlank ( )

    Returns true if the string has length 0 or contains only whitespace.

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ''.isBlank()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '   '.isBlank()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'noway'.isBlank()

    Source

  • isEmpty ( )

    Returns true if the string has length 0.

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ''.isEmpty()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'a'.isBlank()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ' '.isBlank()

    Source

  • isScript ( )

    Returns true if the string contains only characters in that script. Whitespace is ignored.

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'أتكلم'.isArabic()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'визит'.isCyrillic()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '잘 먹겠습니다'.isHangul()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'ミックスです'.isKatakana()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    "l'année".isLatin()

    Methods

    • isArabic
    • isCyrillic
    • isGreek
    • isHangul
    • isHan
    • isKanji
    • isHebrew
    • isHiragana
    • isKana
    • isKatakana
    • isLatin
    • isThai
    • isDevanagari

    Source

  • katakana ( )

    Converts hiragana into katakana.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'かたかな'.katakana()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'こんにちは'.katakana()

    Source

  • last ( [ n ]  = 1 )

    Returns the last n characters of the string.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'lucky charms'.last()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'lucky charms'.last(3)

    Source

  • lines ( [ eachLineFn ] )

    Runs eachLineFn against each line in the string, and returns an array.

    • Callback: eachLineFn

      line The current line.
      i The current index.
      arr An array of all lines.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    lineText.lines()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    lineText.lines(function(l) {
      // Called once per line
    });

    Source

  • pad ( num , [ padding ]  = ' ' )

    Pads the string out with padding to be exactly num characters.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'wasabi'.pad(8)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'wasabi'.pad(8, '-')

    Source

  • padLeft ( num , [ padding ]  = ' ' )

    Pads the string out from the left with padding to be exactly num characters.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'wasabi'.padLeft(8)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'wasabi'.padLeft(8, '-')

    Source

  • padRight ( num , [ padding ]  = ' ' )

    Pads the string out from the right with padding to be exactly num characters.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'wasabi'.padRight(8)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'wasabi'.padRight(8, '-')

    Source

  • parameterize ( )

    Replaces special characters in a string so that it may be used as part of a pretty URL.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'hell, no!'.parameterize()

    Source

  • pluralize ( [ num ] )

    Returns the plural form of the last word in the string. If num is passed, the word will be singularized if equal to 1. Otherwise it will be pluralized. Custom pluralization rules can be added using addPlural.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'post'.pluralize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'post'.pluralize(1)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'post'.pluralize(2)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'octopus'.pluralize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'sheep'.pluralize()

    Source

  • remove ( f )

    Removes the first occurrence of f in the string. f can be a either case-sensitive string or a regex. In either case only the first match will be removed. To remove multiple occurrences, use removeAll.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'schfifty five'.remove('f')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'schfifty five'.remove(/[a-f]/g)

    Source

  • removeAll ( f )

    Removes any occurences of f in the string. f can be either a case-sensitive string or a regex. In either case all matches will be removed. To remove only a single occurence, use remove.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'schfifty five'.removeAll('f')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'schfifty five'.removeAll(/[a-f]/)

    Source

  • removeTags ( [ tag ]  = 'all' , [ replace ] )

    Removes HTML tags and their contents from the string. tag may be an array of tags or 'all', in which case all tags will be removed. replace will replace what was removed, and may be a string or a function of type replaceFn to handle replacements. If this function returns a string, then it will be used for the replacement. If it returns undefined, the tags will be removed normally.

    • Callback: replaceFn

      tag The tag name.
      inner The tag content.
      attr The attributes on the tag, if any, as a string.
      outer The entire matched tag string.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '<p>just <b>some</b> text</p>'.removeTags()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '<p>just <b>some</b> text</p>'.removeTags('b')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '<p>hi!</p>'.removeTags('p', function(all, content) {
      return 'bye!';
    });

    Source

  • repeat ( [ num ]  = 0 )

    Returns the string repeated num times. This method is provided as a polyfill.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.repeat(2)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'a'.repeat(5)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'a'.repeat(0)

    Source

  • replaceAll ( f , [ str1 ] , [ str2 ] , [ ... )

    Replaces all occurences of f with arguments passed. This method is intended to be a quick way to perform multiple string replacements quickly when the replacement token differs depending on position. f can be either a case-sensitive string or a regex. In either case all matches will be replaced.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '-x -y -z'.replaceAll('-', 1, 2, 3)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'one and two'.replaceAll(/one|two/, '1st', '2nd')

    Source

  • reverse ( )

    Reverses the string.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'jumpy'.reverse()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'lucky charms'.reverse()

    Source

  • shift ( n )

    Shifts each character in the string n places in the character map.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'a'.shift(1)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'ク'.shift(1)

    Source

  • singularize ( )

    Returns the singular form of the last word in the string.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'posts'.singularize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'octopi'.singularize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'sheep'.singularize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'word'.singularize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'CamelOctopi'.singularize()

    Source

  • spacify ( )

    Converts camelcase, underscores, and hyphens to spaces.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'camelCase'.spacify()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'an-ugly-string'.spacify()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'oh-no_youDid-not'.spacify().capitalize(true)

    Source

  • startsWith ( search , [ pos ]  = 0 )

    Returns true if the string starts with substring search. Search begins at pos, which defaults to the entire string length. This method is provided as a polyfill.

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'hello'.startsWith('hell')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'hello'.startsWith('HELL')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'hello'.startsWith('ell', 1)

    Source

  • stripTags ( [ tag ]  = 'all' , [ replace ] )

    Strips HTML tags from the string. tag may be an array of tags or 'all', in which case all tags will be stripped. replace will replace what was stripped, and may be a string or a function of type replaceFn to handle replacements. If this function returns a string, then it will be used for the replacement. If it returns undefined, the tags will be stripped normally.

    • Callback: replaceFn

      tag The tag name.
      inner The tag content.
      attr The attributes on the tag, if any, as a string.
      outer The entire matched tag string.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '<p>just <b>some</b> text</p>'.stripTags()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '<p>just <b>some</b> text</p>'.stripTags('p')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '<p>hi!</p>'.stripTags('p', function(all, content) {
      return '|';
    });

    Source

  • titleize ( )

    Creates a title version of the string. Capitalizes all the words and replaces some characters in the string to create a nicer looking title. String#titleize is meant for creating pretty output.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'man from the boondocks'.titleize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'x-men: apocalypse'.titleize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'TheManWithoutAPast'.titleize()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'raiders_of_the_lost_ark'.titleize()

    Source

  • to ( [ index ]  = end )

    Returns a section of the string ending at index.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'lucky charms'.to()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'lucky charms'.to(7)

    Source

  • toNumber ( [ base ]  = 10 )

    Converts the string into a number. Any value with a "." fill be converted to a floating point value, otherwise an integer.

    Returns: Number

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '153'.toNumber()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '12,000'.toNumber()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '10px'.toNumber()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'ff'.toNumber(16)

    Source

  • trim ( )

    Removes leading and trailing whitespace from the string. Whitespace is defined as line breaks, tabs, and any character in the "Space, Separator" Unicode category, conforming to the the ES5 spec. This method is provided as a polyfill.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '   wasabi   '.trim()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '   wasabi   '.trimLeft()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '   wasabi   '.trimRight()

    Source

  • trimLeft ( )

    Removes leading whitespace from the string. Whitespace is defined as line breaks, tabs, and any character in the "Space, Separator" Unicode category, conforming to the the ES5 trim spec.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '   wasabi   '.trimLeft()

    Source

  • trimRight ( )

    Removes trailing whitespace from the string. Whitespace is defined as line breaks, tabs, and any character in the "Space, Separator" Unicode category, conforming to the the ES5 trim spec.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '   wasabi   '.trimRight()

    Source

  • truncate ( length , [ from ]  = 'right' , [ ellipsis ]  = '...' )

    Truncates a string. from can be 'right', 'left', or 'middle'. If the string is shorter than length, ellipsis will not be added.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'sittin on the dock'.truncate(10)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'sittin on the dock'.truncate(10, 'left')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'sittin on the dock'.truncate(10, 'middle')

    Source

  • truncateOnWord ( length , [ from ]  = 'right' , [ ellipsis ]  = '...' )

    Truncates a string without splitting up words. from can be 'right', 'left', or 'middle'. If the string is shorter than length, ellipsis will not be added. A "word" is defined as any sequence of non-whitespace characters.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'here we go'.truncateOnWord(5)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'here we go'.truncateOnWord(5, 'left')

    Source

  • underscore ( )

    Converts hyphens and camel casing to underscores.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'a-farewell-to-arms'.underscore()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'capsLock'.underscore()

    Source

  • unescapeHTML ( )

    Restores escaped HTML characters.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    '&lt;p&gt;some text&lt;/p&gt;'.unescapeHTML()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'one &amp; two'.unescapeHTML()

    Source

  • unescapeURL ( [ partial ]  = false )

    Restores escaped characters in a URL escaped string. If partial is true, it will only unescape non-valid URL tokens, and is included here for completeness, but should be rarely needed.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'http%3A%2F%2Ffoo.com%2F'.unescapeURL()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'http%3A%2F%2Ffoo.com%2F'.unescapeURL(true)

    Source

  • words ( [ eachWordFn ] )

    Runs eachWordFn against each word in the string, and returns an array. A "word" is defined as any sequence of non-whitespace characters.

    • Callback: eachWordFn

      word The current word.
      i The current index.
      arr An array of all words.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'broken wear'.words()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'broken wear'.words(function(w) {
      // Called twice: "broken", "wear"
    });

    Source

  • zenkaku ( [ mode ]  = 'all' )

    Converts half-width characters (hankaku) to full-width (zenkaku). mode accepts all, alphabet, numbers, katakana, spaces, punctuation, or any combination of a, n, k, s, or p, respectively.

    Returns: String

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'タロウ YAMADAです!'.zenkaku()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'タロウ YAMADAです!'.zenkaku('a')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'タロウ YAMADAです!'.zenkaku('alphabet')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'タロウです! 25歳です!'.zenkaku('katakana')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'タロウです! 25歳です!'.zenkaku('kn')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    'タロウです! 25歳です!'.zenkaku('sp')

    Source

  • addAcronym ( src )

    Adds a new acronym that will be recognized when inflecting strings. Acronyms are recognized by camelize, underscore, dasherize, titleize, humanize, and spacify. src must be passed as it will appear in a camelized string. Acronyms may contain lower case letters but must begin with an upper case letter. Note that to use acronyms in conjuction with pluralize, the pluralized form of the acronym must also be added.

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Sugar.String.addAcronym('HTML');

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Sugar.String.addAcronym('API');

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Sugar.String.addAcronym('APIs');

    Source

  • addHuman ( src , human )

    Adds a new humanization rule. Rules are used by humanize and titleize. str can be either a string or a regular expression, in which case human can contain refences to capturing groups.

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Sugar.String.addHuman('src', 'source');

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Sugar.String.addHuman(/_ref/, 'reference');

    Source

  • addPlural ( singular , [ plural ]  = singular )

    Adds a new pluralization rule. Rules are used by pluralize and singularize. If singular is a string, then the reciprocal will also be added for singularization. If it is a regular expression, capturing groups are allowed for plural. plural defaults to the same as singular to allow uncountable words.

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Sugar.String.addPlural('hashtag', 'hashtaggies');

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Sugar.String.addPlural(/(tag)$/, '$1gies');

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Sugar.String.addPlural('advice');

    Source

  • No saved methods