Skip to content

Home

Check if process arguments contain flags

Checks if the current process's arguments contain the specified flags.

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

More like this

Start typing a keyphrase to see matching snippets.