is-char-suitable-for-html-attr-name2.0.14

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

§ Quick Take

import { strict as assert } from "assert";
import { isAttrNameChar } from "is-char-suitable-for-html-attr-name";

// Follows the spec:
// https://html.spec.whatwg.org/multipage/syntax.html#attributes-2

assert.equal(isAttrNameChar("a"), true);
assert.equal(isAttrNameChar("?"), 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

isAttrNameChar(str)

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.

§ Changelog

See it in the monorepo opens in a new tab, on GitHub.

§ Contributing

To report bugs or request features or assistance, raise an issue on GitHub opens in a new tab.

Any code contributions welcome! All Pull Requests will be dealt promptly.

§ Licence

MIT opens in a new tab

Copyright © 2010–2021 Roy Revelt and other contributors

Related packages:

📦 html-all-known-attributes 4.0.14
All HTML attributes known to the Humanity
📦 emlint 4.5.5
Pluggable email template code linter
📦 html-crush 4.1.8
Minifies HTML/CSS: valid or broken, pure or mixed with other languages
📦 stristri 3.1.6
Extracts or deletes HTML, CSS, text and/or templating tags from string
📦 string-strip-html 8.2.11
Strips HTML tags from strings. No parser, accepts mixed sources
📦 detect-is-it-html-or-xhtml 4.0.14
Answers, is the string input string more an HTML or XHTML (or neither)
📦 detect-templating-language 2.0.14
Detects various templating languages present in string