package
Manipulate strings according to the word parsing rules of the UNIX Bourne shell.
npm install shellwordsGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
17.9 kB
Includes dependencies.
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.
With npm:
npm install shellwordsWith pnpm:
pnpm add shellwordsWith Yarn:
yarn add shellwordsShellwords exports the following functions, shown here in the TypeScript declaration file format.
/**
* 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;
/**
* Builds a command line string from an argument list.
import { escape, split, join } from "shellwords";
split("foo 'bar baz'");
// ["foo", "bar baz"]
escape("What's up, yo?");
// 'What\\\'s\\ up,\\ yo\\?'
join(["What's", "up,", "gang?");
// 'What\\\'s up, gang\\?'shellwords is released under the MIT license. See LICENSE.