mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
feat(get-image-colors): new definition (#47809)
- definition types - tests https://github.com/colorjs/get-image-colors Thanks!
This commit is contained in:
parent
51ba34e7b0
commit
5fbe400c5f
28
types/get-image-colors/get-image-colors-tests.ts
Normal file
28
types/get-image-colors/get-image-colors-tests.ts
Normal 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
32
types/get-image-colors/index.d.ts
vendored
Normal 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;
|
||||
23
types/get-image-colors/tsconfig.json
Normal file
23
types/get-image-colors/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/get-image-colors/tslint.json
Normal file
1
types/get-image-colors/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user