JsString

com.raquo.ew.JsString
See theJsString companion object
trait JsString extends JsIterable[String]

JS-native operations on strings. Alternative to JSStringOps from Scala.js

Attributes

Companion
object
Graph
Supertypes
trait JsIterable[String]
class Object
trait Any
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def `match`(regexp: RegExp): Array[String]

Alternatives:

  • If the g flag is used, all results matching the complete regular expression will be returned, but capturing groups will not.

  • if the g flag is not used, only the first complete match and its related capturing groups are returned. In this case, the returned item will have additional properties as described in the docs.

Alternatives:

  • If you only want the first match found, you might want to use myJsRegExp.exec(str)

  • If you need to know if a string matches a regular expression, use myJsRegExp.test(str)

Attributes

See also
def `match`(regexp: String): Array[String]
def asScalaJs: String
Implicitly added by RichJsString

Cast a JsString to scala.String. It's safe because they have the same runtime representation.

Cast a JsString to scala.String. It's safe because they have the same runtime representation.

Attributes

def charAt(index: Int): String

Returns a new string consisting of the single UTF-16 code unit located at index in the string.

Returns a new string consisting of the single UTF-16 code unit located at index in the string.

  • If index is out of range, returns an empty string.

Attributes

See also
def charCodeAt(index: Int): Double

Returns an integer between 0 and 65535 representing the UTF-16 code unit at the given index.

Returns an integer between 0 and 65535 representing the UTF-16 code unit at the given index.

  • If index is out of range, charCodeAt() returns NaN.

Attributes

See also
def charPointAt(pos: Int): UndefOr[Int]

Returns a non-negative integer that is the Unicode code point value at the given position in the string.

Returns a non-negative integer that is the Unicode code point value at the given position in the string.

  • If there is no element at pos, returns undefined.

  • If the element at pos is a UTF-16 high surrogate, returns the code point of the surrogate pair.

  • If the element at pos is a UTF-16 low surrogate, returns only the low surrogate code point.

!! Not supported by IE !!

Attributes

See also
def endsWith(searchString: String, length: Int): Boolean

Value parameters

length

If provided, it is used as the length of the string in which we're searching. Defaults to its real length. !! Not supported by IE !!

searchString

The characters to search for.

Attributes

See also
def indexOf(searchString: String, fromIndex: Int): Int

Returns the index of the first occurrence of the specified substring at an index greater than or equal to the specified number.

Returns the index of the first occurrence of the specified substring at an index greater than or equal to the specified number.

  • Returns -1 if not found.

Value parameters

fromIndex

The lowest index at which the found substring can begin, for it to be found. Defaults to 0.

Attributes

See also
def lastIndexOf(searchString: String, fromIndex: Int): Int

Returns the index of the last occurrence of the specified substring at an index less than or equal to the specified number.

Returns the index of the last occurrence of the specified substring at an index less than or equal to the specified number.

  • Returns -1 if not found.

Value parameters

fromIndex

The highest index at which the found substring can begin, for it to be found. Defaults to +Infinity

Attributes

See also
def length: Int

Return the length of the string, in UTF-16 code units.

Return the length of the string, in UTF-16 code units.

Attributes

See also
def localeCompare(compareString: String, locales: UndefOr[String | JsArray[String] | Array[String]], options: UndefOr[Object]): Int

Returns a number indicating whether a reference string comes before, or after, or is the same as the given string in sort order: negative number if referenceStr occurs before compareString; positive if the referenceStr occurs after compareString; 0 if they are equivalent.

Returns a number indicating whether a reference string comes before, or after, or is the same as the given string in sort order: negative number if referenceStr occurs before compareString; positive if the referenceStr occurs after compareString; 0 if they are equivalent.

locales and options customize the behavior of the function and let applications specify the language whose formatting conventions should be used.

!! Not supported by Android WebView !!

Attributes

See also
def normalize(form: String): JsString

Returns the Unicode Normalization Form of the string.

Returns the Unicode Normalization Form of the string.

!! Not supported by IE !!

Value parameters

form

One of "NFC", "NFD", "NFKC", or "NFKD", specifying the Unicode Normalization Form

Attributes

See also
def padEnd(targetLength: Int, padString: String): JsString

Pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the end of the current string.

Pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the end of the current string.

!! Not supported by IE !!

Attributes

See also
def padStart(targetLength: Int, padString: String): JsString

Pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the start of the current string.

Pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the start of the current string.

!! Not supported by IE !!

Attributes

See also
def repeat(count: Int): JsString

Returns a string that repeats the current string count times

Returns a string that repeats the current string count times

