Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cuisinart

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cuisinart - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

test/tests/extracommands.js

41

cuisinart.js

@@ -12,5 +12,5 @@ var assert = require('assert');

var matchOption = function(args,option){
var optionMatches = function(args,option){
var bothFlags = option.flag && option.longFlag;
var pattern = bothFlags ? '(?:' : '';
var pattern = '(';
if(option.flag){

@@ -23,8 +23,11 @@ pattern += ('\\s-' + option.flag);

}
if(bothFlags){
pattern += ')';
}
pattern += '(?:\\s|$)([^-]+)?';
pattern += ')';
pattern += '(?:\\s|$)([^-\\s]+)?';
var regex = new RegExp(pattern);
var matches = args.join(' ').match(regex);
return matches && matches[0] ? matches.splice(1) : matches;
}
var matchOption = function(args,option){
var matches = optionMatches(args,option);
if(matches){

@@ -39,4 +42,5 @@ return matches[1] ? matches[1].trim() : true;

if(command.name){
var regex = new RegExp('(\\s|^)' + command.name + '(\\s|$)');
return regex.test(args.join(' '));
var regex = new RegExp('(?:\\s|^)(' + command.name + ')(?:\\s|$)');
var matches = args.join(' ').match(regex);
return matches && matches[1] ? matches[1].trim() : false;
} else {

@@ -140,2 +144,18 @@ return false;

};
self.unmatchedArgs = function(args){
var argsString = Array.prototype.slice.call(args,2).join('##');
this._commands.forEach(function(command){
var match = matchCommand(args,command);
if(match){
argsString = argsString.replace(match,'');
(command.options || []).forEach(function(option){
var optionMatch = optionMatches(args,option);
if(optionMatch){
argsString = argsString.replace(optionMatch.join('##').trim(),'');
}
});
}
});
return argsString.split('##').filter(function(v){return v;});
}

@@ -146,4 +166,5 @@ // methods

self.parse = function(args,callback){
args = Array.prototype.slice.call(args,2);
var matchedCommands = 0;
async.forEach(self._commands,function(command,done){
async.forEachSeries(self._commands,function(command,done){
var matched = matchCommand(args,command);

@@ -165,3 +186,3 @@ if(matched){

if(command.stop) return done(new Error('complete'));
done(err);
done();
};

@@ -168,0 +189,0 @@ command.run.apply(self,[optionMap].concat(self._baseArgs,complete));

{
"name": "cuisinart",
"version": "0.1.2",
"version": "0.1.3",
"description": "A node js command line parser",

@@ -5,0 +5,0 @@ "main": "cuisinart.js",

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