feat(get-image-colors): new definition (#47809)

- definition types
- tests

https://github.com/colorjs/get-image-colors

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-09-21 21:51:17 +02:00 committed by GitHub
parent 51ba34e7b0
commit 5fbe400c5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 0 deletions

View File

@ -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[]
});

32
types/get-image-colors/index.d.ts vendored Normal file
View File

@ -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 <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
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<chroma.Color[]>;
declare function colorPalette(input: string, options?: colorPalette.Options): Promise<chroma.Color[]>;
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;

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }