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

shiajs

v1.4.2

Published

### promiseAny(iterable) Any promise fulfills -> resolve(value); All promises rejected -> reject(errArray).

Downloads

15

Readme

async delay(ms)

promiseAny(iterable)

Any promise fulfills -> resolve(value); All promises rejected -> reject(errArray).

digest(algorithm, data, hmackey)

md5(str)

sha256(str, hmackey)

sha512(str, hmackey)

timeiso(date, tz=null, len=-5)

ISO 8601 format datetime. date can be a Date object or timestamp (milliseconds), otherwise as now; tz is the timezone, or use local timesozne if it is not a number; len can be a number or date directive.

$log(...)

console.log starts with time.

async fileByLines(file, cbLine)

Call cbLine() every lines of the file, return promise.

async fileLinesMap(file, cbLine)

Create an array by running every lines of the file thru cbLine().

*traverseDir(parent)

Traverse a folder recursively.

for (const f of traverseDir('FOLDER')) console.log(f);

excelCsv(file, list, headers)

file is the csv path to write; list is a list of list, or a list of object; headers is table headers, can ignore.

urlJoin(host, path='/')

parseProxyList(proxiesStr)

async asyncPool(list, worker, size=10, showError=false)

Async call worker(list[idx], idx, list, label) every item of list parallelly. worker can return an Error instance to abort the thread; size is the thread pool size; showError can be true, false, or an async function showError(err, list[idx], idx, list, label).


Push Notification

This return an instance of the QPush, IFTTT or Telegram class based on the env variable PUSH_TOKEN.

const push = require('shiajs/push');
push.log('push some log');

Put PUSH_TOKEN on the /etc/environment for global use:

PUSH_TOKEN="qpush:name:code"
# PUSH_TOKEN="ifttt:token_key:event"
# PUSH_TOKEN="tg:bot_id:bot_token:chat_id"

QPush & QGroup class

Send push notification to QPush app for iOS.

const {QPush, QGroup} = require('shiajs/qpush');

const push = new QPush('name', 'code');
push.log('push some log'); // push.info() is the same
push.error(new Error('push an error'));

const group = new QGroup(['name1', 'code1'], ['name2', 'code2']);
group.info('info to group').error('push error to group');

IFTTT class

Send push notification to IFTTT app.

const {IFTTT} = require('shiajs/ifttt');
const push = new IFTTT('token');
const push2 = new IFTTT('token2', 'default_event_name');
push.log('push some log'); // push.info() is the same
push.error(new Error('push an error'));
push.send({
    value1: 'text1',
    value2: 'text2',
}, 'event_name');

Telegram class

Send push notification to Telegram app.

const {Telegram} = require('shiajs/telegram');
const tg = new Telegram('123456789', 'token', 'chat_id_1');
tg.setChatIds('chat_id_1', 'chat_id_2', 'chat_id_3'); // push to multi
tg.agent = new ProxyAgent('socks5h://127.0.0.1:1080'); // use socks proxy
tg.log('push some log'); // tg.info() is the same
tg.error(new Error('push an error'));
tg.showMessages(); // received messages in bot

Stopwatch class

const Stopwatch = require('shiajs/stopwatch');
const sw = new Stopwatch();
// ...
sw.tap('label');
// ...
const elapse1 = sw.tap();
console.log(elapse1, sw.get('label'), sw.toString(3));

Persist Object

Auto save the object to a file when top-level property are changed.

const Persist = require('shiajs/persist');
const config = Persist('/data/mypath/myconfig.json', {
    defaultValue: [123],
    state: 'init',
});
config.foo = 'bar'; // will auto save to the file
console.log(config.foo);
const Persist = require('shiajs/persist');
const config = Persist.tmp('filename-in-tmp-dir.json', { node: {} });
config.node.name = 'master'; // not top-level
config.save = void 0; // top-level

Promise Chain

Run async action one by one.

const PromiseChain = require('shiajs/promisechain')
const chain = new PromiseChain();
chain.add(fetchPage, 1);
chain.wait(5000).add(fetchPage.bind(null), 2)
chain.add(() => fetchPage(3)).wait(3000).add(() => {
    return fetchPage(4);
});
ws.on('message', data => {
    chain.add(doSomething, data).wait(1000);
});

Deferred Promise

Deferred promise with timeout.

const Deferred = require('shiajs/deferred')
const d = new Deferred();
await d.timeout(3000) // promise with timeout error after 3s
await d.promise; // no timeout
d.resolve(value);
d.reject(new Error('error'));

Running Sum

Compute running sum of the last n items in a sliding window.

const RunningSum = require('shiajs/runningsum')
const rsum = new RunningSum(10); // window size
rsum.add(5).add(12).add(8);
ws.on('message', data => {
    rsum.add(data.num);
    console.log(rsum.sum, rsum.avg);
});