Search e01
One query across the encyclopedia, books, dictionary, papers, Wikidata and the developer library. Every hit carries its source.
6 results across 6 corpora for String.prototype.toWellFormed().
Developer library 6
Firefox 119 release notes for developers
iterable are now supported (See [Firefox bug 1792650](https://bugzil.la/1792650) for more details.) - The String.prototype.isWellFormed() and String.prototype.toWellFormed() methods respectively can be used to check if a string contains well-formed Unicode text (i.e., contains no [lone surrogates](/docs/Web/JavaScript/Reference/Global_Objects/String#utf-16_characters_unicode_code_points_and_grapheme_clusters)) and s
String
th UTF-16 (such as `encodeURI()` or TextEncoder). You can check if a string is well-formed with the isWellFormed() method, or sanitize lone surrogates with the toWellFormed() method. On top of Unicode characters, there are certain sequences of Unicode characters that should be treated as one visual unit, known as a _grapheme cluster_. The most common case is emojis: many emojis that have a range of variations are ac
String.prototype.toWellFormed()
The **`toWellFormed()`** method of String values returns a string where all [lone surrogates](/docs/Web/JavaScript/Reference/Global_Objects/String#utf-16_characters_unicode_code_points_and_grapheme_clusters) of this string are replaced with the Unicode replacement character U+FFFD. ## Syntax ```js-nolint toWellFormed() ``` ### Parameters None. ### Return value A new string that is a copy of this string, with al
String.prototype.isWellFormed()
d()` is more efficient, as engines can directly access the internal representation of strings. If you need to convert a string to a well-formed string, use the toWellFormed() method. `isWellFormed()` allows you to handle ill-formed strings differently from well-formed strings, such as throwing an error or marking it as invalid. ## Examples ### Using isWellFormed() ```js const strings = [ // Lone leading surrogat
encodeURIComponent()
Component("\uD800"); // Lone low-surrogate code unit throws "URIError: malformed URI sequence" encodeURIComponent("\uDFFF"); ``` You can use String.prototype.toWellFormed(), which replaces lone surrogates with the Unicode replacement character (U+FFFD), to avoid this error. You can also use String.prototype.isWellFormed() to check if a string contains lone surrogates before passing it to `encodeURIComponent()`. ##
encodeURI()
equence" encodeURI("\uD800"); // Lone low-surrogate code unit throws "URIError: malformed URI sequence" encodeURI("\uDFFF"); ``` You can use String.prototype.toWellFormed(), which replaces lone surrogates with the Unicode replacement character (U+FFFD), to avoid this error. You can also use String.prototype.isWellFormed() to check if a string contains lone surrogates before passing it to `encodeURI()`. ## Specific