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

cmdline

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cmdline - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

1

bin/cli.js

@@ -24,3 +24,4 @@ #!/usr/bin/env node

console.log('default:', $0);
console.log('has t:', this.has('t'));
})
.ready();

@@ -5,6 +5,11 @@ const Class = require('cify').Class;

//常量
const OPTION_REGEXP = /^\-+([\s\S]*)/i;
const COMMAND_REGEXP = /^[a-z0-9]+/i;
const NOOP_FUNCTION = function () { };
const TOKEN_TYPE_OPTION_VALUE = 'OPTION_VALUE';
/**
* 定义命令行参数解析器
**/
const Parser = new Class({

@@ -30,5 +35,10 @@

**/
command: function (names, fn, _arguments) {
command: function (names, fn, pattern) {
if (!names) return this;
fn = fn || NOOP_FUNCTION;
if (utils.isFunction(pattern)) {
fn = [pattern, pattern = fn][0];
}
if (!utils.isFunction(fn)) {
fn = NOOP_FUNCTION;
};
this._commands = this._commands || {};

@@ -41,6 +51,8 @@ names = utils.isArray(names) ? names : [names];

};
this.handle({
command: name,
arguments: !!_arguments
}, fn);
if (pattern === true) {
pattern = { arguments: true };
}
pattern = (utils.isObject(pattern) ? pattern : {}) || {};
pattern.command = name;
this.handle(pattern, fn);
}, this);

@@ -54,5 +66,6 @@ return this;

handle: function (pattern, fn) {
if (arguments.length == 1) {
return this.handle(null, pattern);
if (utils.isFunction(pattern)) {
fn = [pattern, pattern = fn][0];
}
if (!utils.isFunction(fn)) return this;
pattern = pattern || {};

@@ -74,2 +87,8 @@ if (utils.isString(pattern.command)) {

if (!names) return this;
if (utils.isFunction(settings)) {
fn = [settings, settings = fn][0];
}
if (!utils.isFunction(fn)) {
fn = NOOP_FUNCTION;
};
this._options = this._options || {};

@@ -158,2 +177,16 @@ settings = (utils.isArray(settings) ? settings : [settings]).map(function (setting) {

/**
* 是否包含某一个参数或选项
**/
has: function (name) {
return this._injectMap.hasOwnProperty(name);
},
/**
* 获取一个参数或选项
**/
get: function (name) {
return this._injectMap[name];
},
/**
* 解析 tokens

@@ -165,4 +198,11 @@ **/

this._tokens.forEach(function (token) {
tokens = tokens.concat(OPTION_REGEXP.test(token) ?
token.split('=') : token);
var eqIndex = token.indexOf('=');
if (!OPTION_REGEXP.test(token) || eqIndex < 0) {
tokens.push(token);
} else {
tokens.push(token.substring(0, eqIndex));
var optVal = new String(token.substring(eqIndex + 1));
optVal.type = TOKEN_TYPE_OPTION_VALUE;
tokens.push(optVal);
}
}, this);

@@ -233,3 +273,4 @@ this._tokens = tokens;

(!setting.regexp || setting.regexp.test(nextToken))) {
var value = utils.isNull(nextToken) ? setting.default : nextToken;
var value = utils.isNull(nextToken) ?
setting.default : nextToken.toString();
return setting.convert ? setting.convert(value) : value;

@@ -242,3 +283,3 @@ } else {

this.options[token] = values;
} else {
} else if (token.type != TOKEN_TYPE_OPTION_VALUE) {
this.argv.push(token);

@@ -245,0 +286,0 @@ }

2

package.json
{
"name": "cmdline",
"rawName": "cmdline",
"version": "1.0.5",
"version": "1.0.6",
"description": "cmdline is a process.argv parser",

@@ -6,0 +6,0 @@ "main": "./lib/index.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