No dependencies whatsoever. This package declares no dependencies or devDependencies.
Permalink to InstallationInstallation
Permalink to Quick TakeQuick Take
Permalink to ExamplesExamples
- Only the first character is checked
- Characters rejected in attribute names
- Characters allowed in attribute names
Purpose
Checks whether the first Unicode code point can appear in an HTML attribute name. It accepts punctuation such as underscores and periods, non-ASCII letters, supplementary characters such as emoji, and non-breaking spaces. See the HTML attribute-name syntax.
The function rejects ASCII whitespace, controls, quotes, slashes, equals signs, greater-than signs, lone surrogates, and Unicode noncharacters. It also rejects the less-than sign because the HTML parser treats it as an error in attribute names. This character check does not validate a complete attribute name or determine whether an attribute has defined semantics.
API — isAttrNameChar()
The main function isAttrNameChar() is imported like this:
It’s a function which takes one input argument:
| Input argument | Type | Obligatory | Description |
|---|---|---|---|
strType: String Obligatory: yes | |||
str | String | yes | The character to evaluate. |
The function always returns a boolean and never throws errors.
In case of non-string input or empty string, it just returns false.
Only the first Unicode code point is checked, including both UTF-16 code units of a supplementary character. For example, "-rest" and ":rest" return true, while " rest" returns false. The rest of the string does not affect the result.
Also
If you need a comprehensive list of all possible HTML attribute names, check out html-all-known-attributes.