Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jimmycuadra/shellwords
Manipulate strings according to the word parsing rules of the UNIX Bourne shell.
https://github.com/jimmycuadra/shellwords
commonjs commonjs-module commonjs-modules esm esmodule esmodules javascript nodejs shell shellwords typescript
Last synced: 3 days ago
JSON representation
Manipulate strings according to the word parsing rules of the UNIX Bourne shell.
- Host: GitHub
- URL: https://github.com/jimmycuadra/shellwords
- Owner: jimmycuadra
- License: mit
- Created: 2011-11-13T07:33:06.000Z (about 13 years ago)
- Default Branch: main
- Last Pushed: 2022-10-17T07:33:13.000Z (over 2 years ago)
- Last Synced: 2025-01-14T05:09:07.328Z (11 days ago)
- Topics: commonjs, commonjs-module, commonjs-modules, esm, esmodule, esmodules, javascript, nodejs, shell, shellwords, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/shellwords
- Size: 81.1 KB
- Stars: 38
- Watchers: 4
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://docs.ruby-lang.org/en/3.1/Shellwords.html).
## Installation
With npm:
```
npm install shellwords
```With pnpm:
```
pnpm add 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
``` typescript
import { escape, split } from "shellwords";split("foo 'bar baz'");
// ["foo", "bar baz"]escape("What's up, yo?");
// 'What\\\'s\\ up,\\ yo\\?'
```## Legal
shellwords is released under the MIT license. See `LICENSE`.