diff --git a/types/shelljs/index.d.ts b/types/shelljs/index.d.ts index 0301f2c1e0..7557ddae22 100644 --- a/types/shelljs/index.d.ts +++ b/types/shelljs/index.d.ts @@ -6,6 +6,7 @@ // Paul Huynh // Alexander Futász // ExE Boss +// Mirco Sanguineti // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -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 diff --git a/types/shelljs/make.d.ts b/types/shelljs/make.d.ts index b6b6f99fa9..652b0cfb45 100644 --- a/types/shelljs/make.d.ts +++ b/types/shelljs/make.d.ts @@ -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; } diff --git a/types/shelljs/shelljs-tests.ts b/types/shelljs/shelljs-tests.ts index 37d8933e39..b7b7afc5b1 100644 --- a/types/shelljs/shelljs-tests.ts +++ b/types/shelljs/shelljs-tests.ts @@ -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']);