string-to-argv

string-to-argv is a tool to parse command line string into an argument array to mimic `process.argv`

Usage no npm install needed!

<script type="module">
  import stringToArgv from 'https://cdn.skypack.dev/string-to-argv';
</script>

README

npm Build Status Coverage Status dependencies Status devDependencies Status GitHub license

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
import parseArgvString from 'string-to-argv';
// Node.js
// const parseArgvString = require('string-to-argv');

const argv = parseArgvString(`curl "https://example.com" -X POST --data "{ \\"projectId\\": 1, \\"locale\\": \\"en\\" }" --cookie "USER_NAME=O'Connor"`);

console.log(argv);
/*
[
    'curl',
    'https://example.com',
    '-X',
    'POST',
    '--data',
    '{ "projectId": 1, "locale": "en" }',
    '--cookie',
    'USER_NAME=O\'Connor'
]
*/