# 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.

Latest version **0.3.2** (published 2023-05-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install string-argv
pnpm add string-argv
yarn add string-argv
bun add string-argv
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2023-05-01 |
| First published | 2014-02-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=0.6.19 |
| Dependencies | 0 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 63 |
| Author | Anthony McCormick |
| Maintainers | mccormicka, cellule |
| Keywords | argv |

## Links

- npm: https://www.npmjs.com/package/string-argv
- Repository: https://github.com/mccormicka/string-argv
- Issues: https://github.com/mccormicka/string-argv/issues
- npm.io page: https://npm.io/package/string-argv

## Recent versions

- 0.3.2 (latest) — 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

## 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

```ts
// 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);
```

```js
// 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.

---
_Source: https://npm.io/package/string-argv · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
