UNPKG

split-cmd

Version:

💦Split a command into an array or an object

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