string.trimStart()
removes whitespace from the beginning of a string
trimStart()
method is defined on every string (on the prototype)
GIVEN a string starting with one space
- WHEN the string is only a space THEN
trimStart
leave an empty string - WHEN followed by a word THEN just the word will be left
- WHEN followed by a word and then spaces THEN the word and the spaces after will be left
- WHEN trimming a right-to-left (RTL) string THEN spaces are still trimmed from the left side
- WHEN trimming a russian (cyrillic) string THEN gets trimmed on the left too
- WHEN followed by a UTF string THEN it also removes the leading space
GIVEN a string starting with any number of spaces
- WHEN starting without a space THEN
trimStart()
will leave the string as is - WHEN starting with many spaces THEN those will be trimmed only at the start (left for a left-to-right language)
- WHEN trimming a RTL string THEN it spaces are removed from the left, ignoring the string direction
- WHEN a string starts with spaces and line breaks THEN those are removed too
additional knowledge
- WHEN
trimStart()
is called THEN the original string stays untouched - trimLeft and trimStart are the same function
Links
Description of `String.prototype.trimStart()` on MDN.
The specification describing `String.prototype.trimStart()`.
The official tests for JavaScript (engines) for `trimStart`.