shebang-regex
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The shebang-regex
NPM package provides a regular expression specifically for matching a Shebang line in text. Shebang lines are meta-syntax lines found at the top of scripts in Unix-based systems, and play a vital role in specifying the interpreter for script execution. It's a popular tool among developers dealing with Unix-like environments.
Using shebang-regex
is simple and straightforward. After installing it using npm by running npm install shebang-regex
, you can readily import it into your JavaScript file with the line import shebangRegex from 'shebang-regex';
.
Here's an example with a string starting with a Shebang line, which this package helps you identify:
import shebangRegex from 'shebang-regex';
const string = '#!/usr/bin/env node\nconsole.log("unicorns");';
// Test if the string contains a shebang
console.log(shebangRegex.test(string)); // true
// Extract the shebang line
console.log(shebangRegex.exec(string)[0]); // '#!/usr/bin/env node'
// Extract the path of the shebang
console.log(shebangRegex.exec(string)[1]); // '/usr/bin/env node'
In this example, we use .test()
to check whether the string contains a shebang, and .exec()
to extract either the entire shebang line or its path specifically.
The documentation for the shebang-regex
package can be found directly in its README file on GitHub. The readme, located at https://github.com/sindresorhus/shebang-regex
, contains all necessary information on how to install and use the package. There are no separate docs for shebang-regex
. As it's designed to serve a specific and simple function, the README on GitHub provides the most complete and relevant documentation for the tool.