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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vbarbarosh/puppeteer-helpers

v0.2.2

Published

A set of helpers for Puppeteer

Readme

A set of helpers for Puppeteer.

Installation

npm install vbarbarosh/puppeteer-helpers

Basic usage

#!/usr/bin/env node

const cli = require('@vbarbarosh/node-helpers/src/cli');
const puppeteer = require('puppeteer');
const puppeteer_log = require('@vbarbarosh/puppeteer-helpers/src/puppeteer_log');

cli(main);

async function main()
{
    const browser = await puppeteer.launch();

    try {
        const page = puppeteer_log(await browser.newPage());
        await page.setViewport({width: 1280, height: 768});
        await page.goto('http://example.com');
        await page.screenshot({path: 'a.png', fullPage: true, omitBackground: true});
        // ...
    }
    finally {
        await browser.close();
    }
}

demos • puppeteer_eval

#!/usr/bin/env node

const Promise = require('bluebird');
const cli = require('@vbarbarosh/node-helpers/src/cli');
const puppeteer = require('puppeteer');
const puppeteer_eval = require('@vbarbarosh/puppeteer-helpers/src/puppeteer_eval');
const {performance} = require('perf_hooks');

const items = [
    {
        url: 'https://www.bnm.md',
        expr: `{
            usd: [
                (+document.querySelector('#ajax-wrapper-list > div > ul > li:nth-child(1) > span.rate')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
                (+document.querySelector('#ajax-wrapper-list > div > ul > li:nth-child(1) > span.rate')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
            ],
            eur: [
                (+document.querySelector('#ajax-wrapper-list > div > ul > li:nth-child(2) > span.rate')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
                (+document.querySelector('#ajax-wrapper-list > div > ul > li:nth-child(2) > span.rate')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
            ],
        }`
    },
    {
        url: 'https://www.xe.com/currencyconverter/convert/?Amount=1&From=MDL&To=USD',
        expr: `
            document.querySelector('#siteHeader svg').parentElement.click(),
            await waitForSelector('#inverse'),
            document.querySelector('#inverse').click(),
            await waitForSelector('[data-key=USD] .ellipser'), {
            usd: [
                (parseFloat(document.querySelector('[data-key=USD] .ellipser')?.textContent).toFixed(2)||null),
                (parseFloat(document.querySelector('[data-key=USD] .ellipser')?.textContent).toFixed(2)||null),
            ],
            eur: [
                (parseFloat(document.querySelector('[data-key=EUR] .ellipser')?.textContent).toFixed(2)||null),
                (parseFloat(document.querySelector('[data-key=EUR] .ellipser')?.textContent).toFixed(2)||null),
            ],
        }`,
    },
    {
        url: 'https://comertbank.md',
        expr: `{
            usd: [
                (+document.querySelector('div.vault.v_banka > div:nth-child(2) > div:nth-child(2)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
                (+document.querySelector('div.vault.v_banka > div:nth-child(3) > div:nth-child(2)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
            ],
            eur: [
                (+document.querySelector('div.vault.v_banka > div:nth-child(2) > div:nth-child(3)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
                (+document.querySelector('div.vault.v_banka > div:nth-child(3) > div:nth-child(3)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
            ],
        }`,
    },
    {
        url: 'https://fincombank.com',
        expr: `{
            usd: [
                (+document.querySelector('table.exchange-rates__table.active > tbody > tr:nth-child(1) > td:nth-child(2)')?.textContent||0).toFixed(2),
                (+document.querySelector('table.exchange-rates__table.active > tbody > tr:nth-child(1) > td:nth-child(3)')?.textContent||0).toFixed(2),
            ],
            eur: [
                (+document.querySelector('table.exchange-rates__table.active > tbody > tr:nth-child(2) > td:nth-child(2)')?.textContent||0).toFixed(2),
                (+document.querySelector('table.exchange-rates__table.active > tbody > tr:nth-child(2) > td:nth-child(3)')?.textContent||0).toFixed(2),
            ],
        }`,
    },
    {
        url: 'https://www.maib.md/ru',
        expr: `{
            usd: [
                (+document.querySelector('.exchange__table tbody tr:nth-child(1) td:nth-child(2)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
                (+document.querySelector('.exchange__table tbody tr:nth-child(1) td:nth-child(3)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
            ],
            eur: [
                (+document.querySelector('.exchange__table tbody tr:nth-child(2) td:nth-child(2)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
                (+document.querySelector('.exchange__table tbody tr:nth-child(2) td:nth-child(3)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
            ],
        }`,
    },
    {
        url: 'https://www.victoriabank.md/ru/kurs-obmena',
        expr: `{
            usd: [
                (+document.querySelector('#numerar > div.vb-table.vb-table-default.text-center > div:nth-child(2) > div:nth-child(2)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
                (+document.querySelector('#numerar > div.vb-table.vb-table-default.text-center > div:nth-child(2) > div:nth-child(3)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
            ],
            eur: [
                (+document.querySelector('#numerar > div.vb-table.vb-table-default.text-center > div:nth-child(3) > div:nth-child(2)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
                (+document.querySelector('#numerar > div.vb-table.vb-table-default.text-center > div:nth-child(3) > div:nth-child(3)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
            ],
        }`,
    },
    {
        url: 'https://micb.md',
        expr: `{
            usd: [
                (+document.querySelector('#currancy-rates > table > tbody > tr:nth-child(1) > td:nth-child(2)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
                (+document.querySelector('#currancy-rates > table > tbody > tr:nth-child(1) > td:nth-child(3)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
            ],
            eur: [
                (+document.querySelector('#currancy-rates > table > tbody > tr:nth-child(2) > td:nth-child(2)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
                (+document.querySelector('#currancy-rates > table > tbody > tr:nth-child(2) > td:nth-child(3)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
            ],
        }`,
    },
    {
        url: 'https://ecb.md',
        expr: `{
            usd: [
                (+document.querySelector('.curr-list > .sector-1 > :nth-child(2)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
                (+document.querySelector('.curr-list > .sector-1 > :nth-child(3)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
            ],
            eur: [
                (+document.querySelector('.curr-list > .sector-1 > :nth-child(6)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
                (+document.querySelector('.curr-list > .sector-1 > :nth-child(7)')?.textContent||0).toFixed(2).replace(/^0.00$/, '')||null,
            ],
        }`,
    },
];

