mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-07 09:49:07 +00:00
[color-hash] Add definitions (#41524)
* Add color-hash definitions * Change namespace export
This commit is contained in:
committed by
Armando Aguirre
parent
ddb263c5b4
commit
4e36732801
@@ -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] });
|
||||
Vendored
+58
@@ -0,0 +1,58 @@
|
||||
// Type definitions for color-hash 1.0
|
||||
// Project: https://github.com/zenozeng/color-hash
|
||||
// Definitions by: Johannes Hoppe <https://github.com/JohannesHoppe>
|
||||
// Kamil Socha <https://github.com/ksocha>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
type ColorValueArray = [number, number, number];
|
||||
|
||||
interface HueObject {
|
||||
min: number;
|
||||
max: number;
|
||||
}
|
||||
|
||||
type Hue = number | HueObject | ReadonlyArray<HueObject>;
|
||||
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;
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user