UNPKG

html-tokenizer

Version:

Small, fast, event-driven, fault-tolerant html tokenizer. Works in node or browsers.

27 lines 852 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const PATTERN = /(\s*([^>\s]*))/g; const QUOTES = new Set('"\''); /** * Extract an attribute from a chunk of text. */ function readAttribute(str, pos) { const quote = str.charAt(pos); const pos1 = pos + 1; if (QUOTES.has(quote)) { const nextQuote = str.indexOf(quote, pos1); if (nextQuote === -1) { return { length: str.length - pos, value: str.substring(pos1) }; } else { return { length: (nextQuote - pos) + 1, value: str.substring(pos1, nextQuote) }; } } else { PATTERN.lastIndex = pos; const match = PATTERN.exec(str) || []; return { length: match[1].length, value: match[2] }; } } exports.default = readAttribute; //# sourceMappingURL=read-attribute.js.map