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.

MIT 10 个版本
安装
npm install string-argv
yarn add string-argv
pnpm add string-argv
bun add string-argv
README

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.

版本列表
0.3.2 2023-05-01
0.3.1 2019-08-29
0.3.0 2019-04-16
0.2.1 2019-04-16
0.2.0 2019-04-14
0.1.2 2019-03-11
0.1.1 2018-08-05
0.1.0 2018-07-31
0.0.2 2016-03-11
0.0.1 2014-02-04