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

prevOpen Source→is-html-attribute-closingnext

is-html-attribute-closing4.2.5

Is a character on a given index a closing of an HTML attribute?

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • API — ISATTRCLOSING…
  • API — VERSION
  • Changelog

No 3rd party dependencies. All dependencies and devDependencies, checked recursively, are Codsen packages.

Permalink to InstallationInstallation

Permalink to Quick TakeQuick Take

Permalink to ExamplesExamples

  • Broken #1
  • Broken #2
  • Broken #3
  • Return false for unusable source indexes
  • Recover when spaces replace attribute equals signs
  • Recover when an attribute value has no opening quote
  • Distinguish quotes inside a value from its closing quote
  • Detect the end of a single-quoted attribute value
  • Ignore quotes that belong to templating code inside a value

Purpose

This program detects, is a character at a given index in a given string being a closing of an attribute. In healthy code, that’s normally a double quotes character.

This program is aimed at fixing seriously broken HTML code — missing closing quotes, mismatching closing quotes, swapped quotes and unencoded “content” quotes as a part of attribute’s value.

It’s driving the codsen-tokenizer which in turn powers codsen-parser which in turn powers emlint.

For healthy HTML code, however, finding the closing double quotes is a trivial task.

API — isAttrClosing()

The main function isAttrClosing() 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
idxOfAttrOpening
Type: Natural number or zero
Obligatory: yes
idxOfAttrOpeningNatural number or zeroyesIndex of an opening quote of an attribute
isThisClosingIdx
Type: Natural number
Obligatory: yes
isThisClosingIdxNatural numberyesIndex you ask this program to evaluate, is it a closing quote

The function returns a boolean.

Attribute names and string indices

Following attribute names can contain underscores, periods, other permitted punctuation, and Unicode characters, including supplementary characters such as emoji. The helper uses these names to distinguish the current attribute’s closing quote from a later attribute’s quote.

Both indices are UTF-16 offsets, as returned by JavaScript’s indexOf(). A supplementary character occupies two code units; do not count it as one when calculating an index.

const html = '<div foo="text" foo😀="next">';

isAttrClosing(html, 9, 14); // true: closes foo
isAttrClosing(html, 9, 27); // false: closes foo😀

When an equals sign is missing, the helper uses additional recovery heuristics. Punctuation inside a broken value is weaker evidence than a recognized attribute name. This function identifies likely boundaries; it does not validate an entire attribute name or HTML document.

If anything is wrong with the input arguments, the program returns false. It never throws.

API — version

You can import version:

Permalink to changelogChangelog

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