Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Module for standard input/output management with nodejs.
To install the most recent release from npm, run:
npm install stdio
You can do many things with this module:
var stdio = require('stdio');
var ops = stdio.getopt({
'check': {key: 'c', args: 2, description: 'What this option means'},
'map': {key: 'm', description: 'Another description', mandatory: true},
'kaka': {key: 'k', args: 2, mandatory: true},
'ooo': {key: 'o'}
});
console.log(ops);
If you run the previous example with the command
node pruebas.js -c 23 45 88 --map -k 23 44 cosa
Program output will be:
{ check: [ '23', '45' ],
args: [ '88', 'cosa' ],
map: true,
kaka: [ '23', '44' ] }
So you can check options:
if(ops.map){
// Your action
}
if(ops.kaka){
// Your action, using ops.kaka[0] or ops.kaka[1] or...
}
As you can see, every option in ops
object can have one of the following 3 types of values:
true
if it has been specified without an args
attribute.string
if it has been specified with args: 1
.string
array, if it has been specified with args
> 1.Options can have the multiple
flag, in which case they can appear multiple times (with one argument each time). The value of that option will be an array with all provided arguments:
var ops = stdio.getopt({
'check': {key: 'c', description: 'What this option means', multiple: true}
});
node program.js -c 1 -c 2 -c 3
{ check: ['1', '2', '3'] }
Options can have the attribute multiple
:
var ops = stdio.getopt({
'check': {key: 'c', args: 1, description: 'What this option means', multiple: true}
});
in which case they can appear multiple times:
node test.js -c 1 -c 2 -c 3
So that an array will be returned:
{ check: ['1', '2', '3'] }
This module generates a descriptive usage message automatically. You'll see it when your program is called with -- help
option (or its short version -h
), which is automatically supported. The following code:
var stdio = require('stdio');
var ops = exports.getopt({
una: {description: 'Sets something to some value', args: 2, mandatory: true},
otra_muy_larga: {description: 'A boolean flag', key: 'o', mandatory: true},
una_sin_desc: {description: 'Another boolean flag'},
ultima: {description: 'A description', key: 'u', args: 1}
});
will produce the following output (if it is called with --help
flag):
USAGE: node main.js [OPTION1] [OPTION2]... arg1 arg2...
--una <ARG1> <ARG2> Sets something to some value (mandatory)
-o, --otra_muy_larga A boolean flag (mandatory)
--una_sin_desc Another boolean flag
-u, --ultima <ARG1> A description
If a non-expected option is given or a mandatory option isn't, then an error will be shown, suggesting to use --help
option to know how to use your program and finishing it automatically.
Missing "una" argument.
Try "--help" for more information.
The following code will read the whole standard input at once and put it into text
variable.
var stdio = require('stdio');
stdio.read(function(text){
console.log(text);
});
Obviously it is recommended only for small input streams, for instance a small file:
node myprogram.js < input-file.txt
The following code will execute dynamically a function over every line, when it is read from the standard input:
var stdio = require('stdio');
stdio.readByLines(function lineHandler(line, index) {
// You can do whatever you want with every line
console.log('Line %d:', index, line);
}, function () {
console.log('Finished');
});
The previous code will apply lineHandler()
to every line while they are read, without waiting the whole input to end, so it is very useful for large text streams. For instance a continuous log:
tail -f /var/log/system.log | node myprogram.js
The following code will ask the user for some info and then print it.
stdio.question('What is your name?', function (err, name) {
stdio.question('How old are you?', function (err, age) {
stdio.question('Are you male or female?', ['male', 'female'], function (err, sex) {
console.log('Your name is "%s". You are a "%s" "%s" years old.', name, sex, age);
});
});
});
By default stdio.question()
offers some retries when allowed answers are restricted (see the male/female question above). If no possible answers are specified, then the user can answer whatever he wants to the question.
To run tests, use the following command from module's root:
npm test
FAQs
Standard input/output manager for Node.js
The npm package stdio receives a total of 17,400 weekly downloads. As such, stdio popularity was classified as popular.
We found that stdio demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.