Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→is-html-tag-openingnext

is-html-tag-opening4.2.1

Does an HTML tag start at given position?

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • API — ISOPENING()
  • API — DEFAULTS
  • API — VERSION
  • IN PRACTICE
  • Changelog

Installation

Quick Take

Examples

  • Recognise a closing tag
  • Ignore a less-than sign used for comparison
  • opts.allowCustomTagNames
  • opts.skipOpeningBracket
  • Recognise a self-closing tag with attributes

Purpose

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

API — isOpening()

The main function isOpening() is imported like this:

It’s a function which takes three input arguments:

Input argumentTypeObligatoryDescription
str
Type: String
Obligatory: yes
strStringyesThe input string of zero or more characters
idx
Type: Natural number or zero
Obligatory: no (defaults to 0)
idxNatural number or zerono (defaults to 0)Index of an opening bracket (<)
opts
Type: falsy or Plain Object
Obligatory: no
optsfalsy or Plain ObjectnoOptional Options Object

The optional options object has the following shape:

KeyTypeDefaultDescription
allowCustomTagNames
Type: boolean
Default: false
allowCustomTagNamesbooleanfalseProgram is aware of all known HTML tag names and by default will exclude what it can’t recognise. You can turn off that behaviour and make it rely on bracket/attribute patterns only.
skipOpeningBracket
Type: boolean
Default: false
skipOpeningBracketbooleanfalseBy default, algorithm expects that idx is on a bracket <. If you enable it, you can start from idx at the first tag’s character.

Here are all defaults in one place for copying:

Function returns a boolean.

API — defaults

You can import defaults:

It's a plain object:

The main function calculates the options to be used by merging the options you passed with these defaults.

API — version

You can import version:

In Practice

This program allows you to tackle any raw unencoded brackets in HTML code, for example: <div> < </div>.

It will drive codsen-tokenizer which in turn will drive codsen-parser which in turn will drive emlint.

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab