npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cheerio-iterable

v1.0.0

Published

Adds iterable functionality to the cheerio module, and adds conventional array functionality to cheerio (jquery) style elements

Downloads

3

Readme

cheerio-iterable

Adds iterable functionality to the cheerio module, and allows standard array functionality to used on cheerio/jquery elements.

Install It

npm install --save cheerio-iterable

Use it

var cheerio = require('cheerio-iterable');
var $ = cheerio.load(html);

Examples

Iterating over group of elements

html/xml:

<div>
  <h1>foo</h1>
  <h1>bar</h1>
</div>

js:

for(member of $('h1')){
  console.log("Text: "+member.text());
}

output:

Text: foo
Text: bar

Iterating over children of an element

html/xml:

<div id="content">
  <h1>foo</h1>
  <h2>bar</h2>
</div>

js:

for(child of $('#content').children()){
  console.log("Text: "+child.text());
}

output:

Text: foo
Text: bar

Using the iterable property

html/xml:

<div>
  <h1>First</h1>
  <h1>Second</h1>
</div>
<div>
  <h3>Third</h3>
</div>

js:

for (member of [...$('h3'),...$('h1')]) {
  console.log(member.text());
}

output:

Third
First
Second

Array prototypes

Most of the array prototype methods have been implemented for cheerio (some replacing existing functions). The Array.prototype.find function is implemented under element.arrayfind for a cheerio element "element".

Using the map function:

html/xml:

<div id="content">
  <h1>Hello</h1>
  <h2>World</h2>
</div>

js:

var array = $('#content')
  .children()
  .map((element)=>element.text());
console.log(array);

output:

['Hello', 'World']

Using the reverse function

js:

var array = $('#content')
  .children()
  .reverse()
  .map((element)=>element.text());
console.log(array);

html/xml:

<div id="content">
  <h1>Hello</h1>
  <h2>World</h2>
</div>

output:

['World', 'Hello']