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

@types/cheerio

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/cheerio

TypeScript definitions for Cheerio

  • 0.22.27
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.1M
increased by4.6%
Maintainers
1
Weekly downloads
 
Created

What is @types/cheerio?

@types/cheerio provides TypeScript type definitions for the Cheerio library, which is a fast, flexible, and lean implementation of core jQuery designed specifically for the server. Cheerio parses markup and provides an API for traversing/manipulating the resulting data structure.

What are @types/cheerio's main functionalities?

Loading HTML

Load HTML into Cheerio and parse it. This allows you to manipulate and traverse the HTML structure.

const cheerio = require('cheerio');
const $ = cheerio.load('<h2 class="title">Hello world</h2>');
console.log($('h2.title').text()); // Outputs: Hello world

Selecting Elements

Select elements using CSS selectors, similar to jQuery. This allows you to easily find and manipulate specific parts of the HTML.

const cheerio = require('cheerio');
const $ = cheerio.load('<ul><li>Apple</li><li>Banana</li></ul>');
$('li').each((index, element) => {
  console.log($(element).text());
}); // Outputs: Apple, Banana

Modifying Elements

Modify elements in the HTML. This includes changing text, attributes, and more.

const cheerio = require('cheerio');
const $ = cheerio.load('<h2 class="title">Hello world</h2>');
$('h2.title').text('Hello there!');
console.log($.html()); // Outputs: <h2 class="title">Hello there!</h2>

Extracting Data

Extract data from the HTML. This is useful for web scraping and data extraction tasks.

const cheerio = require('cheerio');
const $ = cheerio.load('<ul><li class="fruit">Apple</li><li class="fruit">Banana</li></ul>');
const fruits = [];
$('li.fruit').each((index, element) => {
  fruits.push($(element).text());
});
console.log(fruits); // Outputs: ['Apple', 'Banana']

Other packages similar to @types/cheerio

FAQs

Package last updated on 12 Mar 2021

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