§ Quick Take

import { strict as assert } from "assert";
import isOpening from "dist/is-html-tag-opening.esm";

const text = `<span>a < b<span>`;

// opening span tag's opening
assert.equal(isOpening(text, 0), true);

// unencoded bracket between a and b
assert.equal(isOpening(text, 8), false);

// closing span tag's opening
assert.equal(isOpening(text, 11), true);

§ Purpose

Detect, is an opening bracket (<) a tag opening? Otherwise, it might be an un-encoded text.

§ API - Input

isOpening(str, idx)

In other words, function which takes two arguments:

Input argumentKey value's typeObligatory?Description
strStringyesThe input string of zero or more characters
idxNatural number or zeroyesIndex of an opening bracket (<)

If supplied input arguments are of any other types, an error will be thrown.

§ API - Output

It returns a boolean.

§ In Practice

This program allows us to tackle any raw unencoded brackets in HTML code. It will drive linters.

§ Licence

MIT opens in a new tab

Copyright © 2010–2020 Roy Revelt and other contributors

Related packages:

📦 codsen-tokenizer 3.1.0
HTML and CSS lexer aimed at code with fatal errors, accepts mixed coding languages
📦 codsen-parser 0.7.9
Parser aiming at broken or mixed code, especially HTML & CSS
📦 emlint 2.19.2
Pluggable email template code linter
📦 is-html-attribute-closing 1.3.0
Is a character on a given index a closing of an HTML attribute?
📦 html-crush 2.0.9
Minifies HTML/CSS: valid or broken, pure or mixed with other languages
📦 string-strip-html 6.2.0
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)