UNPKG

1.94 kBTypeScriptView Raw
1// Type definitions for shell-quote 1.7
2// Project: https://github.com/substack/node-shell-quote
3// Definitions by: Jason Cheatham <https://github.com/jason0x43>
4// Cameron Diver <https://github.com/CameronDiver>
5// Opportunity Liu <https://github.com/OpportunityLiu>
6// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7// TypeScript Version: 2.2
8
9export type ControlOperator = '||' | '&&' | ';;' | '|&' | '<(' | '>>' | '>&' | '&' | ';' | '(' | ')' | '|' | '<' | '>';
10
11export type ParseEntry =
12 | string
13 | { op: ControlOperator }
14 | { op: 'glob'; pattern: string }
15 | { comment: string };
16
17export interface ParseOptions {
18 /**
19 * Custom escape character, default value is `\`
20 */
21 escape?: string;
22}
23
24/**
25 * Return a quoted string for the array `args` suitable for using in shell commands.
26 */
27export function quote(args: ReadonlyArray<string>): string;
28
29/**
30 * Return an array of arguments from the quoted string `cmd`.
31 *
32 * Interpolate embedded bash-style `$VARNAME` and `${VARNAME}` variables with the `env` object which like bash will replace undefined variables with `""`.
33 */
34export function parse(
35 cmd: string,
36 env?: { readonly [key: string]: string | undefined },
37 opts?: ParseOptions,
38): ParseEntry[];
39
40/**
41 * Return an array of arguments from the quoted string `cmd`.
42 *
43 * Interpolate embedded bash-style `$VARNAME` and `${VARNAME}` variables
44 * with the `env` object which like bash will replace undefined variables with `""`.
45 *
46 * @param env
47 * A function to perform lookups.
48 * When env(key) returns a string, its result will be output just like env[key] would.
49 * When env(key) returns an object, it will be inserted into the result array like the operator objects.
50 */
51export function parse<T extends object | string>(
52 cmd: string,
53 env: (key: string) => T | undefined,
54 opts?: ParseOptions,
55): Array<ParseEntry | T>;