1 | # Shellwords
|
2 |
|
3 | Shellwords 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 |
|
7 | With npm:
|
8 |
|
9 | ```
|
10 | npm install shellwords
|
11 | ```
|
12 |
|
13 | With Yarn:
|
14 |
|
15 | ```
|
16 | yarn add shellwords
|
17 | ```
|
18 |
|
19 | ## API
|
20 |
|
21 | Shellwords 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 | */
|
30 | export 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 | */
|
38 | export declare const escape: (str?: string) => string;
|
39 | ```
|
40 |
|
41 | ## Example
|
42 |
|
43 | ``` typescript
|
44 | import { escape, split } from "shellwords";
|
45 |
|
46 | shellwords.split("foo 'bar baz'");
|
47 | // ["foo", "bar baz"]
|
48 |
|
49 | shellwords.escape("What's up, yo?");
|
50 | // 'What\\\'s\\ up,\\ yo\\?'
|
51 | ```
|
52 |
|
53 | ## Legal
|
54 |
|
55 | shellwords is released under the MIT license. See `LICENSE`.
|