All files parse-cmd.js

100% Statements 22/22
96.43% Branches 27/28
100% Functions 1/1
100% Lines 22/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44    2x 64x 31x   64x 1x     63x     63x 2x 2x     63x 20x     63x 20x 20x     63x   63x 63x 18x   63x 18x     63x     2x      
"use strict";
 
const parseCmd = (params = []) => {
  if (typeof params === "string") {
    params = params.split(" ");
  }
  if (!Array.isArray(params)) {
    throw new TypeError(`${params} should be an array or a string`);
  }
 
  params = [...params];
 
  // remove both '/usr/local/bin/node' and the script itself
  if (params.length && params[0].endsWith("bin/node")) {
    params.shift();
    params.shift();
  }
  // remove nprr
  if (params.length && params[0] === "nprr") {
    params.shift();
  }
  // remove npm run
  if (params.length > 1 && params[0] === "npm" && params[1] === "run") {
    params.shift();
    params.shift();
  }
 
  let [scriptName, ...options] = params;
 
  const optionsSeparator = "--";
  if (scriptName === optionsSeparator) {
    scriptName = undefined;
  }
  if (Array.isArray(options) && options[0] === optionsSeparator) {
    options.shift();
  }
 
  return { scriptName: scriptName || "", options: options || [] };
};
 
module.exports = {
  parseCmd
};