has-flag
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
"Has-flag" is a handy npm package primarily used to ascertain if a specific flag is present within your Node.js command line arguments - known as argv
. It's a convenience function that operates correctly even when an argument terminator --
is exposed.
To integrate "has-flag" in your application or script, first, make sure to have it installed via the Node Package Manager (npm) using the following command:
$ npm install has-flag
After successfully installing, you can import it into your JavaScript file and leverage its functionality. Below are representative examples of how you may use "has-flag":
// Importing hasFlag into your file
import hasFlag from 'has-flag';
// Usage
hasFlag('unicorn'); // returns true if the 'unicorn' flag is present in the argv
hasFlag('--unicorn'); // similar to the above example, the '--' prefix is optional
hasFlag('f'); // returns true if the 'f' flag is present in the argv
hasFlag('-f'); // similar to the above example, the '-' prefix is optional
hasFlag('foo=bar'); // returns true if the 'foo=bar' flag is present in the argv
hasFlag('foo'); // returns false if 'foo' does not exist in the arguments
hasFlag('rainbow'); // returns false if 'rainbow' does not exist in the arguments
You can pass in the flags when running your script:
$ node foo.js -f --unicorn --foo=bar -- --rainbow
The "has-flag" package will determine the presence or absence of a flag and return a boolean accordingly.
The official documentation for the "has-flag" package is provided directly within its GitHub repository's README file. Here, you can find usage examples, installation instructions, and an outline of the API for this npm package. If you want more professional and sustainably-maintained support for this package, the Tidelift subscription link within the README can be an excellent resource.