Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

process.argv

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

process.argv - npm Package Compare versions

Comparing version
0.1.0
to
0.6.0
+21
LICENSE
MIT License
Copyright (c) 2016-2020 Yusuke Kawasaki
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
export default function argv(args: string[]): <T>(config: T) => T;
+14
-6
{
"name": "process.argv",
"description": "light-weight command line arguments parser for cli application",
"version": "0.1.0",
"description": "light-weight CLI arguments parser",
"version": "0.6.0",
"author": "@kawanet",

@@ -10,10 +10,17 @@ "bugs": {

"dependencies": {
"obop": "^0.0.12"
"obop": "^0.2.0"
},
"devDependencies": {
"jshint": "^2.9.2",
"mocha": "^2.5.3"
"jshint": "^2.12.0",
"mocha": "^8.2.0"
},
"files": [
"LICENSE",
"README.md",
"process.argv.js",
"types/process.argv.d.ts"
],
"homepage": "https://github.com/kawanet/process.argv#readme",
"jshintConfig": {
"esversion": 6,
"mocha": true,

@@ -39,3 +46,4 @@ "node": true,

"test": "npm run jshint && npm run mocha"
}
},
"typings": "./types/process.argv.d.ts"
}
+45
-15
# process.argv.js
light-weight command line arguments parser for cli application
light-weight CLI arguments parser
[![Node.js CI](https://github.com/kawanet/process.argv/workflows/Node.js%20CI/badge.svg?branch=master)](https://github.com/kawanet/process.argv/actions/)
[![npm version](https://badge.fury.io/js/process.argv.svg)](https://www.npmjs.com/package/process.argv)
## Synopsis
```sh
```js
#!/usr/bin/env node
var argv = require("process.argv")(process.argv.slice(2));
const argv = require("process.argv");
const processArgv = argv(process.argv.slice(2));
// default options --foo=AAA --bar-buz=BBB
var config = {
// apply CLI options onto defaults: --foo=AAA --bar-buz=BBB
const config = processArgv({
foo: "AAA",

@@ -18,7 +22,4 @@ bar: {

}
};
});
// apply options given on CLI arguments
config = argv(config);
// show help message if --help given

@@ -31,8 +32,37 @@ if (config.help) {

// rest of CLI arguments
var files = config["--"] || [];
files.forEach(function(file) {
console.log(file);
const args = config["--"] || [];
args.forEach(function(arg) {
console.log(arg);
});
```
CLI
```sh
node cli.js --foo=aaa --bar-buz=bbb file1 file2 file3
```
## TypeScript
```ts
import argv from "process.argv";
const processArgv = argv(process.argv.slice(2));
interface Config {
foo: string;
bar: {
buz: string;
},
qux?: boolean;
}
const config = processArgv<Config>({
foo: "AAA",
bar: {
buz: "BBB"
}
});
```
## FAQ

@@ -58,3 +88,3 @@

A. `.` is the special special character used internally. It's not available in a key.
A. `.` is the special character used internally. It's not available in a key.

@@ -64,3 +94,3 @@ ## Install

```sh
npm install -g process.argv
npm install --save process.argv
```

@@ -76,3 +106,3 @@

Copyright (c) 2016 Yusuke Kawasaki
Copyright (c) 2016-2020 Yusuke Kawasaki

@@ -79,0 +109,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

Sorry, the diff of this file is not supported yet

#!/usr/bin/env mocha
var argv = require("../process.argv")(process.argv.slice(2));
// default options --foo=AAA --bar-buz=BBB
var config = {
foo: "AAA",
bar: {
buz: "BBB"
}
};
// apply options given on CLI arguments
config = argv(config);
// show help message if --help given
if (config.help) {
require("fs").createReadStream(__dirname + "/help.md").pipe(process.stderr);
process.exit(1);
}
// rest of CLI arguments
var files = config["--"] || [];
files.forEach(function(file) {
// console.log(file);
});
// ================================
var TITLE = __filename.replace(/^.*\//, "");
describe(TITLE, function() {
it("readme", function() {
var assert = require("assert");
assert.ok(config.foo);
assert.ok(config.bar.buz);
});
});
// ================================
#!/usr/bin/env mocha
var assert = require("assert");
var dotargv = require("../process.argv");
var TITLE = __filename.replace(/^.*\//, "");
describe(TITLE, function() {
var SAMPLE_ARGS = ["aaa", "--bbb=ccc", "--ddd", "--eee-fff=ggg", "--hhh-iii", "jjj", "--kkk-lll-mmm=nnn", "--", "ooo", "--", "ppp"];
var SAMPLE_CONFIG = {
bbb: "CCC",
ddd: "DDD",
eee: {
fff: "GGG"
},
hhh: {
iii: "III"
},
kkk: {
lll: {
mmm: "NNN"
}
},
qqq: "QQQ"
};
it("argv([...])()", function() {
var argv = dotargv(SAMPLE_ARGS);
var config = argv(); // empty
assert.equal(config.bbb, "ccc");
assert.equal(config.ddd, true);
assert.equal(config.eee.fff, "ggg");
assert.equal(config.hhh.iii, true);
assert.equal(config.kkk.lll.mmm, "nnn");
assert.equal(config.qqq, null);
assert.ok(config["--"]);
assert.ok(config["--"] instanceof Array);
assert.equal(config["--"].join(","), ["aaa", "jjj", "ooo", "--", "ppp"].join(","));
});
it("argv([...])({...})", function() {
var argv = dotargv(SAMPLE_ARGS);
var config = JSON.parse(JSON.stringify(SAMPLE_CONFIG)); // deep clone
config = argv(config);
assert.equal(config.bbb, "ccc");
assert.equal(config.ddd, true);
assert.equal(config.eee.fff, "ggg");
assert.equal(config.hhh.iii, true);
assert.equal(config.kkk.lll.mmm, "nnn");
assert.equal(config.qqq, "QQQ");
});
it("argv()({...})", function() {
var argv = dotargv(); // empty
var config = JSON.parse(JSON.stringify(SAMPLE_CONFIG)); // deep clone
config = argv(config);
assert.equal(config.bbb, "CCC");
assert.equal(config.ddd, "DDD");
assert.equal(config.eee.fff, "GGG");
assert.equal(config.hhh.iii, "III");
assert.equal(config.kkk.lll.mmm, "NNN");
assert.equal(config.qqq, "QQQ");
});
var A4 = ["file"];
it("argv(" + JSON.stringify(A4) + ")()", function() {
var argv = dotargv(A4);
var config = argv();
assert.ok(config["--"]);
assert.ok(config["--"] instanceof Array);
assert.equal(config["--"].join(","), A4.join(","));
});
var A5 = "--%25=1 --%2D=2 --%3D=3".split(" ");
it("argv(" + JSON.stringify(A5) + ")()", function() {
var argv = dotargv(A5);
var config = argv();
assert.equal(config["%"], 1);
assert.equal(config["-"], 2);
assert.equal(config["="], 3);
});
});
// ================================