You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
387 B

4 years ago
  1. 'use strict';
  2. const shebangRegex = require('shebang-regex');
  3. module.exports = (string = '') => {
  4. const match = string.match(shebangRegex);
  5. if (!match) {
  6. return null;
  7. }
  8. const [path, argument] = match[0].replace(/#! ?/, '').split(' ');
  9. const binary = path.split('/').pop();
  10. if (binary === 'env') {
  11. return argument;
  12. }
  13. return argument ? `${binary} ${argument}` : binary;
  14. };