mediawiki.String

Module providing string utility functions.

Methods

byteLength(str) → {number}static #

Calculate the byte length of a string (accounting for UTF-8).

Parameters:

Name Type Description
str string
Author:
  • Jan Paul Posma, 2011
  • Timo Tijhof, 2012
  • David Chan, 2013
Source:

Returns:

Type
number
Calculate the byte length of a string (accounting for UTF-8).

charAt(string, offset, backwards) → {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

Like String.charAt(), but return the pair of UTF-16 surrogates for characters outside of BMP.

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
Calculate the character length of a string (accounting for UTF-16 surrogates).

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
Lowercase the first character.

trimByteLength(safeVal, newVal, byteLimit, filterFunction) → {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, filterFunction) → {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
Uppercase the first character.

Type Definitions

StringTrimmed #

Type:

Properties:

Name Type Description
newVal string

a trimmed version of the string

trimmed boolean

whether the string is different from the original version.

Source: