Merge pull request #34683 from msanguineti/shelljs

[shelljs] Added construct and function signatures for shelljs/ShellString
This commit is contained in:
Benjamin Lichtman
2019-04-15 09:43:27 -07:00
committed by GitHub
3 changed files with 53 additions and 0 deletions

View File

@@ -6,6 +6,7 @@
// Paul Huynh <https://github.com/pheromonez>
// Alexander Futász <https://github.com/aldafu>
// ExE Boss <https://github.com/ExE-Boss>
// Mirco Sanguineti <https://github.com/msanguineti>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node"/>
@@ -965,6 +966,51 @@ export type ShellString = string & ShellReturnValue;
export type ShellArray = string[] & ShellReturnValue;
export interface ShellStringConstructor {
/**
* Wraps a string (or array) value. This has all the string (or array) methods,
* but also exposes extra methods: `.to()`, `.toEnd()`, and all the pipe-able
* methods (ex. `.cat()`, `.grep()`, etc.).
*
* This can be easily converted into a string by calling `.toString()`.
*
* This type also exposes the corresponding command's stdout, stderr, and return status
* code via the `.stdout` (string), `.stderr` (string), and `.code` (number) properties
* respectively.
*
* Construct signature allows for:
*
* var foo = new ShellString('hello world');
*
* as per example in shelljs docs:
* https://github.com/shelljs/shelljs#shellstringstr
*
* @param value The string value to wrap.
* @return A string-like object with special methods.
*/
new(value: string): ShellString;
new(value: string[]): ShellArray;
/**
* Wraps a string (or array) value. This has all the string (or array) methods,
* but also exposes extra methods: `.to()`, `.toEnd()`, and all the pipe-able
* methods (ex. `.cat()`, `.grep()`, etc.).
*
* This can be easily converted into a string by calling `.toString()`.
*
* This type also exposes the corresponding command's stdout, stderr, and return status
* code via the `.stdout` (string), `.stderr` (string), and `.code` (number) properties
* respectively.
*
* @param value The string value to wrap.
* @return A string-like object with special methods.
*/
(value: string): ShellString;
(value: string[]): ShellArray;
}
export const ShellString: ShellStringConstructor;
export interface ChmodFunction {
/**
* Alters the permissions of a file or directory by either specifying the absolute

View File

@@ -39,4 +39,5 @@ declare global {
const tempdir: typeof shelljs.tempdir;
const touch: typeof shelljs.touch;
const uniq: typeof shelljs.uniq;
const ShellString: typeof shelljs.ShellString;
}

View File

@@ -196,3 +196,9 @@ shell
.ls("dir")
.grep(/^stuff/)
.head({"-n": 5}).stdout;
const foo = new shell.ShellString('hello world');
const farr = new shell.ShellString(['hello', 'world']);
const boo = shell.ShellString('hello world');
const barr = shell.ShellString(['hello', 'world']);