UNPKG

split-cmd

Version:

💦Split a command into an array or an object

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