string-to-argv
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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'
]
*/

Readme

Keywords

Package Sidebar

Install

npm i string-to-argv

Weekly Downloads

84

Version

1.0.0

License

ISC

Unpacked Size

10.2 kB

Total Files

5

Last publish

Collaborators

  • vladimir-tikhonov