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

scrpr

v0.1.28

Published

a scraper multitool

Downloads

7

Readme

scrpr

scrpr is a lightweight scraper multitool. it can fetch data via https, detect changes and parse the most common formats.

Usage Example

const scrpr = require("scrpr");

const scraper = scrpr({
	concurrency: 5,
	cachedir: '/tmp/scraper-cache',
});


scraper("https://example.org/data.csv", { 
	parse: "csv", 
}, function(err, change, data){

	if (err) console.error(err);
	if (change) console.log(data);
	
});

scrpr(opts)function scraper

Constructor, returns scraper function

Opts:

  • concurrency — number of parallel requests; default: 1
  • cachedir — directory to save cache data in; default: <root module>/.scrpr-cache

scraper([url], [opts], [callback(err, change, data)])

Scraper, delivers data

Opts:

  • method — http method; default: get
  • url — URL, alternative to url parameter
  • headers — additional http request headers, default: {}
  • data — http data to be sent, default: null
  • cache — use cache, default: true
  • cacheid — override cache id, default: hash(url, opts)
  • parse — format to parse, default: null (raw data)
  • successCodes — array of http status codes considered successful, default: [ 200 ]
  • needle — options passed on to needle, default {}
  • xlsx — options passed on to xlsx, default {}
  • xsv — options passed on to xsv, default {}
  • pdf — options passed on to pdf.js-extract, default {}
  • preprocess(data, callback(err, data)) — modify data before parsing
  • postprocess(data, callback(err, data)) — modify data after parsing
  • stream — deliver data as ReadableStream — no parsing or processing, default: false
  • metaredirects — follow <meta http-equiv="refresh"> style redirects, default: false
  • iconv — decode stream or data as this charset with iconv-lite before parsing, default: false
  • cooldown — microseconds since last fetch before a resource is fetched again, default: false
  • sizechange — treat unchanged content-length as same file, default: false

Callback:

  • err — contains Error or null
  • changetrue if data changed
  • data — raw or parsed data when changed, otherwise status string

Parsers

  • csv — Comma Seperated Values; data is an Object, parsed with xsv
  • tsv — Tab Separated Values; data is an Object, parsed with xsv
  • ssv — Semicolon Separated Values (data has been exported "as csv" with some localizations of Microsoft Excel): data is an Object, parsed with xsv
  • xml — eXtensible Markup Language; data is an Object, parsed with xml2js
  • json — JavaScript object Notation; data is an Object, parsed natively
  • html — HyperText Markup Language; data is an instance of cheerio
  • yaml — YAML Ain't Markup Language; data is an Object, parsed with yaml
  • xlsx — Office Open XML Workbook; data is an Object, parsed with xlsx; { "<sheetname>": [ [ cell, cell, cell, ... ], ... ] }
  • pdf — Portable Document Format; data is an Object, parsed with pdf.js-extract;
  • kdl — KDL Document Language; data is an Object, parsed with kdljs;
  • dw — Datawrapper Visualisation; data is an Object, extracted with dataunwrapper;

FTP

Rudimentary handling for ftp URLs is available if the optional get-uri dependency is installed.

Local Files

Rudimentary handling for local files is available with the file:/ pseude-protocol.

Optional dependencies

xsv, xlsx, xml2js, yaml, cheerio, dataunwrapper, iconv-lite, kdljs, pdf.js-extract and get-uri are optional dependencies. They should only be installed if their use is required.

License

UNLICENSE