diff --git a/types/color-hash/color-hash-tests.ts b/types/color-hash/color-hash-tests.ts new file mode 100644 index 0000000000..53e23ee74e --- /dev/null +++ b/types/color-hash/color-hash-tests.ts @@ -0,0 +1,31 @@ +import ColorHash = require('color-hash'); + +const colorHash = new ColorHash(); + +const result1: [number, number, number] = colorHash.hsl('Hello World'); +const result2: [number, number, number] = colorHash.rgb('Hello World'); +const result3: string = colorHash.hex('Hello World'); + +// Custom Hash +const customHash = (str: string) => 5; + +new ColorHash({ hash: customHash }); + +// Custom Hue +new ColorHash({ hue: 90 }); +new ColorHash({ hue: { min: 90, max: 270 } }); +new ColorHash({ + hue: [ + { min: 30, max: 90 }, + { min: 180, max: 210 }, + { min: 270, max: 285 }, + ], +}); + +// Custom Lightness +new ColorHash({ lightness: 0.5 }); +new ColorHash({ lightness: [0.35, 0.5, 0.65] }); + +// Custom Saturation +new ColorHash({ saturation: 0.5 }); +new ColorHash({ saturation: [0.35, 0.5, 0.65] }); diff --git a/types/color-hash/index.d.ts b/types/color-hash/index.d.ts new file mode 100644 index 0000000000..f23c58ba7d --- /dev/null +++ b/types/color-hash/index.d.ts @@ -0,0 +1,58 @@ +// Type definitions for color-hash 1.0 +// Project: https://github.com/zenozeng/color-hash +// Definitions by: Johannes Hoppe +// Kamil Socha +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +type ColorValueArray = [number, number, number]; + +interface HueObject { + min: number; + max: number; +} + +type Hue = number | HueObject | ReadonlyArray; +type Lightness = number | ColorValueArray; +type Saturation = number | ColorValueArray; + +type HashFunction = (input: string) => number; + +interface ColorHashOptions { + lightness?: Lightness; + saturation?: Saturation; + hue?: Hue; + hash?: HashFunction; +} + +declare class ColorHash { + constructor(options?: ColorHashOptions); + + /** + * Returns the hash in [h, s, l]. + * Note that H ∈ [0, 360); S ∈ [0, 1]; L ∈ [0, 1]; + * + * @param input string to hash + * @returns [h, s, l] + */ + hsl(input: string): ColorValueArray; + + /** + * Returns the hash in [r, g, b]. + * Note that R, G, B ∈ [0, 255] + * + * @param input string to hash + * @returns [r, g, b] + */ + rgb(input: string): ColorValueArray; + + /** + * Returns the hash in hex. + * + * @param input string to hash + * @returns hex with # + */ + hex(input: string): string; +} + +export as namespace ColorHash; +export = ColorHash; diff --git a/types/color-hash/tsconfig.json b/types/color-hash/tsconfig.json new file mode 100644 index 0000000000..6f9c7f6c28 --- /dev/null +++ b/types/color-hash/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", + "color-hash-tests.ts" + ] +} diff --git a/types/color-hash/tslint.json b/types/color-hash/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/color-hash/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }