https://github.com/seangenabe/command-join
Escape and join command-line arguments. Cross-platform.
https://github.com/seangenabe/command-join
argv cli command command-line cross-platform escape join shell
Last synced: 7 months ago
JSON representation
Escape and join command-line arguments. Cross-platform.
- Host: GitHub
- URL: https://github.com/seangenabe/command-join
- Owner: seangenabe
- License: mit
- Created: 2015-12-05T19:19:18.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-05-23T08:15:12.000Z (about 6 years ago)
- Last Synced: 2024-04-25T00:34:07.524Z (about 1 year ago)
- Topics: argv, cli, command, command-line, cross-platform, escape, join, shell
- Language: TypeScript
- Size: 32.2 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# 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")
```