Class: String

String

The String reference type is a subclass of Object. A String can be created by any expression that evaluates to a string such as a string literal or template string. Strings are also created when a value is coerced into the String type such as using a non-numerical value as an Object key or adding any non-String value to a String. Characters within a String cannot be modified; a new String has to be created. Unlike JavaScript, Strings in Mildew are stored internally as UTF-8 and converted to UTF-32 for certain functions and when iterated.

Members

length

Get the length of a String

Methods

(static) fromCharCode(…var_args) → {String}

Creates a UTF-8 string from a sequence of integers between 0 and 255. If the first argument is an Array, creates a String from the Array elements.
Parameters:
Name Type Attributes Description
var_args integer <repeatable>
A sequence of valid UTF-8 code points
Returns:
A UTF-8 string if the arguments form a valid string, otherwise undefined
Type
String

(static) fromCodePoint(…var_args) → {String}

Creates a UTF-8 string from a UTF-32 string described by the values of the arguments. If the first argument is an Array, creates a String from the Array elements.
Parameters:
Name Type Attributes Description
var_args integer <repeatable>
A sequence of 32-bit unsigned integers representing unicode characters
Returns:
A UTF-8 string equivalent to the unicode string described by the parameters.
Type
String

charAt(index) → {String}

Gets a string representing the UTF-8 character at a given index. If the 8-bit character at the given index does not form a complete valid UTF character, an empty String is returned.
Parameters:
Name Type Description
index integer Index into the String
Returns:
A String containing a single character or undefined if index is out of range
Type
String

charCodeAt(index) → {integer}

Gets the unsigned 8-bit value of a character at the given index into the UTF-8 string.
Parameters:
Name Type Description
index integer Index into the String
Returns:
The numerical value of the character at the given index or undefined if index is out of range
Type
integer

codePointAt(index) → {integer}

Gets the value of a UTF-32 character value at a given index. This is done by iterating through each code point index number of times. If the index is out of range, returns undefined.
Parameters:
Name Type Description
index integer How many code points to iterate
Returns:
The value of the UTF-32 character.
Type
integer

concat(…var_args) → {String}

Concatenates this String to a list of Strings given and returns the new String
Parameters:
Name Type Attributes Description
var_args String <repeatable>
A list of Strings to concatenate to this String
Returns:
The concatenation of Strings
Type
String

endsWith(testString, sizeLimitopt) → {boolean}

Tests if the string or a substring ends with the characters specified by testString
Parameters:
Name Type Attributes Default Description
testString String String to test
sizeLimit integer <optional>
this.length The upper range of this String to test
Returns:
True if this String ends with testString else false
Type
boolean

includes(text) → {boolean}

Determines if this String contains a given character sequence
Parameters:
Name Type Description
text String The substring that might be contained in this String
Returns:
True if text is a substring of this String otherwise false
Type
boolean

indexOf(searchText) → {integer}

If this String contains another String, returns the index of where the other String is.
Parameters:
Name Type Description
searchText String substring to search in this String
Returns:
The index if the String is found, otherwise -1
Type
integer

lastIndexOf(searchText, startIndexopt) → {integer}

Searches this String for the given string starting at the last character going backwards.
Parameters:
Name Type Attributes Default Description
searchText String The string to search for in this String
startIndex integer <optional>
this.length The character position to start the reverse search.
Returns:
The index of the located string if found, else -1
Type
integer

match(regex) → {Array.<String>}

Returns the result of calling the RegExp parameter on this String
Parameters:
Name Type Description
regex RegExp A RegExp object
Returns:
The match result
Type
Array.<String>

matchAll(regex) → {Generator}

Returns an iterator that iterates over all matches of the given pattern against this String
Parameters:
Name Type Description
regex RegExp A regular expression. If this argment is a String, it will be converted to a regular expression whose source is the String.
Returns:
An iterator that iterates over each match. If any of the arguments are invalid, returns undefined instead.
Type
Generator

normalize(formatopt) → {String}

Normalize a String
Parameters:
Name Type Attributes Default Description
format String <optional>
"NFC" This can be blank or "NFC", "NFD", "NFKC", or "NFKD"
Returns:
The normalized form of the original String
Type
String

padEnd(totalLength, paddingopt) → {String}

Adds padding to the end of a string until its length is totalLength. Returns a new String
Parameters:
Name Type Attributes Default Description
totalLength integer The total length the resulting String should be
padding String <optional>
' ' The String to repeatedly add
Returns:
A padded String of length totalLength
Type
String

padStart(totalLength, paddingopt) → {String}

Adds padding to the start of a string until its length is totalLength. Returns a new String
Parameters:
Name Type Attributes Default Description
totalLength integer The total length of the resulting String
padding String <optional>
' ' The String to use as padding
Returns:
A padded String of length totalLength
Type
String

repeat(times) → {String}

Gets a String as the result of repeating this String a number of times
Parameters:
Name Type Description
times integer how many times to repeat the string
Returns:
The original String repeated a number of times
Type
String

replace(pattern, replacement) → {String}

Replace the first substring in a String and return the result of the replacement.
Parameters:
Name Type Description
pattern String | RegExp Either a substring representing what to replace, or a regular expression. If the 'g' flag was set on the regex, all occurences will be replaced.
replacement String | function The string to replace substrings with, or a function that takes the matching substring and returns a string value to replace the match with.
Returns:
A new String with the replaced substring.
Type
String

replaceAll(pattern, replacement) → {String}

Replaces all occurrences of a string in this String that matches the given pattern and returns the result.
Parameters:
Name Type Description
pattern String | RegExp A pattern string or a regular expression
replacement String | function The String to replace the substrings or a function that takes the substring and returns another string.
Returns:
A new String with the replaced substrings.
Type
String
Searches this String for a given RegExp pattern.
Parameters:
Name Type Description
regex RegExp A regular expression. If this argument is a String it will be converted to a regular expression.
Returns:
The index at which the patter was found, or -1 if not found.
Type
integer

slice(startopt, endopt) → {String}

Returns a substring between start and end-1 inclusive.
Parameters:
Name Type Attributes Default Description
start integer <optional>
0 The starting index
end integer <optional>
this.length The ending index
Returns:
A substring described by the parameters if it forms a valid UTF-8 string otherwise undefined
Type
String

split(splitteropt) → {Array.<String>}

Splits a String into an Array of Strings based on the given delimiter
Parameters:
Name Type Attributes Default Description
splitter String <optional>
"," The delimiter to separate Strings
Returns:
An array of at least one element containing Strings
Type
Array.<String>

startsWith(substring, startIndexopt) → {boolean}

Determines if this String starts with a given substring and starts searching from the beginning at the given index.
Parameters:
Name Type Attributes Default Description
substring String substring to search for
startIndex integer <optional>
0 Where in this String to start searching
Returns:
True if this String starts with substring, otherwise false.
Type
boolean

substring(startIndex, endIndex) → {String}

Returns a slice of this String as converted to a UTF-32 string. The index values must be within range of the 32-bit form of the string.
Parameters:
Name Type Description
startIndex integer the index to start the slice
endIndex integer the index to end the slice. Defaults to the length of the UTF-32 string
Returns:
A valid UTF-8 string within the range described by the indices.
Type
String

toLowerCase() → {String}

Returns an all lower-case form of this String
Returns:
The lower-case form of this String
Type
String

toUpperCase() → {String}

Returns an all upper-case form of this String
Returns:
The upper-case form of this String
Type
String