index.js 387 B

12345678910111213141516171819
  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. };