§ 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.

§ Changelog

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

§ Licence

MIT opens in a new tab

Copyright © 2010–2020 Roy Revelt and other contributors

Related packages:

📦 codsen-tokenizer 4.3.0
HTML and CSS lexer aimed at code with fatal errors, accepts mixed coding languages
📦 codsen-parser 0.8.3
Parser aiming at broken or mixed code, especially HTML & CSS
📦 is-html-attribute-closing 1.4.1
Is a character on a given index a closing of an HTML attribute?
📦 html-crush 3.0.3
Minifies HTML/CSS: valid or broken, pure or mixed with other languages
📦 stristri 2.0.0
Extracts or deletes HTML, CSS, text and/or templating tags from string
📦 string-strip-html 7.0.3
Strips HTML tags from strings. No parser, accepts mixed sources