diff --git a/types/colornames/colornames-tests.ts b/types/colornames/colornames-tests.ts new file mode 100644 index 0000000000..6fc9bb712a --- /dev/null +++ b/types/colornames/colornames-tests.ts @@ -0,0 +1,29 @@ +import colorNames = require("colornames"); + +// $ExpectType Color +const color = colorNames("red"); + +// $ExpectType string +color.value; +// $ExpectType boolean | undefined +color.css; +// $ExpectType boolean | undefined +color.vga; +// $ExpectType string +color.name; + +// $ExpectType Color +colorNames.get("blue"); +// $ExpectType Color[] +colorNames.get.all(); +// $ExpectType Color[] +colorNames.get.css(); +// $ExpectType Color +colorNames.get.css("orange"); +// $ExpectType Color[] +colorNames.get.vga(); +// $ExpectType Color +colorNames.get.vga("violet"); + +// $ExpectType Color[] +colorNames.all(); diff --git a/types/colornames/index.d.ts b/types/colornames/index.d.ts new file mode 100644 index 0000000000..d9b331167b --- /dev/null +++ b/types/colornames/index.d.ts @@ -0,0 +1,93 @@ +// Type definitions for colornames 1.1 +// Project: https://github.com/timoxley/colornames#readme +// Definitions by: Manuel Thalmann +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * Represents a color. + */ +interface Color { + /** + * Gets the value of the color. + */ + value: string; + + /** + * Gets a value indicating whether the color is a valid `CSS`-color. + */ + css?: boolean; + + /** + * Gets a value indicating whether the color is a valid `VGA`-color. + */ + vga?: boolean; + + /** + * Gets the name of the color. + */ + name: string; +} + +/** + * Povides the functionality to resolve colors of a specific type by its name. + */ +interface ColorResolver { + /** + * Gets the color with the specified name. + * + * @param name + * The name of the color to get. + */ + (name: string): Color; + + /** + * Gets all colors. + */ + (): Color[]; +} + +/** + * Provides the functionality to resolve any kind of color by its name. + */ +interface GlobalResolver { + /** + * Gets the color with the specified name. + */ + (name: string): Color; + + /** + * Provides the functionality to query colors. + */ + get: { + /** + * Gets the color with the specified name. + * + * @param name + * The name of the color to get. + */ + (name: string): Color; + + /** + * Gets all available colors. + */ + all(): Color[]; + + /** + * Provides the functionality to resolve `css`-colors. + */ + css: ColorResolver; + + /** + * Provides the functionality to resolve `vga`-colors. + */ + vga: ColorResolver; + }; + + /** + * Gets all available colors. + */ + all(): Color[]; +} + +declare let colorNames: GlobalResolver; +export = colorNames; diff --git a/types/colornames/tsconfig.json b/types/colornames/tsconfig.json new file mode 100644 index 0000000000..b494da59cd --- /dev/null +++ b/types/colornames/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "colornames-tests.ts" + ] +} diff --git a/types/colornames/tslint.json b/types/colornames/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/colornames/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }