🤖 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:
Piotr Błażejewicz (Peter Blazejewicz) 2020-08-28 23:07:47 +02:00 committed by GitHub
parent de98631ecb
commit 0527086d1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -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;

View File

@ -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