Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
argv-router
Advanced tools
npm install argv-router
匹配表达式分为单参数和组合参数两种,不可混合使用
单参数时直接指定参数名即可,使用简写、全称命名时用英文逗号分隔
const argvRouter = require('argv-router')
argvRouter({
'-v, --version'(argv) {
console.log(argv)
},
'-w, --watch, <>'(argv) {
console.log(argv)
}
})
组合参数时,多个参数使用空格分隔
const argvRouter = require('argv-router')
argvRouter({
'-a -w'(argv) {
console.log(argv)
},
})
在使用组合参数时可以搭配单参数实现自动扩展,使用单参数中的任意简写或全称命名。如以下示例中组合参数“-a -w”会尝试匹配“-a -w”、“-a --watch”、“--async -w”、“--async --watch”。
let options = {
'-w, --watch'(argv) {
},
'-a, --async'(argv) {
},
'-a -w'(argv) {
}
}
argvRouter(options)
通过“<>”占位符号定义是否启用参数值
const argvRouter = require('argv-router')
argvRouter({
'-a <> -w <>'(argv) {
console.log(argv)
},
})
通过“[$name]”定义是否启用无参数名的快捷赋值选项,在argv中返回一个以“$name”命名的匹配项数组
const argvRouter = require('argv-router')
argvRouter({
'[files] -a <> -w <>'(argv) {
console.log(argv.files)
},
})
首先按匹配参数数量进行升级,匹配参数越多优先级越高。在等量参数数量下,包含快速赋值的匹配项先级高于其它选项。
在参数为空时指定默认行为
let options = {
'-w, --watch'(argv) {
},
'-a, --async'(argv) {
}
}
let router = argvRouter(options, '-w')
在js中动态执行指定的cli命令
let router = argvRouter(options)
router.execute('-v')
router.execute('-w -a')
FAQs
简单的node.js命令行参数路由分发器
The npm package argv-router receives a total of 1 weekly downloads. As such, argv-router popularity was classified as not popular.
We found that argv-router demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.