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

auger

v1.0.1

Published

Readline with promises

Downloads

3

Readme

auger

Install

npm install --save auger

Usage

var auger = require('auger'),
    readline = require('readline'),
    fs = require('fs'),
    rl = readline.createInterface(process.stdin, process.stdout),
    aug = auger(rl);

rl.setPrompt('OHAI> ');
rl.prompt();

aug.ask('copy src.js? (y/n) ').then(function(bool){
    if(bool){
        console.log('Copying src.js to dest.js');
        var rs = fs.createReadStream('src.js'),
            ws = fs.createWriteStream('dest.js');

        rs.pipe(ws).on('finish', function(){
            rl.close();
        });
    }
});

About

It's pretty self explanatory. Pass an interface of readline to auger, and get an object that has an ask method. The ask method is almost exactly like rl.question except for this difference:

Normal readline

rl.question('question?', function(result){

});

auger readline

aug.ask('question?').then(function(result){

});

Readline input

auger translates input into it's respective javascript types where it can.

These are the type translations from a string to a javascript primitive:

  • true/true/n/y -> Boolean
  • integers/string -> Number
  • comma seperated list -> Array
  • everything else -> String

Translation

Call the auger function with options:

aug = auger(rl, {
    translate: false //No translation.
});
aug = auger(rl, {
    //Translate with a function.
    translate: function(answer){
        if(answer === 'y'){
            return true;
        }
        return false;
    }
});

The translate option can be a boolean, or a function. The default is a boolean value of true.

If translate is a boolean the default transform is used.

If translate is a function then that function will be called so you can return an appropriate value on each readline input.

If you want to translate some values, and not others that is fine too.

aug1 = auger(rl, {
    translate: false //No translation.
});

aug2 = auger(rl, {
    translate: true //Use translation.
});

More than one instance of auger is fine because they will all share the same readline interface.

Use auger with penumbra

var pen = require('penumbra')(),
    auger = require('auger'),
    rl = require('readline').createInterface(process.stdin, process.stdout),
    aug = auger(rl);
    fs = require('vinyl-fs');


pen.task('move', function * (){
    var answer;
    while(true){
        //Keep asking if the input is not a boolean.
        if(typeof (answer = yield aug.ask('Move files? (y/n) ')) === 'boolean'){
            //The answer is boolean.
            break;
        }
    }

    if(!answer){
        return aug.close();
    }
    console.log('moving files');
    yield [
        fs.src(['./*.js']),
        fs.dest('./output')
    ];
    aug.close();
});

If you save the file as move.js then you'd run the command:

node move.js move

Consistency?

auger also has all the methods of readline interface. There's no requirement to use them. You can still command readline from an rl instance.

Happy coding!