New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

auger

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auger

Readline with promises

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

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!

Keywords

FAQs

Package last updated on 22 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc