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

cheerio-to-text

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cheerio-to-text

Turn a Cheerio object into plain text

  • 0.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
increased by37.38%
Maintainers
1
Weekly downloads
 
Created
Source

cheerio-to-text

Explained by an example:

import fs from "fs"
import cheerio from "cheerio"
import { render } from "cheerio-to-text"

const html = fs.readFileSync("page.html", "utf-8")
console.log(html)
//
// <!doctype html>
// <body>
//   <div id="main">
//    <p>Para<strong>graph</strong>.</p>
//    <ul><li>Foo</li><li>Bar</li></ul><h3>Heading</h3>
//   </div>
// </body>
//

const $ = cheerio.load(html)
console.log($("div#main").text())
//
//  Paragraph.
//  FooBarHeading
//

console.log(render($("div#main")))
//
//  Paragraph.
//  Foo
//  Bar
//  Heading
//

Much of the origin of this that GitHub Docs scrapes every page with got and cheerio and then needs to convert that into an appropriate string of plain text that it can use for searching with Elasticsearch. Using myCheerioObject.text() isn't good enough because it lumps together HTML blocking tags that have no whitespace between the > and the next <.

License

MIT

How to hack

Run npm run build:watch in one terminal the look at example.mjs (which you run with node example.mjs)

How to run tests

jest

Or

jest --watch -t "some test text"

Keywords

FAQs

Package last updated on 02 Oct 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