Interface String

Index

Methods

Methods

public add(str: string, index?: number): string

Adds at [index].
Negative values are also allowed.

extra

%insert% is provided as an alias, and is generally more readable when using an index.

example

'schfifty'.add(' five') -> schfifty five 'dopamine'.insert('e', 3) -> dopeamine 'spelling eror'.insert('r', -3) -> spelling error

Parameters

  • str: string

    String to add.

  • index?: number optional

    Index where is added. Default = str.length

Returns

string

Original string with added at [index].

public assign(objs?: Array<any>): string

Assigns variables to tokens in a string.

extra

If an object is passed, it's properties can be assigned using the object's keys. If a non-object (string, number, etc.) is passed it can be accessed by the argument number beginning with 1 (as with regex tokens). Multiple objects can be passed and will be merged together (original objects are unaffected).

example

'Welcome, Mr. {name}.'.assign({ name: 'Franklin' }) -> 'Welcome, Mr. Franklin.' 'You are {1} years old today.'.assign(14) -> 'You are 14 years old today.' '{n} and {r}'.assign({ n: 'Cheech' }, { r: 'Chong' }) -> 'Cheech and Chong'

Parameters

  • objs?: Array<any> optional

    Variable tokens to assign in the string.

Returns

string

String with assigned to variables in the original string.

public at(index: number, loop?: boolean): string

Gets the character(s) at a given index.

extra

When [loop] is true, overshooting the end of the string (or the beginning) will begin counting from the other end. As an alternate syntax, passing multiple indexes will get the characters at those indexes.

example

