Socket
Socket
Sign inDemoInstall

string-argv

Package Overview
Dependencies
0
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    string-argv

string-argv parses a string into an argument array to mimic process.argv. This is useful when testing Command Line Utilities that you want to pass arguments to.


Version published
Weekly downloads
11M
increased by0.02%
Maintainers
2
Install size
6.68 kB
Created
Weekly downloads
 

Package description

What is string-argv?

The string-argv npm package is used to parse string representations of command-line arguments into an array format, similar to how the arguments would be received in a Node.js script when running from the command line. It can handle quoted arguments, escaped characters, and supports both single and double quotes.

What are string-argv's main functionalities?

Parsing command-line argument strings

This feature allows you to convert a string that represents command-line arguments into an array of arguments, as they would appear in process.argv in a Node.js application.

const parseArgs = require('string-argv');
const args = parseArgs('node app.js --option=value "argument with spaces"');
console.log(args);

Other packages similar to string-argv

Changelog

Source

v0.3.1 (2022-09-16)

  • Now provides both esm and cjs builds
  • Update TypeScript to 4.8.3

Readme

Source

What is it?

string-argv parses a string into an argument array to mimic process.argv. This is useful when testing Command Line Utilities that you want to pass arguments to and is the opposite of what the other argv utilities do.

Installation

npm install string-argv --save

Usage

// Typescript
import stringArgv from 'string-argv';

const args = stringArgv(
  '-testing test -valid=true --quotes "test quotes" "nested \'quotes\'" --key="some value" --title="Peter\'s Friends"',
  'node',
  'testing.js'
);

console.log(args);
// Javascript
var { parseArgsStringToArgv } = require('string-argv');

var args = parseArgsStringToArgv(
    '-testing test -valid=true --quotes "test quotes" "nested \'quotes\'" --key="some value" --title="Peter\'s Friends"',
    'node',
    'testing.js'
);

console.log(args);
/** output
[ 'node',
  'testing.js',
  '-testing',
  'test',
  '-valid=true',
  '--quotes',
  'test quotes',
  'nested \'quotes\'',
  '--key="some value"',
  '--title="Peter\'s Friends"' ]
  **/

params

required: arguments String: arguments that you would normally pass to the command line.

optional: environment String: Adds to the environment position in the argv array. If ommitted then there is no need to call argv.split(2) to remove the environment/file values. However if your cli.parse method expects a valid argv value then you should include this value.

optional: file String: file that called the arguments. If omitted then there is no need to call argv.split(2) to remove the environment/file values. However if your cli.parse method expects a valid argv value then you should include this value.

Keywords

FAQs

Last updated on 29 Aug 2019

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc