UNPKG

split-cmd

Version:

💦Split a command into an array or an object

2 lines (1 loc) • 402 B
function t(t){if("string"!=typeof t)throw new Error("Command must be a string");var r=t.match(/[^"\s]+|"(?:\\"|[^"])*"/g);return r?r.map(function(t){return'"'===t.charAt(0)&&'"'===t.charAt(t.length-1)?t.slice(1,-1):t}):[]}exports.split=t,exports.splitToObject=function(r){var n=t(r);switch(n.length){case 0:return{};case 1:return{command:n[0]};default:var e=n[0];return n.shift(),{command:e,args:n}}};