1.0.0 • Published 3 years ago

command-line-string-parser v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

Command-line string parser

A function to pass a string to a child nodejs process via command-line to parse it then return it back as an array of arguments.

Installation

npm install command-line-string-parser

Usage

The parser returns a promise that resolves with an array of arguments using nodejs' process.argv mechanism. This treats both "double-quoted" , 'single-quoted', and "quoted with spaces" arguments as a single entry to the argument list.

const parser = require ( 'command-line-string-parser' ) ;

parser ( '"argument 1 (quoted)" argument2unquoted' ) ; //returns a promise

The child nodejs process command:

node ./commandparser.js "argument 1 (quoted)" argument2unquoted
const parser = require ( 'command-line-string-parser' ) ;

var parsePromise = parser . parse ( '"argument 1 (quoted)" argument2unquoted' ) ;

parsePromise . then ( ( CommandArgument ) => {
    console . log ( CommandArgument ) // [ "argument 1 (quoted)" , "argument2unquoted" ] ;
} ) ;
1.0.1

3 years ago

1.0.0

3 years ago