Is given character suitable to be in an HTML attribute's name?

§ Quick Take

import { strict as assert } from "assert";
import is from "dist/is-char-suitable-for-html-attr-name.esm";

// Follows the spec:

assert.equal(is("a"), true);
assert.equal(is("?"), false);

§ Purpose

It's a function which validates strings (first character of it), is it suitable to be in an HTML attribute's name. See the official spec opens in a new tab for HTML attribute names.

§ API - Input


In other words, function which takes one string argument:

Input argumentKey value's typeObligatory?Description
strStringyesThe character to evaluate.

This program does not throw. It just returns false.

If the input string is longer than 1, its first character is used.

Zero-length string yields false, same like non-string type values.

§ API - Output

Boolean, true or false. Erroneous input arguments will yield false as well.

§ PS.

If you need a comprehensive list of all possible HTML attribute names, check out html-all-known-attributes.

§ Licence

MIT opens in a new tab

Copyright © 2010–2020 Roy Revelt and other contributors

Related packages:

📦 html-all-known-attributes 2.0.8
All HTML attributes known to the Humanity
📦 emlint 2.19.1
Pluggable email template code linter
📦 html-crush 2.0.9
Minifies HTML/CSS: valid or broken, pure or mixed with other languages
📦 string-strip-html 6.1.1
Strips HTML tags from strings. No parser, accepts mixed sources
📦 detect-is-it-html-or-xhtml 3.10.0
Answers, is the string input string more an HTML or XHTML (or neither)
📦 html-table-patcher 2.0.14
Visual helper to place templating code around table tags into correct places
📦 is-html-tag-opening 1.8.3
Is given opening bracket a beginning of a tag?