bargain
v1.1.1
Published
A barebones package for parsing option strings
Downloads
3
Readme
bargain
A barebones package for parsing option strings
> node ./index.js -i path/to/input/file.js -o path/to/output/file.js -a foo -b bar -c -d baz beep boop
// ./index.js
import { parseArguments } from "bargain";
// or
const { parseArguments } = require("bargain");
console.log(parseArguments(process.argv.split(2)));
// {
// _: [ 'beep', 'boop' ],
// i: 'path/to/input/file.js',
// o: 'path/to/output/file.js',
// a: 'foo',
// b: 'bar',
// c: true,
// d: 'baz'
// }
Options
parseArguments()
has to options you can pass for the second parameter, aliases
and defaults
console.log(
parseArguments(process.argv.split(2), {
aliases: {
input: ["i", "in"]
}
defaults: {
output: "output.js"
}
})
);
aliases
are additional names for arguments. In the example-i input.js
and-in input.js
will both return{ input: "input.js" }
defaults
are default values in the case if no value is provided. If no value is provided for output, then the function will return{ output: "output.js" }