From 7b098c46b6079ff74c8160a919225e52f28bdd70 Mon Sep 17 00:00:00 2001 From: "Gustavo R. 'Gustavo6046' Rehermann" Date: Tue, 30 Oct 2018 19:55:35 -0300 Subject: [PATCH] Fixed typings to export a function namespace. --- types/ansi/ansi-tests.ts | 7 +- types/ansi/ansi.d.ts | 188 --------------------------------------- types/ansi/index.d.ts | 159 +++++++++++++++++++++++++++++++++ types/ansi/tsconfig.json | 4 +- 4 files changed, 164 insertions(+), 194 deletions(-) delete mode 100644 types/ansi/ansi.d.ts create mode 100644 types/ansi/index.d.ts diff --git a/types/ansi/ansi-tests.ts b/types/ansi/ansi-tests.ts index d5d897dea3..c8e5669d3c 100644 --- a/types/ansi/ansi-tests.ts +++ b/types/ansi/ansi-tests.ts @@ -1,5 +1,4 @@ -import ansi = require('ansi'); - +import ansi from 'ansi'; const cursor = ansi(process.stdout); Object.keys({ @@ -21,5 +20,5 @@ Object.keys({ , brightCyan: 96 , brightWhite: 97 }).forEach((color) => { - cursor[color]().bold().write('Hello, bold ' + color.replace(/([a-z])([A-Z])/g, (_, l, u) => l + ' ' + u.toLowerCase()) + ' world!\n').reset(); -}); \ No newline at end of file + cursor[color]().bold().write(`Hello, bold ${color.replace(/([a-z])([A-Z])/g, (_: string, l: string, u: string): string => `${u} ${l.toLowerCase()}`)} world!\n`).reset(); +}); diff --git a/types/ansi/ansi.d.ts b/types/ansi/ansi.d.ts deleted file mode 100644 index 76c27e0a92..0000000000 --- a/types/ansi/ansi.d.ts +++ /dev/null @@ -1,188 +0,0 @@ -// Type definitions for ansi v0.3.1 -// Project: https://www.npmjs.com/package/ansi -// Definitions by: Gustavo6046 https://github.com/Gustavo6046 -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module 'ansi'; - -/** - * References: - * - * - http://en.wikipedia.org/wiki/ANSI_escape_code - * - http://www.termsys.demon.co.uk/vtansi.htm - * - */ - - -/** - * Creates a Cursor instance based off the given `writable stream` instance. - */ - -declare function ansi(stream: Cursor, options?: Object) : Cursor; - -/** - * The `Cursor` class. - */ - -declare class Cursor { - constructor(stream: Cursor, options?: Object); - - /** - * Helper function that calls `write()` on the underlying Stream. - * Returns `this` instead of the write() return value to keep - * the chaining going. - */ - write(data: string) : Cursor; - - /** - * Buffer `write()` calls into memory. - * - * @api public - */ - buffer() : Cursor; - - /** - * Write out the in-memory buffer. - * - * @api public - */ - flush() : Cursor; - - /** - * Makes a beep sound! - */ - beep() : Cursor; - - /** - * Moves cursor to specific position - */ - goto(x?: number, y?: number) : Cursor; - - /** - * Resets all ANSI formatting on the stream. - */ - reset() : Cursor; - - /** - * Sets the foreground color with the given RGB values. - * The closest match out of the 216 colors is picked. - */ - rgb(r: number, g: number, b: number) : Cursor; - - /** - * Accepts CSS color codes for use with ANSI escape codes. - * For example: `#FF000` would be bright red. - */ - hex(color: string) : Cursor; - - up() : Cursor; - down() : Cursor; - forward() : Cursor; - back() : Cursor; - nextLine() : Cursor; - previousLine() : Cursor; - horizontalAbsolute() : Cursor; - eraseData() : Cursor; - eraseLine() : Cursor; - scrollUp() : Cursor; - scrollDown() : Cursor; - savePosition() : Cursor; - restorePosition() : Cursor; - queryPosition() : Cursor; - hide() : Cursor; - show() : Cursor; - - bold() : Cursor; - italic() : Cursor; - underline() : Cursor; - inverse() : Cursor; - resetbold() : Cursor; - resetitalic() : Cursor; - resetunderline() : Cursor; - resetinverse() : Cursor; - - white() : Cursor; - black() : Cursor; - blue() : Cursor; - cyan() : Cursor; - green() : Cursor; - magenta() : Cursor; - red() : Cursor; - yellow() : Cursor; - grey() : Cursor; - brightBlack() : Cursor; - brightRed() : Cursor; - brightGreen() : Cursor; - brightYellow() : Cursor; - brightBlue() : Cursor; - brightMagenta() : Cursor; - brightCyan() : Cursor; - brightWhite() : Cursor; -} - -/** - * The `Colorer` class manages both the background and foreground colors. - */ -declare class Colorer { - constructor(cursor: Cursor, base: string); - - /** - * Write an ANSI color code, ensuring that the same code doesn't get rewritten. - */ - _setColorCode(code: string) : Colorer; - - /** - * Resets the color. - */ - reset() : Cursor; - - /** - * Sets the foreground color with the given RGB values. - * The closest match out of the 216 colors is picked. - */ - rgb(r: number, g: number, b: number) : Cursor; - - /** - * Accepts CSS color codes for use with ANSI escape codes. - * For example: `#FF000` would be bright red. - */ - hex(color: string) : Cursor; - - white() : Cursor; - black() : Cursor; - blue() : Cursor; - cyan() : Cursor; - green() : Cursor; - magenta() : Cursor; - red() : Cursor; - yellow() : Cursor; - grey() : Cursor; - brightBlack() : Cursor; - brightRed() : Cursor; - brightGreen() : Cursor; - brightYellow() : Cursor; - brightBlue() : Cursor; - brightMagenta() : Cursor; - brightCyan() : Cursor; - brightWhite() : Cursor; -} - -// UTIL FUNCTIONS // - -/** - * Translates a 255 RGB value to a 0-5 ANSI RGV value, - * then returns the single ANSI color code to use. - */ -declare function rgb(r: number, g: number, b: number) : number; - -/** - * Turns rgb 0-5 values into a single ANSI color code to use. - */ - -declare function rgb5(r: number, g: number, b: number) : number; - -/** - * Accepts a hex CSS color code string (# is optional) and - * translates it into an Array of 3 RGB 0-255 values, which - * can then be used with rgb(). - */ -declare function hex (color: string) : number[]; \ No newline at end of file diff --git a/types/ansi/index.d.ts b/types/ansi/index.d.ts new file mode 100644 index 0000000000..7dd597b3bc --- /dev/null +++ b/types/ansi/index.d.ts @@ -0,0 +1,159 @@ +// Type definitions for ansi 0.3 +// Project: https://www.npmjs.com/package/ansi +// Definitions by: Gustavo6046 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * References: + * + * - http://en.wikipedia.org/wiki/ANSI_escape_code + * - http://www.termsys.demon.co.uk/vtansi.htm + * + */ + +declare function ansi(stream: ansi.Cursor, options?: any): ansi.Cursor; + +declare namespace ansi { + class Cursor { + constructor(stream: Cursor, options?: any); + + /** + * Helper function that calls `write()` on the underlying Stream. + * Returns `this` instead of the write() return value to keep + * the chaining going. + */ + write(data: string): Cursor; + + /** + * Buffer `write()` calls into memory. + * + * @api public + */ + buffer(): Cursor; + + /** + * Write out the in-memory buffer. + * + * @api public + */ + flush(): Cursor; + + /** + * Makes a beep sound! + */ + beep(): Cursor; + + /** + * Moves cursor to specific position + */ + goto(x?: number, y?: number): Cursor; + + /** + * Resets all ANSI formatting on the stream. + */ + reset(): Cursor; + + /** + * Sets the foreground color with the given RGB values. + * The closest match out of the 216 colors is picked. + */ + rgb(r: number, g: number, b: number): Cursor; + + /** + * Accepts CSS color codes for use with ANSI escape codes. + * For example: `#FF000` would be bright red. + */ + hex(color: string): Cursor; + + up(): Cursor; + down(): Cursor; + forward(): Cursor; + back(): Cursor; + nextLine(): Cursor; + previousLine(): Cursor; + horizontalAbsolute(): Cursor; + eraseData(): Cursor; + eraseLine(): Cursor; + scrollUp(): Cursor; + scrollDown(): Cursor; + savePosition(): Cursor; + restorePosition(): Cursor; + queryPosition(): Cursor; + hide(): Cursor; + show(): Cursor; + + bold(): Cursor; + italic(): Cursor; + underline(): Cursor; + inverse(): Cursor; + resetbold(): Cursor; + resetitalic(): Cursor; + resetunderline(): Cursor; + resetinverse(): Cursor; + + white(): Cursor; + black(): Cursor; + blue(): Cursor; + cyan(): Cursor; + green(): Cursor; + magenta(): Cursor; + red(): Cursor; + yellow(): Cursor; + grey(): Cursor; + brightBlack(): Cursor; + brightRed(): Cursor; + brightGreen(): Cursor; + brightYellow(): Cursor; + brightBlue(): Cursor; + brightMagenta(): Cursor; + brightCyan(): Cursor; + brightWhite(): Cursor; + } + + /** + * The `Colorer` class manages both the background and foreground colors. + */ + class Colorer { + constructor(cursor: Cursor, base: string); + + /** + * Write an ANSI color code, ensuring that the same code doesn't get rewritten. + */ + _setColorCode(code: string): Colorer; + + /** + * Resets the color. + */ + reset(): Cursor; + + /** + * Sets the foreground color with the given RGB values. + * The closest match out of the 216 colors is picked. + */ + rgb(r: number, g: number, b: number): Cursor; + + /** + * Accepts CSS color codes for use with ANSI escape codes. + * For example: `#FF000` would be bright red. + */ + hex(color: string): Cursor; + + white(): Cursor; + black(): Cursor; + blue(): Cursor; + cyan(): Cursor; + green(): Cursor; + magenta(): Cursor; + red(): Cursor; + yellow(): Cursor; + grey(): Cursor; + brightBlack(): Cursor; + brightRed(): Cursor; + brightGreen(): Cursor; + brightYellow(): Cursor; + brightBlue(): Cursor; + brightMagenta(): Cursor; + brightCyan(): Cursor; + brightWhite(): Cursor; + } +} diff --git a/types/ansi/tsconfig.json b/types/ansi/tsconfig.json index ffdd8853a8..8ba65a1954 100644 --- a/types/ansi/tsconfig.json +++ b/types/ansi/tsconfig.json @@ -1,6 +1,6 @@ { "files": [ - "ansi.d.ts", + "index.d.ts", "ansi-tests.ts" ], "compilerOptions": { @@ -19,6 +19,6 @@ ], "noEmit": true, "forceConsistentCasingInFileNames": true, - "types": ["node"] + "types": [] } } \ No newline at end of file