cli(main);

async function main()
{
    // net::ERR_CERT_DATE_INVALID at http://eximbank.com
    const browser = await puppeteer.launch({ignoreHTTPSErrors: true, headless: 'new'});
    try {
        const results = await Promise.map(items, mapper, {concurrency: 10});
        async function mapper(item) {
            const begin = performance.now();
            const page = await browser.newPage();
            // https://comertbank.md/ returns 404 for HeadlessChrome
            // Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/92.0.4512.0 Safari/537.36
            await page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4512.0 Safari/537.36');
            await page.exposeFunction('waitForSelector', async function (selector) {
                await page.waitForSelector(selector);
            });
            try {
                console.log(`begin: ${item.url}`);
                await page.goto(item.url);
                const out = {url: item.url, ...await puppeteer_eval(page, item.expr)};
                const time = `${+((performance.now() - begin)/1000).toFixed(2)}sec`;
                console.log(`done: ${item.url} [${time}]`);
                out.time = time;
                return out;
            }
            catch (error) {
                console.log(`Parse failed with message: ${error.message}`, item);
                const time = `${+((performance.now() - begin)/1000).toFixed(2)}sec`;
                return {url: item.url, time, error, usd: ['', ''], eur: ['', '']};
            }
            finally {
                await page.close();
            }
        }
        const table = results.map(v => [v.url, ...v.usd, ...v.eur, v.time]);
        table.sort((b,a) => a[1] - b[1]);
        console.log();
        console.log(render_table(table));
    }
    catch (error) {
        console.log(error.message);
    }
    finally {
        await browser.close();
    }
}

function render_table(array)
{
    const len = {};
    array.forEach(function (row) {
        row.forEach(function (value, i) {
            len[i] = Math.max(len[i]||0, String(value).length);
        });
    });
    let out = '';
    array.forEach(function (row) {
        out += row.map((v,i) => String(v).padEnd(len[i])).join(' | ').replace(/\s*$/, '\n');
    });
    return out;
}
begin: https://www.bnm.md
begin: https://comertbank.md
begin: https://fincombank.com
begin: https://www.maib.md/ru
begin: https://www.victoriabank.md/ru/kurs-obmena
begin: https://www.xe.com/currencyconverter/convert/?Amount=1&From=MDL&To=USD
begin: https://ecb.md
begin: https://micb.md
done: https://ecb.md [3.06sec]
done: https://micb.md [3.77sec]
done: https://www.bnm.md [4.06sec]
done: https://www.victoriabank.md/ru/kurs-obmena [4.61sec]
done: https://www.xe.com/currencyconverter/convert/?Amount=1&From=MDL&To=USD [4.86sec]
done: https://www.maib.md/ru [5.37sec]
done: https://fincombank.com [6.16sec]
done: https://comertbank.md [6.89sec]

https://www.bnm.md                                                     | 17.93 | 17.93 | 19.46 | 19.46 | 4.06sec
https://comertbank.md                                                  | 17.85 | 18.00 | 19.25 | 19.50 | 6.89sec
https://fincombank.com                                                 | 17.83 | 18.03 | 19.28 | 19.52 | 6.16sec
https://www.maib.md/ru                                                 | 17.83 | 18.05 | 19.28 | 19.55 | 5.37sec
https://ecb.md                                                         | 17.82 | 18.02 | 19.26 | 19.52 | 3.06sec
https://www.xe.com/currencyconverter/convert/?Amount=1&From=MDL&To=USD | 17.81 | 17.81 | 19.30 | 19.30 | 4.86sec
https://www.victoriabank.md/ru/kurs-obmena                             | 17.75 | 18.03 | 19.20 | 19.49 | 4.61sec
https://micb.md                                                        | 17.75 | 18.05 | 19.20 | 19.55 | 3.77sec