Socket
Book a DemoInstallSign in
Socket

unparse-args

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unparse-args

Unparse parsed arguments back to the original argv array or a command string.

latest
Source
npmnpm
Version
1.2.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

unparse-args

Build Status

A Node module to help you unparse parsed arguments back to the original argv array or a command string.

This module will:

  • unparse parsed arguments back to an argv array
  • easily regenerate a command string based on the unparsed array
  • work with yargs, minimist, and subarg (also handles subcontexts)

Use Scenario

Imagine a hypothetical command string with flags, subcommands, options... etc:

node example.js another --number 297261 -t something -x 'something longer than just 1 word' -a -e

Popular argument parsing modules for Node: yargs, subarg, and minimist all parse these into an object like:

var args = { 
    _: [ 'node', '/Users/arjun/example/example.js', 'another' ],
    number: 297261,
    t: 'something',
    x: 'something longer than just 1 word',
    a: true,
    e: true
};

But we might want to manipulate it and flatten it out again to be like:

['node', '/Users/arjun/example/example.js', 'another', '--number', '297261', '-t', 'something', '-x', 'something longer than just 1 word', '-a', '-e']

Installation

npm install --save unparse-args

Basic Usage

Include

var unparse = require('unparse-args');

Assume some parsed arguments.

var parsed = subarg(process.argv);
// OR
var parsed = minimist(process.argv);
// OR
var parsed = yargs.parse(process.argv);

Unparse Parsed Arguments

Easily unparse them into an array.

var unparsed = unparse(parsed)
console.log(unparsed); // ['node', 'example.js', 'another', '--number', '297261', '-t', 'something', '-x', 'something longer than just 1 word', '-a', '-e']

Convert Arg Array to Command String

var command_string = unparsed.command_string;
console.log(command_string); // node example.js another --number 297261 -t something -x 'something longer than just 1 word' -a -e

I know I know, unparsed is an array, so how can it have a property?? Magic.

License

The MIT License (MIT) Copyright (c) 2014 Arjun Mehta

Keywords

command

FAQs

Package last updated on 19 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts