Array.prototype.every()
and Array.prototype.includes()
to check if process.argv
contains all the specified flags.-
or --
and prefix them accordingly.const hasFlags = (...flags) =>
flags.every(flag =>
process.argv.includes(/^-{1,2}/.test(flag) ? flag : '--' + flag)
);
// node myScript.js -s --test --cool=true
hasFlags('-s'); // true
hasFlags('--test', 'cool=true', '-s'); // true
hasFlags('special'); // false
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️