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

bblib

v2.0.8

Published

promisified libs for Node.js

Downloads

37

Readme

Introduction

Provide some promisified version (by bluebird) for some commonly used libs.

Install

$ npm i bblib

Usage

For Standard libs:

const bfs = require('bblib/fs');

async function main() {
  var exists = await bfs.exists('/path/to/file');
  if (exists) {
    // do something
  }
}

main();

For npm packages: bblib provide only the promisify script, so that you don't need to install all the packages. in order to use promisified version of a npm package, you need to install it to your project manually. for example, if you'd like to use promisified request lib:

  1. install the request package by:
$ npm i request -S
  1. use the promisified version in your code:
const request = require('bblib/request');

async function main() {
  var res = await request('https://www.google.com');

  console.log(`status: ${res.statusCode}`);
  console.log(`body  : ${res.body}`);
}

main();

Wrappers

Some libs were designed base on EvenEmitter, which can not be promisified simply. Here is the list or some useful libs

Same as before, you need to install the original package first by

$ npm i $PKG -S

sh

Wrap child_process to execute shell command

ssh2

Wrap ssh2 to provide ssh access

Homepage: https://github.com/mscdex/ssh2

const Client = require('bblib/ssh2');

async function main() {
  var client = new Client({
    host: 'example.com',
    username: 'root',
    password: '******'
  });

  var retryCount = 10;
  try {
    await client.connect(retryCount);
  } catch (e) {
    ...
  }

  var files = await client.exec('ls');
  var sftp = await client.sftp();
  await sftp.writeFile('/path/to/files.log', files);
  client.disconnect();
}

RestClient

Wrap request to provide a general purpose RESTful client

var client = new RestClient({
   suppress: true,                              // suppress rejection while response status is not ok
   prefix: 'http://api.example.com',            // api url prefix
   beforeSend: async function(opts) {           // modify request options before sending, like adding signature
     opts.headers = {
       signature: await sign(opt.form)
     };
   },
   afterReceive: function(resp) {               // reject with a custom error while status code is not 200
     if (resp.status !== 200)
       return P.reject(new MyOwnError('request error'));
   }
})

// or:

var client = new RestClient({ suppress: true });
client.prefix = 'https://api.example.com';
client.beforeSend = function(options) {  };

// then:

async function madin() {
  var getQuery = { page: 2 };
  var list = await client.get('/orders', getQuery);
  if (list['error'])
    throw new Error(list['message']);

  console.log(list.body['data']);

  var postJson = { name: 'John Doe', phone: '94823944', ... };
  var postQuery = { overwrite: true };
  var created = await client.post('/orders', postJson, postQuery);
  if (created['error'])
    throw new Error(created['message']);

  console.log(created.body.data.id);

  try {
    client.suppress = false;
    await client.get('/path/some/error');
  } catch (e) {
    console.log(e.response.body.message);
  }
}

Contribution

You are more than welcome to contribute by sending Pull Request.