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

inchworm

v0.6.1

Published

Will crawl across any webpage and expose rxjs observables for you to subscribe

Downloads

3

Readme

inchworm Build Status Coverage Status

This library will crawl a web page using jsdom and produce different observable rxjs streams that allow you to subscribe to various page elements, stylesheets and scripts.

Installation

For integrated usage where you can add your own subscriptions (observers) to the crawling, install it as a dependency in your node project.

npm i -S inchworm

Quick Example

import Inchworm from './Inchworm'

const worm = new Inchworm()
worm.page.subscribe(({url, content}) => {
	console.log(content) // will spit out the webpage html
})
worm.anchorTags.subscribe( el => {
	console.log(el.getAttribute('href')) // fired for every links on the page
})
worm.crawl('https://wookets.github.io')

Subscribing to Crawler Events

When you crawl() a document, inchworm will load the HTML document into Cheerio and crawl for various (e.g. link, script) tags. When it encounters one of these, it will push an event out to any subscribers. Inchworm passes back to you a Cheerio-wrapped DOM Element.

Anchor Tags

cont worm = new Inchworm()
// for every anchor tag we find, we emit an observer
worm.anchorTags.subscribe( el => {
	// el is just a DOM element (mdn)[https://developer.mozilla.org/en-US/docs/Web/API/Element]
})
worm.crawl(url)

Image tags

Inline css.

const worm = new Inchworm()
worm.imgTags.subscribe( el => {})
worm.crawl(url)

Link tags

Remember that a tag doesn't automatically mean stylesheet.

const worm = new Inchworm()
worm.linkTags.subscribe( el => {
	if (this.loadStylesheets && linkEl.getAttribute('rel') === 'stylesheet') {
		let href = linkEl.getAttribute('href')
	}
})
worm.crawl(url)

Script tags

Can be an inline script or an external sheet.

const worm = new Inchworm()
worm.scriptTags.subscribe( el => {})
worm.crawl(url)

Style tags

Inline css.

const worm = new Inchworm()
worm.styleTags.subscribe( el => {})
worm.crawl(url)

Subscribing to Document Loading

Inchworm surfaces up document loading to provide you the opportunity to go with your own processing. You can even handle the first page crawl and do something completely different from what Inchworm provides out of the box. Or if you want Inchworm to load CSS and JS files and expose their contents when they are loaded, you can do that as well. It should be noted that while Inchworm uses jsdom to parse the HTML page for you, CSS and JS files are left to you - maybe one day I'll find some parsers that would be meaningful, but really it would amount to AST-type parsing given how complex JS and CSS can become.

page

When you invoke the crawl command, it will download the html document from the passed in url. If you want to access the raw html in string form, you can subscribe to the page observable.

const worm = new Inchworm()
worm.page.subscribe( {url, content} => {})
worm.crawl('https://wookets.github.io')

stylesheets

Inchworm by default will not load stylesheets from the links on the html doc. When a stylesheet is loaded, next() will be called on the Stylesheet Observer so you can listen for it.

const worm = new Inchworm({
	loadStylesheets: true
})
worm.stylesheets.subscribe( {url, content} => {
	if (content.match(/.hello-class/)) {
		throw new Error('.hello-class is deprecated')
	}
})
worm.crawl('https://wookets.github.io')

javascript files

Inchworm by default will not load external javascript files from script tags. When a javascript is loaded, next() will be called on the Javascript FIle Observer so you can listen for it.

const worm = new Inchworm({
	loadJavascriptFiles: true
})
worm.javascriptFiles.subscribe( {url, content} => {})
worm.crawl('https://wookets.github.io')

Notes

  • Requires Node 8.x+
  • "JSDOM doesn't do stream parsing, so it doesn't gain much from rxjs" - true... but it could be one day. And if it does, the API won't have to change.