parse-opt-args
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

parse-opt-args

Library for parsing options out of strings

This package uses ES Modules, but provides a CommonJS build as well

npm
Usage: import parseOptArgs = from 'parse-opt-args';

import parseOptArgs = from 'parse-opt-args';
const myInput = `some input -o this is the 'o' option -m this is the 'm' option -q this is the 'q' option`;
const argsParsed = parseOptArgs(myInput, {'optionO':'o', 'optionQ':['q', '-optionQ'], 'optionZ':'-optionZ'});
console.log(argsParsed.optionO); // prints: this is the 'o' option
console.log(argsParsed.optionM); // prints: undefined
console.log(argsParsed.optionQ); // prints: this is the 'q' option
console.log(argsParsed.optionZ); // prints: undefined
console.log(argsParsed.args);    // prints: ['some', 'input', '-m', 'this', 'is', 'the', "'m'", 'option']

Credits

Hybrid build strategy derived from https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html

Readme

Keywords

none

Package Sidebar

Install

npm i parse-opt-args

Weekly Downloads

185

Version

0.2.2

License

MIT

Unpacked Size

36.6 kB

Total Files

27

Last publish

Collaborators

  • wakfi