Added types for color-namer

This commit is contained in:
Dmitriy Serdtsev
2018-02-08 10:36:03 +07:00
parent a593fd2d60
commit bfc371b386
4 changed files with 74 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
import namer = require('color-namer');
const colors1 = namer('#ffffff');
colors1.basic[0].distance;
colors1.basic[0].hex;
colors1.basic[0].name;
colors1.html;
colors1.ntc;
colors1.pantone;
colors1.roygbiv;
colors1.x11;
const colors2 = namer('#ffffff', { pick: ['basic', 'html', 'ntc'] });
colors2.basic;
colors2.html;
colors2.ntc;
const colors3 = namer('#ffffff', { omit: ['basic', 'html', 'ntc'] });
colors3.pantone;
colors3.roygbiv;
colors3.x11;
+25
View File
@@ -0,0 +1,25 @@
// Type definitions for color-namer 1.3
// Project: https://github.com/zeke/color-namer
// Definitions by: Dmitriy Serdtsev <https://github.com/in19farkt>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
export = ColorNamer;
export as namespace ColorNamer;
declare function ColorNamer<T extends ColorNamer.Palette>(color: string, options?: { pick: T[] }): ColorNamer.Colors<T>;
declare function ColorNamer<T extends ColorNamer.Palette>(color: string, options?: { omit: T[] }): ColorNamer.Colors<Diff<ColorNamer.Palette, T>>;
type Diff<T extends string, U extends string> = ({[P in T]: P} & {[P in U]: never } & { [x: string]: never })[T];
declare namespace ColorNamer {
type Colors<T extends Palette> = Record<T, Color[]>;
type Palette = 'roygbiv' | 'basic' | 'html' | 'x11' | 'pantone' | 'ntc';
interface Color {
name: string;
hex: string;
distance: number;
}
}
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true
},
"files": [
"index.d.ts",
"color-namer-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }