Socket
Socket
Sign inDemoInstall

@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


Version published
Weekly downloads
1.9M
increased by3.61%
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 03 Jul 2019

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