{"library":"node-html-parser","title":"Fast HTML Parser","description":"node-html-parser, also known as Fast HTML Parser, is a high-performance JavaScript library designed to parse HTML and generate a simplified Document Object Model (DOM) tree. It prioritizes parsing speed for massive HTML files, meaning some malformed HTML might not be parsed with perfect fidelity, though it handles many common HTML errors like unclosed tags. The library is currently at version 7.1.0 and maintains an active release cadence, with multiple minor and patch updates in recent months. It ships with TypeScript types, supporting TypeScript projects from version 4.1.2 onwards. A key differentiator is its focus on parsing efficiency compared to other HTML parsers.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-html-parser"],"cli":null},"imports":["import { parse } from 'node-html-parser';","import { HTMLElement } from 'node-html-parser';","const HTMLParser = require('node-html-parser');\nconst root = HTMLParser.parse(htmlString);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { parse, HTMLElement } from 'node-html-parser';\n\nconst htmlString = '<ul id=\"list\"><li>Hello World</li></ul><p>Another element</p>';\n\nconst root = parse(htmlString);\n\n// The parse() function adds an implicit wrapper node. The actual parsed content is its first child.\nconsole.log('Structure of the first child:', root.firstChild?.structure);\n\n// Querying for an element by ID\nconst listElement: HTMLElement | null = root.querySelector('#list');\nif (listElement) {\n  console.log('List element found:', listElement.tagName);\n  console.log('List raw attributes:', listElement.rawAttrs);\n  console.log('List inner text:', listElement.innerText);\n}\n\n// Modifying content and serializing back to string\nif (listElement) {\n  listElement.set_content('<li>New Item 1</li><li>New Item 2</li>');\n}\nconsole.log('Modified HTML:', root.toString());\n\n// Example of parsing options\nconst htmlWithComment = '<!-- This is a comment --><div>Hello</div>';\nconst parsedWithComments = parse(htmlWithComment, { comment: true });\nconsole.log('Parsed with comments:', parsedWithComments.toString());\n","lang":"typescript","description":"This quickstart demonstrates parsing an HTML string, querying elements, accessing properties like innerText, modifying content, and serializing the DOM back to an HTML string. It also shows a basic usage of parse options.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}