UNPKG

1.45 kBMarkdownView Raw
1# command-join
2
3Escape command-line arguments, cross-platform.
4
5[![npm](https://img.shields.io/npm/v/command-join.svg?style=flat-square)](https://www.npmjs.com/package/command-join)
6[![Build Status](https://img.shields.io/travis/seangenabe/command-join/master.svg?style=flat-square)](https://travis-ci.org/seangenabe/command-join)
7[![devDependency Status](https://img.shields.io/david/dev/seangenabe/command-join.svg?style=flat-square)](https://david-dm.org/seangenabe/command-join#info=devDependencies)
8[![node](https://img.shields.io/node/v/command-join.svg?style=flat-square)](https://nodejs.org/en/download/)
9
10If you like this package, be sure to star its repo, and please consider [donating](https://seangenabe.netlify.com/donate).
11
12## Usage
13
14```typescript
15import { commandJoin } from "command-join"
16```
17
18### `commandJoin(arg: string | string[]): string`
19
20Escapes each command-line argument and joins them into a string that can then be executed, e.g. via `child_process.exec`.
21
22If a string is passed, an array containing the string will instead be processed.
23
24**Example**
25
26```javascript
27const command = commandJoin(['a', "b\\", "'c"])
28command
29// output on Windows: a "b\\" 'c
30// output on Linux: a 'b\' \'c
31```
32
33See the tests for more convoluted examples.
34
35## Migrating
36
37**Migrating to v3**:
38```diff
39- const commandJoin = require("command-join")
40+ const { commandJoin } = require("command-join")
41```