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

price-finder

v6.0.0-alpha.3

Published

Finds the prices of retail items online

Downloads

74

Readme

price-finder

NPM Version NPM Downloads

Finds the price of retail items online by scraping the web page.

Quick Example

import PriceFinder from 'price-finder';
const priceFinder = new PriceFinder();

// Led Zeppelin II vinyl (from Amazon)
const uri = 'https://www.amazon.com/Led-Zeppelin-II/dp/B00IXHBUG0';
const price = await priceFinder.findItemPrice(uri);
console.log(price); // 22.97

Price Finder Documentation

Configuration Options

When creating a new PriceFinder object, a configuration object can be specified. The following options are configurable:

  • retryStatusCodes : An array of status codes (Numbers) which when returned from the page scrape request, will trigger a retry request (meaning it will attempt to scrape the page again). Defaults to [503].
  • retrySleepTime : If a retry status code is returned from a page scrape request, this is the amount of time (in milliseconds) that the code will sleep prior to re-issuing the request. Defaults to 1000 (ms).

For example:

import PriceFinder from 'price-finder';

const priceFinder = new PriceFinder({
  retrySleepTime: 2000,
});

API

async findItemPrice(uri: string): number

Given a uri (that is for a supported site), this function will scrape the page and attempt to find the current price listed on the page. The result will be returned asynchronously.

If problems occur during processing, an Error will be thrown.

Debugging Price Finder

The pino package is used within price-finder to output debugging information useful in tracking down any potential issues.

Supported Sites

The current supported sites are listed below.

  • Amazon
  • Crutchfield (requires Node 16)
  • Home Depot

Don't see your site listed? Please consider contributing to the project!

Contributing

The price-finder project is a Node.js module, so before cloning the repository make sure node is installed. Once cloned, install dependencies by issuing:

$ yarn

Tests

The project uses Jest for tests (please add tests for any new features).

Unit Tests

To run the unit tests execute:

$ yarn test

These tests can be run in watch mode, listening for any file changes and re-running when that occurs. To do so execute:

$ yarn test:watch
End To End Tests

End-to-end tests exist which will test the price-finder module using real URIs, scraping the pages to verify the code works correctly.

Note that these tests should be run on a limited basis while coding since some sites have been known to throw up CAPTCHA's after repeated, automated page requests.

To execute the end to end tests run:

$ yarn test:e2e

To execute a specific end to end test run:

$ yarn test:e2e:single test/e2e/<test file>

Adding Sites

This project was built to easily drop in support for new sites. The site-manager iterates over all files contained within the sites directory, and adds it to the list of available sites. When a request is issued to price-finder to look up a price, it asks each site if the uri is supported by the site, and if so, uses that site to find the price.

  1. Create a new Site in src/sites:
export default class MySite implements Site {

  ...

}
  1. Add unit and e2e tests for the site
  • unit: test/unit/sites/MySite.test.ts

  • e2e: test/e2e/MySite.e2e.test.ts

  1. Add site to Supported Sites

  2. Create pull request to submit!

Releasing

(These notes require admin permissions)

  1. Update package.json with new version.

  2. Update CHANGELOG.md with new version along with included PRs and short description.

  3. Run yarn build

  4. Create pull request for release with updated files. Merge.

  5. Git tag:

$ git tag -a < version >
(enter in message  "Tag < version >" and include changelog message)

$ git show < version >       (shows data on specific tag)

$ git push origin —tags      (push all tags to remote)
  1. GitHub release:
  • Go to releases, click "Draft a new release"
  • Select the tag from the drop down list
  • Release title is version: "< version >"
  • Description is changelog message
  1. npm publish:
$ npm publish

Etc