@vmdao/minimist-string
v1.0.2
Published
A minimist extension to parse command line sentences as strings
Readme
Disclaimer
This repository is not the original source.
It is a fork preserved after the original repository was removed from GitHub.
- The code and resources here are provided as-is, without any guarantees of accuracy, security, or maintenance.
- Use at your own risk. The maintainers of this fork are not responsible for any issues, damages, or liabilities arising from its usage.
- This project should not be considered official or endorsed by the original authors.
- If you require the official version, please refer to the original source or verified community releases.
minimist-string
minimist-string is a minimist wrapper that is able to pasrse command line sentences as strings. The problem with minimist is that you need to give the arguments in an array with every argument in separated strings (as in node's process.argv). The following wouldn't work:
console.log(minimist(['foo --bar "Hello!"']));
// { _: [ 'foo --bar "Hello!"' ] } wich is not what we wantThe next logical step is doing:
console.log(minimist('foo --bar "Hello!"'.split(' ')));
// { _: [ 'foo' ], bar: '"Hello!"' }That actually returns what we expect. The problem comes when the user-defined string has spaces:
console.log(minimist('foo --bar "Hello world!"'.split(' ')));
// { _: [ 'foo', 'world!"' ], bar: '"Hello' }Only "Hello gets to the bar parameter, while the rest of it gets to argv._, wich is a disaster. minimist-string solves this problem:
Usage
npm install --save minimist-stringconst parseSentence = require('minimist-string');
console.log(parseSentence('foo --bar "Hello world!"'));
// { _: [ 'foo' ], bar: 'Hello world!' }It even works with escaped quotes!
console.log(parseSentence('foo --bar "Hello \\"world\\"!"'));
// { _: [ 'foo' ], bar: 'Hello "world"!' }