-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa77584
commit d3373d5
Showing
1 changed file
with
37 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,55 @@ | ||
# Shellwords | ||
|
||
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](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/shellwords/rdoc/Shellwords.html). | ||
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). | ||
|
||
## Installation | ||
|
||
Add "shellwords" to your `package.json` file and run `npm install`. | ||
With npm: | ||
|
||
``` | ||
npm install shellwords | ||
``` | ||
|
||
With Yarn: | ||
|
||
``` | ||
yarn add shellwords | ||
``` | ||
|
||
## API | ||
|
||
Shellwords exports the following functions, shown here in the TypeScript declaration file format. | ||
|
||
``` typescript | ||
/** | ||
* Splits a string into an array of tokens in the same way the UNIX Bourne shell does. | ||
* | ||
* @param line A string to split. | ||
* @returns An array of the split tokens. | ||
*/ | ||
export declare const split: (line?: string) => string[]; | ||
|
||
/** | ||
* Escapes a string so that it can be safely used in a Bourne shell command line. | ||
* | ||
* @param str A string to escape. | ||
* @returns The escaped string. | ||
*/ | ||
export declare const escape: (str?: string) => string; | ||
``` | ||
|
||
## Example | ||
|
||
``` javascript | ||
var shellwords = require("shellwords"); | ||
``` typescript | ||
import { escape, split } from "shellwords"; | ||
|
||
shellwords.split("foo 'bar baz'"); | ||
// ["foo", "bar baz"] | ||
|
||
shellwords.escape("What's up, yo?"); | ||
// 'What\\\'s\\ up,\\ yo\\?' | ||
``` | ||
|
||
## Legal | ||
|
||
shellwords is released under the MIT license. See `LICENSE`. |