Parse a string into an argument array, do the job like process.argv
for us.
This is a fork from string-argv, changes in this fork:
- export extra
string2argv
&str2argv
aliases. - change
export { xx as default }
toexport default xx
. - compatible with both ESM and CJS (by the change above).
ESM
import { string2argv } from 'string2argv'
const commandLineString = 'echo a b c -rvf --name "demo name"'
// output: [ 'echo', 'a', 'b', 'c', '-rvf', '--name', 'demo name' ]
console.log(string2argv(commandLineString))
CJS
const { default: string2argv } = require('string2argv')
const commandLineString = 'echo a b c -rvf --name "demo name"'
// output: [ 'echo', 'a', 'b', 'c', '-rvf', '--name', 'demo name' ]
console.log(string2argv(commandLineString))