String isWellFormed() and toWellFormed()
String.prototype.isWellFormed() は文字列に孤立サロゲートが含まれないかを判定し、toWellFormed() は孤立サロゲートを置換文字(U+FFFD)に変換します。
概要
String.prototype.isWellFormed() は文字列に孤立サロゲートが含まれないかを判定し、toWellFormed() は孤立サロゲートを置換文字(U+FFFD)に変換します。
対応ブラウザ
| 機能 | デスクトップ | モバイル | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 111 | 111 | 119 | 16.4 | 111 | 16.4 | |
| ビルトインオブジェクト | ||||||
| toWellFormed() は String 値のメソッドで、この文字列のすべての孤立サロゲートを Unicode 置換文字 U+FFFD に置き換えた文字列を返します。 | 111 | 111 | 119 | 16.4 | 111 | 16.4 |
基本構文
JAVASCRIPT
'Hello'.isWellFormed(); // true
'\uD800'.isWellFormed(); // false (isolated surrogate)
'\uD800'.toWellFormed(); // '\uFFFD' ライブデモ
not-positive Unicode. Detect
IsWellFormed Use, string to not-completeall saroge-tpea that include or check..
プレビュー全画面表示
safeall shape notation. autoconvert
ToWellFormed use, not-positive character replacecharacter to convertsafeall to like to..
プレビュー全画面表示
positivealways string. confirm
Normal. String(emojiinclude) that positivealways shape notation in exists and inspect it..
プレビュー全画面表示
実務での使いどころ
-
String isWellFormed() and toWellFormed() の活用
文字列が正しい Unicode 形式かを判定・変換するメソッド。孤立サロゲートを検出・修正できる。
注意点
- 古いブラウザ(IE等)では対応していない。対象ブラウザを確認すること。
アクセシビリティ
- JavaScript による動的更新時は、aria-live リージョンで変更をスクリーンリーダーに通知する。
参考リンク
Powered by web-features