From 5fbe400c5fa5b1963cffbb12e9049642af79b455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Mon, 21 Sep 2020 21:51:17 +0200 Subject: [PATCH] feat(get-image-colors): new definition (#47809) - definition types - tests https://github.com/colorjs/get-image-colors Thanks! --- .../get-image-colors-tests.ts | 28 ++++++++++++++++ types/get-image-colors/index.d.ts | 32 +++++++++++++++++++ types/get-image-colors/tsconfig.json | 23 +++++++++++++ types/get-image-colors/tslint.json | 1 + 4 files changed, 84 insertions(+) create mode 100644 types/get-image-colors/get-image-colors-tests.ts create mode 100644 types/get-image-colors/index.d.ts create mode 100644 types/get-image-colors/tsconfig.json create mode 100644 types/get-image-colors/tslint.json diff --git a/types/get-image-colors/get-image-colors-tests.ts b/types/get-image-colors/get-image-colors-tests.ts new file mode 100644 index 0000000000..b85a2cad87 --- /dev/null +++ b/types/get-image-colors/get-image-colors-tests.ts @@ -0,0 +1,28 @@ +import path = require('path'); +import fs = require('fs'); +import getColors = require('get-image-colors'); +import { Options } from 'get-image-colors'; + +const buffer = fs.readFileSync(path.join(__dirname, 'double-rainbow.gif')); +const options: Options = { + count: 10, + type: 'image/png', +}; + +getColors('./path').then(colors => { + colors; // $ExpectType Color[] +}); +getColors('./path', (err, colors) => { + if (err) throw err; + colors; // $ExpectType Color[] +}); + +getColors(buffer, 'image/gif').then(colors => { + colors; // $ExpectType Color[] + colors.map(color => color.hex()); + colors[0].alpha(0.5).css(); +}); + +getColors(path.join(__dirname, 'double-rainbow.png'), options).then(colors => { + colors; // $ExpectType Color[] +}); diff --git a/types/get-image-colors/index.d.ts b/types/get-image-colors/index.d.ts new file mode 100644 index 0000000000..b0ca5856bd --- /dev/null +++ b/types/get-image-colors/index.d.ts @@ -0,0 +1,32 @@ +// Type definitions for get-image-colors 2.0 +// Project: https://github.com/colorjs/get-image-colors#readme +// Definitions by: Piotr Błażejewicz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// +import chroma = require('chroma-js'); + +/** + * Extract colors from images. Supports GIF, JPG, PNG, and even SVG! + */ +declare function colorPalette(input: Buffer, options: colorPalette.Options, callback: chroma.Color[]): void; +declare function colorPalette(input: Buffer, type: string, callback: colorPalette.Callback): void; +declare function colorPalette(input: Buffer, type: string): Promise; +declare function colorPalette(input: string, options?: colorPalette.Options): Promise; +declare function colorPalette(input: string, callback: colorPalette.Callback): void; + +declare namespace colorPalette { + interface Options { + type?: string; + /** + * @default 5 + */ + count?: number; + } + + /** + * If you don't like promises, you can use node-style callbacks too + */ + type Callback = (error: Error | null, colors: chroma.Color[]) => void; +} + +export = colorPalette; diff --git a/types/get-image-colors/tsconfig.json b/types/get-image-colors/tsconfig.json new file mode 100644 index 0000000000..0861391074 --- /dev/null +++ b/types/get-image-colors/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", + "get-image-colors-tests.ts" + ] +} diff --git a/types/get-image-colors/tslint.json b/types/get-image-colors/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/get-image-colors/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }