We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(This is a bring-your-own-feature experiment, not a prototype of parseArgs implementation.)
Inspired by discussion in #62. How could I add my own support for options and positionals treating negative numbers as ordinary args and not options?
const { parseArgs } = require('@pkgjs/parseArgs'); const kNegativePrefix = 'parseArgs.NEGATIVE:'; // preprocess const rawArgs = process.argv.slice(2); const preparedArgs = rawArgs.map(arg => /^-[0-9]+/.test(arg) ? kNegativePrefix.concat(arg) : arg); const result = parseArgs({ args: preparedArgs, { options: { profit: { type: 'string' }} }); // postprocess const stripPrefix = (arg) => arg.startsWith(kNegativePrefix) ? arg.slice(kNegativePrefix.length) : arg; result.positionals = result.positionals.map(arg => stripPrefix(arg)); Object.entries(result.values).forEach(([key, value]) => { if (typeof value === 'string') result.values[key] = stripPrefix(value); }); console.log(result);
% node index.js --profit 33 44 { flags: { profit: true }, values: { profit: '33' }, positionals: [ '44' ] } % node index.js --profit -33 -44 { flags: { profit: true }, values: { profit: '-33' }, positionals: [ '-44' ] }
The text was updated successfully, but these errors were encountered:
This hasn't attracted any interest, and there hasn't been any further discussions about number processing. Closing as insufficiently interesting. 😴
Sorry, something went wrong.
No branches or pull requests
(This is a bring-your-own-feature experiment, not a prototype of parseArgs implementation.)
Inspired by discussion in #62. How could I add my own support for options and positionals treating negative numbers as ordinary args and not options?
The text was updated successfully, but these errors were encountered: