UNPKG

has-flag

Version:
9 lines (7 loc) 407 B
import process from 'process'; // eslint-disable-line node/prefer-global/process export default function hasFlag(flag, argv = process.argv) { const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--'); const position = argv.indexOf(prefix + flag); const terminatorPosition = argv.indexOf('--'); return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition); }