What is it?
string-to-argv
parses a command line string into an argument array to mimic process.argv
.
Why
It's written as a robust replacement to string-argv. string-to-argv
can properly handle nested quotes to parse strings like curl -d "{ \"projectId\": 1, \"locale\": \"en\" }"
. It also provides bundled typescript
definitions.
Installation
npm install string-to-argv
Usage
// ES6;// Node.js// const parseArgvString = require('string-to-argv'); const argv = ; console;/*[ 'curl', 'https://example.com', '-X', 'POST', '--data', '{ "projectId": 1, "locale": "en" }', '--cookie', 'USER_NAME=O\'Connor']*/