UNPKG

1.18 kBMarkdownView Raw
1# Shellwords
2
3Shellwords provides functions to manipulate strings according to the word parsing rules of the UNIX Bourne shell. It is based on [the Ruby module of the same name](https://docs.ruby-lang.org/en/3.1/Shellwords.html).
4
5## Installation
6
7With npm:
8
9```
10npm install shellwords
11```
12
13With Yarn:
14
15```
16yarn add shellwords
17```
18
19## API
20
21Shellwords exports the following functions, shown here in the TypeScript declaration file format.
22
23``` typescript
24/**
25 * Splits a string into an array of tokens in the same way the UNIX Bourne shell does.
26 *
27 * @param line A string to split.
28 * @returns An array of the split tokens.
29 */
30export declare const split: (line?: string) => string[];
31
32/**
33 * Escapes a string so that it can be safely used in a Bourne shell command line.
34 *
35 * @param str A string to escape.
36 * @returns The escaped string.
37 */
38export declare const escape: (str?: string) => string;
39```
40
41## Example
42
43``` typescript
44import { escape, split } from "shellwords";
45
46shellwords.split("foo 'bar baz'");
47// ["foo", "bar baz"]
48
49shellwords.escape("What's up, yo?");
50// 'What\\\'s\\ up,\\ yo\\?'
51```
52
53## Legal
54
55shellwords is released under the MIT license. See `LICENSE`.