Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
用于方便的解析用户输入的命令行参数,
npm install --save easy-arg
// 引入并创建一个实例
const EasyArg = require('ease-arg');
/**
* 包括两个参数,第一个参数是标识这个实例的字符串
* 第二个参数是一个对象,传入一个unexpectedCommand函数,当我们遇到未预期的命令时,就会调用这个函数
*/
const options = {unexpectedCommand: (command) => {console.log(command + '没有被add过')}}
const easyArg = new EasyArg('hello', options);
// 获取这个实例的name
console.log(easyArg.name);
add
添加一个命令
// 添加init命令,用户输入在init后的参数会以数组的形式传入
// 只有add过的字符串,我们才认为是命令,否则一律认为是参数
easyArg.add('init', (input) => {
console.log('input', input);
});
start
开始解析
// 参数为用户输入的所有命令以及参数组成的对象
easyArg.start((inputCommands) => {
console.log(inputCommands);
});
支持事件的方式触发
// 每当匹配到一个命令的时候,就会触发,接受命令的值以及命令的参数
easyArg.on('command', ({command, args}) => {
if (command === '-b') {
console.log(args);
}
});
const EasyArg = require('easy-arg');
/**
* 包括两个参数,第一个参数是标识这个实例的字符串
* 第二个参数是一个对象,传入一个unexpectedCommand函数,当我们遇到未预期的命令时,就会调用这个函数
*/
const options = {unexpectedCommand: (command) => {console.log(command + '没有被add过')}}
const easyArg = new EasyArg('hello', options);
easyArg.add('init', (input) => {
console.log('input', input);
});
easyArg.add('fad');
easyArg.add('-b');
// 监听每一个匹配到的命令
easyArg.on('command', ({command, args}) => {
if (command === '-b') {
console.log(args);
}
});
// 开始匹配(必须要写)可以接受一个回调函数,函数的参数是输入的所有“命令”(指被add过的命令)
easyArg.start((inputCommands) => {
console.log(inputCommands);
});
// 返回这个实例的name
console.log(easyArg.name);
FAQs
The npm package easy-arg receives a total of 0 weekly downloads. As such, easy-arg popularity was classified as not popular.
We found that easy-arg 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 researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.