mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
🤖 Merge PR #47118 update(probe-image-size): support for older api and minor changes by @peterblazejewicz
- support for still supported fallback singatures - new methods and types added - tests amended - maintainer added https://github.com/nodeca/probe-image-size#api Thanks!
This commit is contained in:
parent
de98631ecb
commit
0527086d1d
17
types/probe-image-size/index.d.ts
vendored
17
types/probe-image-size/index.d.ts
vendored
@ -1,9 +1,17 @@
|
||||
// Type definitions for probe-image-size 5.0
|
||||
// Project: https://github.com/nodeca/probe-image-size#readme
|
||||
// Definitions by: Jinesh Shah <https://github.com/jineshshah36>
|
||||
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
/// <reference types="node" />
|
||||
|
||||
/**
|
||||
* Get image size without full download. Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, PSD.
|
||||
*/
|
||||
declare function probe(source: string, opts: probe.ProbeOptions, callback: probe.ProbeCallback): void;
|
||||
declare function probe(source: string, opts?: probe.ProbeOptions): Promise<probe.ProbeResult>;
|
||||
declare function probe(source: string | NodeJS.ReadableStream, callback: probe.ProbeCallback): void;
|
||||
declare function probe(source: NodeJS.ReadableStream): Promise<probe.ProbeResult>;
|
||||
|
||||
declare namespace probe {
|
||||
interface ProbeResult {
|
||||
@ -21,6 +29,15 @@ declare namespace probe {
|
||||
retries?: number;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
interface ProbeError extends Error {
|
||||
code?: 'ECONTENT';
|
||||
status?: number;
|
||||
}
|
||||
|
||||
type ProbeCallback = (err: ProbeError | null, result: ProbeResult) => void;
|
||||
|
||||
function sync(data: Buffer): ProbeResult | null;
|
||||
}
|
||||
|
||||
export = probe;
|
||||
|
||||
@ -1,4 +1,22 @@
|
||||
import probe = require('probe-image-size');
|
||||
import fs = require('fs');
|
||||
|
||||
const input = fs.createReadStream('image.jpg');
|
||||
const data = fs.readFileSync('image.jpg');
|
||||
probe(''); // $ExpectType Promise<ProbeResult>
|
||||
probe('', { retries: 3 }); // $ExpectType Promise<ProbeResult>
|
||||
probe('http://example.com/image.jpg', { timeout: 5000 }).then(result => {
|
||||
result; // $ExpectType ProbeResult
|
||||
});
|
||||
probe('http://example.com/image.jpg', (err, result) => {
|
||||
if (err) {
|
||||
err; // $ExpectType ProbeError
|
||||
} else {
|
||||
result; // $ExpectType ProbeResult
|
||||
}
|
||||
});
|
||||
probe(input).then(result => {
|
||||
result; // $ExpectType ProbeResult
|
||||
input.destroy();
|
||||
});
|
||||
probe.sync(data); // $ExpectType ProbeResult | null
|
||||
|
||||
Loading…
Reference in New Issue
Block a user