1.1.1 • Published 11 months ago

bargain v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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" }
1.1.1

11 months ago

1.1.0

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago