Module providing string utility functions.
- Source:
Methods
byteLength(str) → {number}static
#
Calculate the byte length of a string (accounting for UTF-8).
Parameters:
Name | Type | Description |
---|---|---|
str |
string |
- Source:
Returns:
- Type
- number
charAt(string, offset, backwardsopt) → {string}static
#
Like String#charAt, but return the pair of UTF-16 surrogates for characters outside of BMP.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
string |
string | ||
offset |
number | Offset to extract the character |
|
backwards |
boolean |
<optional> |
Use backwards direction to detect UTF-16 surrogates, defaults to false |
- Source:
Returns:
- Type
- string
codePointLength(str) → {number}static
#
Calculate the character length of a string (accounting for UTF-16 surrogates).
Parameters:
Name | Type | Description |
---|---|---|
str |
string |
- Source:
Returns:
- Type
- number
lcFirst(string) → {string}static
#
Lowercase the first character. Support UTF-16 surrogates for characters outside of BMP.
Parameters:
Name | Type | Description |
---|---|---|
string |
string |
- Source:
Returns:
- Type
- string
trimByteLength(safeVal, newVal, byteLimit, filterFunctionopt) → {StringTrimmed}static
#
Utility function to trim down a string, based on byteLimit and given a safe start position. It supports insertion anywhere in the string, so "foo" to "fobaro" if limit is 4 will result in "fobo", not "foba". Basically emulating the native maxlength by reconstructing where the insertion occurred.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
safeVal |
string | Known value that was previously returned by this function, if none, pass empty string. |
|
newVal |
string | New value that may have to be trimmed down. |
|
byteLimit |
number | Number of bytes the value may be in size. |
|
filterFunction |
function |
<optional> |
Function to call on the string before assessing the length. |
- Source:
Returns:
- Type
- StringTrimmed
Utility function to trim down a string, based on byteLimit and given a safe start position.
trimCodePointLength(safeVal, newVal, codePointLimit, filterFunctionopt) → {StringTrimmed}static
#
Utility function to trim down a string, based on codePointLimit and given a safe start position. It supports insertion anywhere in the string, so "foo" to "fobaro" if limit is 4 will result in "fobo", not "foba". Basically emulating the native maxlength by reconstructing where the insertion occurred.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
safeVal |
string | Known value that was previously returned by this function, if none, pass empty string. |
|
newVal |
string | New value that may have to be trimmed down. |
|
codePointLimit |
number | Number of characters the value may be in size. |
|
filterFunction |
function |
<optional> |
Function to call on the string before assessing the length. |
- Source:
Returns:
- Type
- StringTrimmed
Utility function to trim down a string, based on codePointLimit and given a safe start position.
ucFirst(string) → {string}static
#
Uppercase the first character. Support UTF-16 surrogates for characters outside of BMP.
Parameters:
Name | Type | Description |
---|---|---|
string |
string |
- Source:
Returns:
- Type
- string
Type Definitions
StringTrimmed
#
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
newVal |
string | a trimmed version of the string |
trimmed |
boolean | whether the string is different from the original version. |
- Source: