范围错误:form 必须是 'NFC'、'NFD'、'NFKC' 或 'NFKD' 之一

当无法识别的字符串传递给 String.prototype.normalize() 方法时,会发生 JavaScript 异常 "form 必须是 'NFC'、'NFD'、'NFKC' 或 'NFKD' 之一"。

¥The JavaScript exception "form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'" occurs when an unrecognized string is passed to the String.prototype.normalize() method.

信息

¥Message

RangeError: The normalization form should be one of NFC, NFD, NFKC, NFKD. (V8-based)
RangeError: form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD' (Firefox)
RangeError: argument does not match any normalization form (Safari)

错误类型

¥Error type

RangeError

什么地方出了错?

¥What went wrong?

String.prototype.normalize() 方法仅接受以下四个值作为其 form 参数:"NFC""NFD""NFKC""NFKD"。如果传递任何其他值,则会抛出错误。阅读 normalize() 的参考资料以了解不同的规范化形式。

¥The String.prototype.normalize() method only accepts the following four values as its form argument: "NFC", "NFD", "NFKC", or "NFKD". If you pass any other value, an error will be thrown. Read the reference of normalize() to learn about different normalization forms.

示例

¥Examples

无效案例

¥Invalid cases

js
"foo".normalize("nfc"); // RangeError
"foo".normalize(" NFC "); // RangeError

有效案例

¥Valid cases

js
"foo".normalize("NFC"); // 'foo'

也可以看看