UNPKG

poku

Version:

🐷 Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.

41 lines (40 loc) 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hasOnly = exports.argToArray = exports.getPaths = exports.hasArg = exports.getArg = void 0; const node_process_1 = require("process"); const [, , ...processArgs] = node_process_1.argv; const regexQuotes = /''|""/; const getArg = (arg, prefix = '--', baseArgs = processArgs) => { const argPattern = `${prefix}${arg}=`; const argValue = baseArgs.find((a) => a.startsWith(argPattern)); if (!argValue) return; return argValue.slice(argPattern.length).replace(regexQuotes, ''); }; exports.getArg = getArg; const hasArg = (arg, prefix = '--', baseArgs = processArgs) => baseArgs.some((a) => a.startsWith(`${prefix}${arg}`)); exports.hasArg = hasArg; const getPaths = (prefix = '--', baseArgs = processArgs) => { let hasPaths = false; const paths = []; for (const arg of baseArgs) { if (arg.startsWith(prefix)) continue; if (!hasPaths) hasPaths = true; paths.push(arg); } return hasPaths ? paths : undefined; }; exports.getPaths = getPaths; const argToArray = (arg, prefix = '--', baseArgs = processArgs) => { const hasArgument = (0, exports.hasArg)(arg, prefix, baseArgs); if (!hasArgument) return; const argValue = (0, exports.getArg)(arg, prefix, baseArgs); if (!argValue) return []; return argValue.split(',').filter((a) => a); }; exports.argToArray = argToArray; exports.hasOnly = (0, exports.hasArg)('only');