string
Extended String API.
Summary
Static Properties
ASCII_LETTERS | All ASCII letters. |
ASCII_LOWERCASE | All lowercase letters. |
ASCII_UPPERCASE | All uppercase letters. |
Static Methods
format | Return a string with {n} replaced with the n-th argument. |
fromCodePoint | Get the string for a given code point or set of code points. |
getCodePoint | Get the code point number for a character in a string. |
getCodePoints | Gets an array of all code points in a string. |
getSymbols | Gets an array of all grapheme clusters (visible symbols) in a string. |
toBool | Convert a string value to a boolean. |
Details
Static Properties
ASCII_LETTERS | All ASCII letters. |
ASCII_LOWERCASE | All lowercase letters. |
ASCII_UPPERCASE | All uppercase letters. |
Static Methods
format(s, [arguments])
Return a string with {n} replaced with the n-th argument.
var s = pc.string.format("Hello {0}", "world");
console.log(s); // Prints "Hello world"
Parameters
s | string | The string to format. |
arguments | object | All other arguments are substituted into the string. |
Returns
stringThe formatted string.
fromCodePoint(args)
Get the string for a given code point or set of code points. Polyfill for
fromCodePoint
.
Parameters
args | number | The code points to convert to a string. |
Returns
stringThe converted string.
getCodePoint(string, [i])
Get the code point number for a character in a string. Polyfill for
codePointAt
.
Parameters
string | string | The string to get the code point from. |
i | number | The index in the string. |
Returns
numberThe code point value for the character in the string.
getCodePoints(string)
Gets an array of all code points in a string.
Parameters
string | string | The string to get code points from. |
Returns
number[]The code points in the string.
getSymbols(string)
Gets an array of all grapheme clusters (visible symbols) in a string. This is needed because some symbols (such as emoji or accented characters) are actually made up of multiple character codes. See here for more info.
Parameters
string | string | The string to break into symbols. |
Returns
string[]The symbols in the string.
toBool(s, [strict])
Convert a string value to a boolean. In non-strict mode (the default), 'true' is converted to true, all other values are converted to false. In strict mode, 'true' is converted to true, 'false' is converted to false, all other values will throw an Exception.
Parameters
s | string | The string to convert. |
strict | boolean | In strict mode an Exception is thrown if s is not an accepted string value. Defaults to false. |
Returns
booleanThe converted value.