command-join
Version:
Escape and join command-line arguments, cross-platform.
42 lines (28 loc) • 1.45 kB
Markdown
# command-join
Escape command-line arguments, cross-platform.
[](https://www.npmjs.com/package/command-join)
[](https://travis-ci.org/seangenabe/command-join)
[](https://david-dm.org/seangenabe/command-join#info=devDependencies)
[](https://nodejs.org/en/download/)
If you like this package, be sure to star its repo, and please consider [donating](https://seangenabe.netlify.com/donate).
## Usage
```typescript
import { commandJoin } from "command-join"
```
### `commandJoin(arg: string | string[]): string`
Escapes each command-line argument and joins them into a string that can then be executed, e.g. via `child_process.exec`.
If a string is passed, an array containing the string will instead be processed.
**Example**
```javascript
const command = commandJoin(['a', "b\\", "'c"])
command
// output on Windows: a "b\\" 'c
// output on Linux: a 'b\' \'c
```
See the tests for more convoluted examples.
## Migrating
**Migrating to v3**:
```diff
- const commandJoin = require("command-join")
+ const { commandJoin } = require("command-join")
```