'jumpy'.at(0) -> 'j' 'jumpy'.at(2) -> 'm' 'jumpy'.at(5) -> 'j' 'jumpy'.at(5, false) -> '' 'jumpy'.at(-1) -> 'y' 'lucky charms'.at(2,4,6,8) -> ['u','k','y',c']

Parameters

  • index: number

    Indicies of the character(s) requested.

  • loop?: boolean optional

    Loop around the string or stop at the end, default = true.

Returns

string

Character(s) at the specified indices.

public at(indicies?: Array<number>): Array<string>

see

at

limitation

Typescript does not allow for arguments after a variable argument list.

Parameters

  • indicies?: Array<number> optional

Returns

Array<string>

public camelize(first?: boolean): string

Converts underscores and hyphens to camel case.

extra

If the Inflections package is included acryonyms can also be defined that will be used when camelizing.

example

'caps_lock'.camelize() -> 'CapsLock' 'moz-border-radius'.camelize() -> 'MozBorderRadius' 'moz-border-radius'.camelize(false) -> 'mozBorderRadius'

Parameters

  • first?: boolean optional

    If [first] is true the first letter will also be capitalized, default = true

Returns

string

Camel case version of the string.

public capitalize(all?: boolean): string

Capitalizes the first character in the string.

method

capitalize([all] = false)

extra

If [all] is true, all words in the string will be capitalized.

example

'hello'.capitalize() -> 'Hello' 'hello kitty'.capitalize() -> 'Hello kitty' 'hello kitty'.capitalize(true) -> 'Hello Kitty'

Parameters

  • all?: boolean optional

    Default = false

Returns

string

String

public chars(fn?: (c: string) => void): Array<string>

Runs callback [fn] against each character in the string. Returns an array of characters.

example

'jumpy'.chars() -> ['j','u','m','p','y'] 'jumpy'.chars(function(c) { // Called 5 times: "j","u","m","p","y" });

Parameters

  • fn?: (c: string) => void optional

    Callback function for each character in the string.

Returns

Array<string>

string[] with each element containing one character in the string.

public codes(fn?: (c: string) => void): Array<number>

Runs callback [fn] against each character code in the string. Returns an array of character codes.

example

'jumpy'.codes() -> [106,117,109,112,121] 'jumpy'.codes(function(c) { // Called 5 times: 106, 117, 109, 112, 121 });

Parameters

  • fn?: (c: string) => void optional

    Callback function for each character code in the string.

Returns

Array<number>

number[] with each element containing one character code in the string.

public compact(): string

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

example

'too \n much \n space'.compact() -> 'too much space' 'enough \n '.compact() -> 'enough'

Returns

string

String with all whitespace compated to a single space.

public dasherize(): string

Converts underscores and camel casing to hypens.

example

'a_farewell_to_arms'.dasherize() -> 'a-farewell-to-arms' 'capsLock'.dasherize() -> 'caps-lock'

Returns

string

String with underscores and camel casing changed to hypens.

public decodeBase64(): string

Decodes the string from base64 encoding.

extra

This method wraps the browser native %atob% when available, and uses a custom implementation when not available.

example

'aHR0cDovL3R3aXR0ZXIuY29tLw=='.decodeBase64() -> 'http://twitter.com/' 'anVzdCBnb3QgZGVjb2RlZA=='.decodeBase64() -> 'just got decoded!'

Returns

string

Decoded base64 string.

public each(search: string, fn?: (m: string) => void): Array<string>

Runs callback [fn] against each occurence of [search].

extra

Returns an array of matches. [search] may be either a string or regex, and defaults to every character in the string.

example

'jumpy'.each() -> ['j','u','m','p','y'] 'jumpy'.each(/[r-z]/) -> ['u','y'] 'jumpy'.each(/[r-z]/, function(m) { // Called twice: "u", "y" });

Parameters

  • search: string

    Search item to look for in the string.

  • fn?: (m: string) => void optional

    Callback function for each occurance of [search]. If [search] is not provided each character is matched.

Returns

Array<string>

string[] of each item matched in the string.

public each(search: RegExp, fn?: (m: string) => void): Array<string>

see

each

Parameters

  • search: RegExp
  • fn?: (m: string) => void optional

Returns

Array<string>

public each(fn?: (m: string) => void): Array<string>

see

each

Parameters

  • fn?: (m: string) => void optional

Returns

Array<string>

public encodeBase64(): string

Encodes the string into base64 encoding.

extra

This method wraps the browser native %btoa% when available, and uses a custom implementation when not available.

example

'gonna get encoded!'.encodeBase64() -> 'Z29ubmEgZ2V0IGVuY29kZWQh' 'http://twitter.com/'.encodeBase64() -> 'aHR0cDovL3R3aXR0ZXIuY29tLw=='

Returns

string

Base64 encoded string.

public endsWith(find: string, pos?: number, case_?: boolean): boolean

Returns true if the string ends with .

example

'jumpy'.endsWith('py') -> true 'jumpy'.endsWith(/[q-z]/) -> true 'jumpy'.endsWith('MPY') -> false 'jumpy'.endsWith('MPY', false) -> true

Parameters

  • find: string

    String or RegExp to find at the end of the string.

  • pos?: number optional

    Ending position to search for, defaults to the end of the string.

  • case_?: boolean optional

    True for case sensitive, default = true.

Returns

boolean

True if the string ends with .

public endsWith(find: string, case_?: boolean): boolean

see

endsWith

Parameters

  • find: string
  • case_?: boolean optional

Returns

boolean

public endsWith(find: RegExp, pos?: number, case_?: boolean): boolean

see

endsWith

Parameters

  • find: RegExp
  • pos?: number optional
  • case_?: boolean optional

Returns

boolean

public endsWith(find: RegExp, case_?: boolean): boolean

see

endsWith

Parameters

  • find: RegExp
  • case_?: boolean optional

Returns

boolean

public escapeHTML(): string

Converts HTML characters to their entity equivalents.

example

'

some text

'.escapeHTML() -> '<p>some text</p>' 'one & two'.escapeHTML() -> 'one & two'

Returns

string

HTML escaped string.

public escapeRegExp(): string

Escapes all RegExp tokens in the string.

example

'really?'.escapeRegExp() -> 'really\?' 'yes.'.escapeRegExp() -> 'yes.' '(not really)'.escapeRegExp() -> '(not really)'

Returns

string

RegExp escaped string.

public escapeURL(param?: boolean): string

Escapes characters in a string to make a valid URL.

extra

If [param] is true, it will also escape valid URL characters for use as a URL parameter.

example

'http://foo.com/"bar"'.escapeURL() -> 'http://foo.com/%22bar%22' 'http://foo.com/"bar"'.escapeURL(true) -> 'http%3A%2F%2Ffoo.com%2F%22bar%22'

Parameters

  • param?: boolean optional

Returns

string

URL escaped string.

public first(n?: number): string

Returns the first [n] characters of the string.

example

'lucky charms'.first() -> 'l' 'lucky charms'.first(3) -> 'luc'

Parameters

  • n?: number optional

Returns

string

String

public from(index?: number): string

Returns a section of the string starting from [index].

example

'lucky charms'.from() -> 'lucky charms' 'lucky charms'.from(7) -> 'harms'

Parameters

  • index?: number optional

Returns

string

String

public hankaku(mode?: string): string

Converts full-width characters (zenkaku) to half-width (hankaku).

extra

[mode] accepts any combination of "a" (alphabet), "n" (numbers), "k" (katakana), "s" (spaces), "p" (punctuation), or "all".

example

'??? YAMADA??!'.hankaku() -> '??? YAMADA??!' '??? YAMADA??!'.hankaku('a') -> '??? YAMADA??!' '??? YAMADA??!'.hankaku('alphabet') -> '??? YAMADA??!' '?????! 25???!'.hankaku('katakana', 'numbers') -> '?????! 25???!' '?????! 25???!'.hankaku('k', 'n') -> '?????! 25???!' '?????! 25???!'.hankaku('kn') -> '?????! 25???!' '?????! 25???!'.hankaku('sp') -> '?????! 25???!'

Parameters

  • mode?: string optional

    default = 'all'

Returns

string

Converted string to hankaku.

public hankaku(modes?: Array<string>): string

see

hankaku

Parameters

  • modes?: Array<string> optional

Returns

string

public has(find: string): boolean

Returns true if the string matches .

example

'jumpy'.has('py') -> true 'broken'.has(/[a-n]/) -> true 'broken'.has(/[s-z]/) -> false

Parameters

  • find: string

    Search parameters.

Returns

boolean

True if the string matchs , otherwise false.

public has(find: RegExp): boolean

see

has

Parameters

  • find: RegExp

Returns

boolean

public hasArabic(): boolean

Returns true if the string contains any characters in Arabic.

example

'?????'.hasArabic() -> true '?????'.hasCyrillic() -> true '? ?????!'.hasHangul() -> true '??????'.hasKatakana() -> true "l'année".hasLatin() -> true

Returns

boolean

True if the string contains Arabic.

public hasCyrillic(): boolean

Returns true if the string contains any characters in Cyrillic.

Returns

boolean

True if the string contains Cyrillic.

public hasDevanagari(): boolean

Returns true if the string contains any characters in Devanagari.

Returns

boolean

True if the string contains Devanagari.

public hasGreek(): boolean

Returns true if the string contains any characters in Greek.

Returns

boolean

True if the string contains Greek.

public hasHan(): boolean

Returns true if the string contains any characters in Han.

Returns

boolean

True if the string contains Han.

public hasHangul(): boolean

Returns true if the string contains any characters in Hangul.

Returns

boolean

True if the string contains Hangul.

public hasHebrew(): boolean

Returns true if the string contains any characters in Hebrew.

Returns

boolean

True if the string contains Hebrew.

public hasHiragana(): boolean

Returns true if the string contains any characters in Hiragana.

Returns

boolean

True if the string contains Hiragana.

public hasKana(): boolean

Returns true if the string contains any characters in Kana.

Returns

boolean

True if the string contains Kana.

public hasKanji(): boolean

Returns true if the string contains any characters in Kanji.

Returns

boolean

True if the string contains Kanji.

public hasKatakana(): boolean

Returns true if the string contains any characters in Katakana.

Returns

boolean

True if the string contains Katakana.

public hasLatin(): boolean

Returns true if the string contains any characters in Latin.

Returns

boolean

True if the string contains Latin.

public hasThai(): boolean

Returns true if the string contains any characters in Thai.

Returns

boolean

True if the string contains Thai.

public hiragana(all?: boolean): string

Converts katakana into hiragana.

example

'????'.hiragana() -> '????' '?????'.hiragana() -> '?????' '????'.hiragana() -> '????' '????'.hiragana(false) -> '????'

Parameters

  • all?: boolean optional

    If [all] is false, only full-width katakana will be converted, default = true.

Returns

string

Converted string to hiragana.

public humanize(): string

Creates a human readable string.

extra

Capitalizes the first word and turns underscores into spaces and strips a trailing '_id', if any. Like String#titleize, this is meant for creating pretty output.

example

'employee_salary'.humanize() -> 'Employee salary' 'author_id'.humanize() -> 'Author'

Returns

string

Pretty printed version of the string.

public insert(str: string, index?: number): string

see

add

Parameters

  • str: string
  • index?: number optional

Returns

string

public isArabic(): boolean

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

example

'?????'.isArabic() -> true '?????'.isCyrillic() -> true '? ?????!'.isHangul() -> true '??????'.isKatakana() -> false "l'année".isLatin() -> true

Returns

boolean

True if the string containsly only characters in Arabic.

public isBlank(): boolean

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

example

''.isBlank() -> true ' '.isBlank() -> true 'noway'.isBlank() -> false

Returns

boolean

True if the string has a length of 0 or contains only whitespace.

public isCyrillic(): boolean

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

Returns

boolean

True if the string containsly only characters in Cyrillic.

public isDevanagari(): boolean

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

Returns

boolean

True if the string containsly only characters in Devanagari.

public isGreek(): boolean

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

Returns

boolean

True if the string containsly only characters in Greek.

public isHan(): boolean

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

Returns

boolean

True if the string containsly only characters in Han.

public isHangul(): boolean

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

Returns

boolean

True if the string containsly only characters in Hangul.

public isHebrew(): boolean

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

Returns

boolean

True if the string containsly only characters in Hebrew.

public isHiragana(): boolean

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

Returns

boolean

True if the string containsly only characters in Hiragana.

public isKana(): boolean

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

Returns

boolean

True if the string containsly only characters in Kana.

public isKanji(): boolean

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

Returns

boolean

True if the string containsly only characters in Kanji.

public isKatakana(): boolean

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

Returns

boolean

True if the string containsly only characters in Katakana.

public isLatin(): boolean

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

Returns

boolean

True if the string containsly only characters in Latin.

public isThai(): boolean

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

Returns

boolean

True if the string containsly only characters in Thai.

public katakana(): string

Converts hiragana into katakana.

example

'????'.katakana() -> '????' '?????'.katakana() -> '?????'

Returns

string

Converted string to katakana.

public last(n?: number): string

Returns the last [n] characters of the string.

example

'lucky charms'.last() -> 's' 'lucky charms'.last(3) -> 'rms'

Parameters

  • n?: number optional

Returns

string

The last [n] characters of the string.

public lines(fn?: (l: string) => void): Array<string>

Runs callback [fn] against each line in the string.

example

'broken wear\nand\njumpy jump'.lines() -> ['broken wear','and','jumpy jump'] 'broken wear\nand\njumpy jump'.lines(function(l) { // Called three times: "broken wear", "and", "jumpy jump" });

Parameters

  • fn?: (l: string) => void optional

    Callback against each line in the original string.

Returns

Array<string>

A string[] where each element is a line in the original string.

public normalize(): string

Returns the string with accented and non-standard Latin-based characters converted into ASCII approximate equivalents.

example

'á'.normalize() -> 'a' 'Ménage à trois'.normalize() -> 'Menage a trois' 'Volkswagen'.normalize() -> 'Volkswagen' 'FULLWIDTH'.normalize() -> 'FULLWIDTH'

Returns

string

String

public pad(padding: string, num?: number): string

Pads either/both sides of the string.

extra

[num] is the number of characters on each side, and [padding] is the character to pad with.

example

'wasabi'.pad('-') -> '-wasabi-' 'wasabi'.pad('-', 2) -> '--wasabi--' 'wasabi'.padLeft('-', 2) -> '--wasabi' 'wasabi'.padRight('-', 2) -> 'wasabi--'

Parameters

  • padding: string

    The padding characters to add to the string.

  • num?: number optional

    The number of to add to the string, default = 1.

Returns

string

String

public padLeft(padding: string, num?: number): string

see

pad

Parameters

  • padding: string
  • num?: number optional

Returns

string

public padRight(padding: string, num?: number): string

see

pad

Parameters

  • padding: string
  • num?: number optional

Returns

string

public paragraphs(fn?: (p: string) => void): Array<string>

Runs callback [fn] against each paragraph in the string.

extra

A paragraph here is defined as a block of text bounded by two or more line breaks.

example

'Once upon a time.\n\nIn the land of oz...'.paragraphs() -> ['Once upon a time.','In the land of oz...'] 'Once upon a time.\n\nIn the land of oz...'.paragraphs(function(p) { // Called twice: "Once upon a time.", "In teh land of oz..." });

Parameters

  • fn?: (p: string) => void optional

    Callback function called for each paragraph in the string.

Returns

Array<string>

Returns a string[] where each element is a paragraph in the original string.

public parameterize(): string

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

example

'hell, no!'.parameterize() -> 'hell-no'

Returns

string

URL parameterizes the string.

public pluralize(): string

Returns the plural form of the word in the string.

method

pluralize()

example

'post'.pluralize() -> 'posts' 'octopus'.pluralize() -> 'octopi' 'sheep'.pluralize() -> 'sheep' 'words'.pluralize() -> 'words' 'CamelOctopus'.pluralize() -> 'CamelOctopi'

Returns

string

String

public remove(find: string): string

Removes any part of the string that matches .

extra

can be a string or a regex.

example

'schfifty five'.remove('f') -> 'schity ive' 'schfifty five'.remove(/[a-f]/g) -> 'shity iv'

Parameters

  • find: string

    Remove this from the string.

Returns

string

String with all instances of removed.

public remove(find: RegExp): string

see

remove

Parameters

  • find: RegExp

Returns

string

public removeTags(tags?: Array<string>): string

Removes all HTML tags and their contents from the string

extra

Tags to remove may be enumerated in the parameters, otherwise will remove all.

example

'

just some text

'.removeTags() -> '' '

just some text

'.removeTags('b') -> '

just text

'

Parameters

  • tags?: Array<string> optional

    Remove these HTML tags.

Returns

string

String with HTML tags removed.

public repeat(num?: number): string

Returns the string repeated [num] times.

example

'jumpy'.repeat(2) -> 'jumpyjumpy' 'a'.repeat(5) -> 'aaaaa' 'a'.repeat(0) -> ''

Parameters

  • num?: number optional

    Number of times to repeat the string, default = 0.

Returns

string

Repeated [num] string.

public reverse(): string

Reverses the string.

example

'jumpy'.reverse() -> 'ypmuj' 'lucky charms'.reverse() -> 'smrahc ykcul'

Returns

string

Reversed string.

public shift(num: number): Array<string>

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

example

'a'.shift(1) -> 'b' '?'.shift(1) -> '?'

Parameters

  • num: number

    Number of characters to shift in the character map.

Returns

Array<string>

String with characters shifted .

public singularize(): string

The reverse of String#pluralize.

example

'posts'.singularize() -> 'post' 'octopi'.singularize() -> 'octopus' 'sheep'.singularize() -> 'sheep' 'word'.singularize() -> 'word' 'CamelOctopi'.singularize() -> 'CamelOctopus'

Returns

string

Returns the singular form of a word in a string.

public spacify(): string

Converts camel case, underscores, and hyphens to a properly spaced string.

example

'camelCase'.spacify() -> 'camel case' 'an-ugly-string'.spacify() -> 'an ugly string' 'oh-no_youDid-not'.spacify().capitalize(true) -> 'something else'

Returns

string

String

public startsWith(find: string, pos?: number, case_?: boolean): boolean

Returns true if the string starts with .

example

'hello'.startsWith('hell') -> true 'hello'.startsWith(/[a-h]/) -> true 'hello'.startsWith('HELL') -> false 'hello'.startsWith('HELL', false) -> true

Parameters

  • find: string

    String or RegExp to look for at the beginning of the string.

  • pos?: number optional

    Starting position to start searching, default = 0.

  • case_?: boolean optional

    True for case sensitive, default = true.

Returns

boolean

True if the string starts with find.

public startsWith(find: string, case_?: boolean): boolean

see

startsWith

Parameters

  • find: string
  • case_?: boolean optional

Returns

boolean

public startsWith(find: RegExp, pos?: number, case_?: boolean): boolean

see

startsWith

Parameters

  • find: RegExp
  • pos?: number optional
  • case_?: boolean optional

Returns

boolean

public startsWith(find: RegExp, case_?: boolean): boolean

see

startsWith

Parameters

  • find: RegExp
  • case_?: boolean optional

Returns

boolean

public stripTags(tags?: Array<string>): string

Strips all HTML tags from the string.

extra

Tags to strip may be enumerated in the parameters, otherwise will strip all.

example

'

just some text

'.stripTags() -> 'just some text' '

just some text

'.stripTags('p') -> 'just some text'

Parameters

  • tags?: Array<string> optional

    HTML tags to strip from the string.

Returns

string

Returns the string with all HTML removed.

public titleize(): string

Creates a title version of the string.

extra

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.

example

'man from the boondocks'.titleize() -> 'Man from the Boondocks' 'x-men: the last stand'.titleize() -> 'X Men: The Last Stand' 'TheManWithoutAPast'.titleize() -> 'The Man Without a Past' 'raiders_of_the_lost_ark'.titleize() -> 'Raiders of the Lost Ark'

Returns

string

Returns a titlized version of the string.

public to(index?: number): string

Returns a section of the string ending at [index].

example

'lucky charms'.to() -> 'lucky charms' 'lucky charms'.to(7) -> 'lucky ch'

Parameters

  • index?: number optional

    Ending position in the substring, default = string.length.

Returns

string

Substring ending at [index].

public toNumber(base?: number): number

Converts the string into a number in base [base].

extra

Any value with a "." fill be converted to a floating point value, otherwise an integer.

example

'153'.toNumber() -> 153 '12,000'.toNumber() -> 12000 '10px'.toNumber() -> 10 'ff'.toNumber(16) -> 255

Parameters

  • base?: number optional

    The base to parse the number in, default = 10.

Returns

number

Parsed number.

public trimLeft(): string

Removes leading whitespace from the string.

see

trim

Returns

string

Returns a string with leading whitespace removed.

public trimRight(): string

Removes trailing whitespace from the string.

see

trim

Returns

string

Returns a string with trailing whitespace removed.

public truncate(length: number, split?: boolean, from?: string, ellipsis?: string): string

Truncates a string.

extra

If [split] is %false%, will not split words up, and instead discard the word where the truncation occurred. [from] can also be %"middle"% or %"left"%.

example

'just sittin on the dock of the bay'.truncate(20) -> 'just sittin on the do...' 'just sittin on the dock of the bay'.truncate(20, false) -> 'just sittin on the...' 'just sittin on the dock of the bay'.truncate(20, true, 'middle') -> 'just sitt...of the bay' 'just sittin on the dock of the bay'.truncate(20, true, 'left') -> '...the dock of the bay'

Parameters

  • length: number

    The length to keep in the string before truncating.

  • split?: boolean optional

    True to split words, false keeps them intact but may truncate earlier.

  • from?: string optional

    Where to truncate the string from, default = 'right'.

  • ellipsis?: string optional

    Character to use as ellipsis.

Returns

string

Truncated string.

public underscore(): string

Converts hyphens and camel casing to underscores.

example

'a-farewell-to-arms'.underscore() -> 'a_farewell_to_arms' 'capsLock'.underscore() -> 'caps_lock'

note

Not to be confused with the populate underscore.js library.

Returns

string

Returns a converted string.

public unescapeHTML(): string

Restores escaped HTML characters.

example

'<p>some text</p>'.unescapeHTML() -> '

some text

' 'one & two'.unescapeHTML() -> 'one & two'

Returns

string

Returns unescaped HTML string.

public unescapeURL(partial?: boolean): string

Restores escaped characters in a URL escaped string.

extra

If [partial] is true, it will only unescape non-valid URL characters. [partial] is included here for completeness, but should very rarely be needed.

example

'http%3A%2F%2Ffoo.com%2Fthe%20bar'.unescapeURL() -> 'http://foo.com/the bar' 'http%3A%2F%2Ffoo.com%2Fthe%20bar'.unescapeURL(true) -> 'http%3A%2F%2Ffoo.com%2Fthe bar'

Parameters

  • partial?: boolean optional

    If true only escape non-valid URL characters, default = false.

Returns

string

String

public words(fn?: (word: string) => void): Array<string>

Runs callback [fn] against each word in the string.

extra

A "word" here is defined as any sequence of non-whitespace characters.

example

'broken wear'.words() -> ['broken','wear'] 'broken wear'.words(function(w) { // Called twice: "broken", "wear" });

Parameters

  • fn?: (word: string) => void optional

    Callback to run against each word in the string.

Returns

Array<string>

Returns an string[] with each element containing a word.

public zenkaku(modes?: Array<string>): string

Converts half-width characters (hankaku) to full-width (zenkaku).

extra

[mode] accepts any combination of "a" (alphabet), "n" (numbers), "k" (katakana), "s" (spaces), "p" (punctuation), or "all".

example

'??? YAMADA??!'.zenkaku() -> '??? YAMADA??!' '??? YAMADA??!'.zenkaku('a') -> '??? YAMADA??!' '??? YAMADA??!'.zenkaku('alphabet') -> '??? YAMADA??!' '?????! 25???!'.zenkaku('katakana', 'numbers') -> '?????! 25???!' '?????! 25???!'.zenkaku('k', 'n') -> '?????! 25???!' '?????! 25???!'.zenkaku('kn') -> '?????! 25???!' '?????! 25???!'.zenkaku('sp') -> '?????! 25???!'

Parameters

  • modes?: Array<string> optional

    Types of characters to convert, default = 'all'.

Returns

string

String