!! Not supported by IE !!

Attributes

See also
def replace(what: String | RegExp, replacement: String): JsString

Value parameters

replacement

Note: this is parsed for special patterns! See docs. !! If you don't want special patterns to be parsed out of replacement, use the version of this method with a replacer function. !!

what

Note: if String, only the first occurrence will be replaced. If RegExp, depends on the g flag.

Attributes

See also
def replace(what: String | RegExp, replacer: Function1[String, String]): JsString

Value parameters

replacer

Accepts the substring to be replaced, and returns what to replace it with. Note that JS can actually provide more data to this function, but we don't expose that. See docs.

what

Note: if String, only the first occurrence will be replaced. If RegExp, depends on the g flag.

Attributes

See also
def replaceAll(what: String | RegExp, replacement: String): JsString

Value parameters

replacement

Note: this is parsed for special patterns! See docs. !! If you don't want special patterns to be parsed out of replacement, use the version of this method with a replacer function. !! !! Not supported by IE, not supported by MobileSafari < 13.4 !!

what

If js.RegExp, must be global, or this will throw.

Attributes

See also
def replaceAll(what: String | RegExp, replacer: Function1[String, String]): JsString

Value parameters

replacer

Accepts the substring to be replaced, and returns what to replace it with. Note that JS can actually provide more data to this function, but we don't expose that. See docs. !! Not supported by IE !!

what

If js.RegExp, must be global, or this will throw.

Attributes

See also
def search(regexp: String | RegExp): Int

Returns the index of the first match between the regular expression and the given string, or -1 if no match was found.

Returns the index of the first match between the regular expression and the given string, or -1 if no match was found.

Attributes

See also
def slice(beginIndex: Int, endIndex: Int): JsString

Extracts the text from the string and returns it.

Extracts the text from the string and returns it.

If beginIndex is negative, slice() begins extraction from the end.

Value parameters

beginIndex

The zero-based index at which to begin extraction.

endIndex

The zero-based index before which to end extraction. The character at this index will not be included. If endIndex is omitted, the entire remainder of the string is extracted.

Attributes

See also
def split(separator: String | RegExp, limit: Int): JsArray[String]

If separator is does not occur in str, the returned array contains one element consisting of the entire string.

If separator is does not occur in str, the returned array contains one element consisting of the entire string.

If separator appears at the beginning (or end) of the string, it still has the effect of splitting. The result is an empty (i.e. zero length) string, which appears at the first (or last) position of the returned array.

If separator is an empty string (""), str is converted to an array of each of its UTF-16 "characters".

Value parameters

limit

Max number of substrings to be included in the array. Any leftover text is not included in the array at all. If limit is 0, [] is returned.

Attributes

See also
def startsWith(searchString: String, position: Int): Boolean

Value parameters

position

The position in the string at which to start searching. Defaults to 0. !! Not supported by IE !!

searchString

The characters to search for.

Attributes

See also
def str: String
Implicitly added by RichJsString
def substr(indexStart: Int, indexEnd: Int): JsString

Returns characters from indexStart up to but not including indexEnd.

Returns characters from indexStart up to but not including indexEnd.

If indexEnd is omitted, the entire remainder of the string is returned.

Attributes

See also
def toLocaleLowerCase(locales: String | JsArray[String] | Array[String]): JsString

Locale-aware lower-case

def toLocaleUpperCase(locales: String | JsArray[String] | Array[String]): JsString

Locale-aware upper-case

def trim(): JsString

Returns a new string with the whitespace from both ends of the original string removed. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).

Returns a new string with the whitespace from both ends of the original string removed. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).

Attributes

See also
def trimEnd(): JsString

Like trim(), but only trims the end of the string

Like trim(), but only trims the end of the string

!! Not supported by IE, not supported by MobileSafari < 12 !!

Attributes

See also

Like trim(), but only trims the start of the string

Like trim(), but only trims the start of the string

!! Not supported by IE, not supported by MobileSafari < 12 !!

Attributes

See also

Inherited methods

def hasOwnProperty(v: String): Boolean

Attributes

Inherited from:
Object
def isPrototypeOf(v: Object): Boolean

Attributes

Inherited from:
Object
def iterator(): Iterator[A]

!! Not supported by IE !!

!! Not supported by IE !!

Attributes

Inherited from:
JsIterable
def propertyIsEnumerable(v: String): Boolean

Attributes

Inherited from:
Object
def toLocaleString(): String

Attributes

Inherited from:
Object
def valueOf(): Any

Attributes

Inherited from:
Object

Concrete fields

val self: JsString
Implicitly added by RichJsString