diff --git a/types/kuler/index.d.ts b/types/kuler/index.d.ts new file mode 100644 index 0000000000..970c33c203 --- /dev/null +++ b/types/kuler/index.d.ts @@ -0,0 +1,25 @@ +// Type definitions for kuler 2.0 +// Project: https://github.com/3rd-Eden/kuler +// Definitions by: Tristan F. +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface KulerInstance { + prefix: string; + suffix: string; + text: string; + /** Parse a hex color string and parse it to it's RGB equiv. */ + hex: (color: string) => [number, number, number]; + /** Transform a 255 RGB value to an RGV code. */ + rgb: (r: number, g: number, b: number) => string; + /** Turns RGB 0-5 values into a single ANSI code. */ + ansi: (r: number, g: number, b: number) => string; + /** Marks an end of color sequence. */ + reset: () => string; + /** Colour the terminal using CSS. */ + style: (color: string) => string; +} + +declare function kuler(text: string, color: string): string; +declare function kuler(text: string): KulerInstance; + +export = kuler; diff --git a/types/kuler/kuler-tests.ts b/types/kuler/kuler-tests.ts new file mode 100644 index 0000000000..4bb8900fd8 --- /dev/null +++ b/types/kuler/kuler-tests.ts @@ -0,0 +1,42 @@ +import kuler = require("kuler"); + +// $ExpectType string +kuler("test").style("red"); + +// @ts-expect-error +kuler("test").style(new Symbol(5)); + +// $ExpectType string +kuler("test", "red"); + +// @ts-expect-error +kuler("test", new Symbol(5)); + +const kulerInstance = kuler("test"); + +// $ExpectType string +kulerInstance.text; + +// $ExpectType string +kulerInstance.ansi(1, 2, 3); + +// $ExpectType [number, number, number] +kulerInstance.hex("#ffffff"); + +// $ExpectType string +kulerInstance.rgb(1, 2, 3); + +// $ExpectType string +kulerInstance.reset(); + +// $ExpectType string +kulerInstance.style("red"); + +// $ExpectType string +kulerInstance.suffix; + +// $ExpectType string +kulerInstance.prefix; + +// @ts-expect-error +kulerInstance.ansi(new Symbol(5), 2, 3); diff --git a/types/kuler/tsconfig.json b/types/kuler/tsconfig.json new file mode 100644 index 0000000000..8190fa8724 --- /dev/null +++ b/types/kuler/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "kuler-tests.ts" + ] +} diff --git a/types/kuler/tslint.json b/types/kuler/tslint.json new file mode 100644 index 0000000000..794cb4bf3e --- /dev/null +++ b/types/kuler/tslint.json @@ -0,0 +1 @@ +{ "extends": "@definitelytyped/dtslint/dt.json" }