I need to interpret some of my commandline arguments (using minimist) as string instead of int. Minimist provides and option to pass an array of commandline arguments you wish to consider as strings.
Something like this:
var args = minimist(process.argv.slice(2), {
"string": [ "abc-src" ]
});
What I want to do is something like this:
var args = minimist(process.argv.slice(2), {
"string": [ /^*-src/ ]
});
Is there a way to do this?
You can use the unknown option to parse the arguments:
const minimist = require('minimist');
const args = minimist(process.argv.slice(2), {
"unknown": (arg) => { /^.*-src$/.test(arg) }
});
console.log(args);
With the following:
node index --foo-src=bar --bar-src=foo
It returns the following:
{ _: [], 'foo-src': 'bar', 'bar-src': 'foo' }
Hope that helps