Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@web/parse5-utils

Package Overview
Dependencies
Maintainers
7
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web/parse5-utils

Utils for using parse5

  • 0.0.0-canary-20230404134439
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
120K
decreased by-8.87%
Maintainers
7
Weekly downloads
 
Created

What is @web/parse5-utils?

@web/parse5-utils is a utility library for working with the parse5 HTML parser. It provides a set of helper functions to manipulate and query the parse5 AST (Abstract Syntax Tree) more easily.

What are @web/parse5-utils's main functionalities?

Querying Elements

This feature allows you to query elements from the parse5 AST using CSS selectors. In the example, it queries all <p> elements from the parsed HTML.

const { parse } = require('parse5');
const { queryAll } = require('@web/parse5-utils');

const html = '<div><p>Hello</p><p>World</p></div>';
const document = parse(html);
const paragraphs = queryAll(document, 'p');
console.log(paragraphs.length); // 2

Manipulating Elements

This feature allows you to manipulate elements within the parse5 AST. In the example, it appends a new <p> element with text 'Hello World' to an existing <div>.

const { parse, serialize } = require('parse5');
const { append, createElement } = require('@web/parse5-utils');

const html = '<div></div>';
const document = parse(html);
const div = document.childNodes[0].childNodes[1];
const newElement = createElement('p', {}, 'Hello World');
append(div, newElement);
console.log(serialize(document)); // <html><head></head><body><div><p>Hello World</p></div></body></html>

Removing Elements

This feature allows you to remove elements from the parse5 AST. In the example, it removes the first <p> element from the parsed HTML.

const { parse, serialize } = require('parse5');
const { remove } = require('@web/parse5-utils');

const html = '<div><p>Hello</p><p>World</p></div>';
const document = parse(html);
const paragraph = document.childNodes[0].childNodes[1].childNodes[0];
remove(paragraph);
console.log(serialize(document)); // <html><head></head><body><div><p>World</p></div></body></html>

Other packages similar to @web/parse5-utils

Keywords

FAQs

Package last updated on 04 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc