Merge pull request #31307 from manuth/master

Add types for the "colornames"-module
This commit is contained in:
Nathan Shively-Sanders
2018-12-17 13:10:51 -08:00
committed by GitHub
4 changed files with 146 additions and 0 deletions
+29
View File
@@ -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();
+93
View File
@@ -0,0 +1,93 @@
// Type definitions for colornames 1.1
// Project: https://github.com/timoxley/colornames#readme
// Definitions by: Manuel Thalmann <https://github.com/manuth>
// 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;
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }