Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions types/wkhtmltopdf/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

/// <reference types="node"/>

import { Readable } from "stream";

/**
* Call wkhtmltopdf and write PDF
* If options.output is defined the file will be returned in the stream
Expand All @@ -13,8 +15,8 @@
declare function wkhtmltopdf(
html: string,
options?: Options,
callback?: (err: Error, stream: NodeJS.ReadWriteStream) => void,
): NodeJS.ReadWriteStream;
callback?: (err: Error | null, stream?: NodeJS.ReadWriteStream) => void,
): Readable;
/**
* Call wkhtmltopdf and write PDF
* If options.output is defined the file will be returned in the stream
Expand All @@ -26,8 +28,8 @@ declare function wkhtmltopdf(
declare function wkhtmltopdf(
url: string,
options?: Options,
callback?: (err: Error, stream: NodeJS.ReadWriteStream) => void,
): NodeJS.ReadWriteStream;
callback?: (err: Error | null, stream?: NodeJS.ReadWriteStream) => void,
): Readable;
/**
* Call wkhtmltopdf and write PDF
* If options.output is defined the file will be returned in the stream
Expand All @@ -36,7 +38,11 @@ declare function wkhtmltopdf(
* @param [options] Options
* @param [callback] Callback
*/
declare function wkhtmltopdf(inputStream: NodeJS.ReadStream, options?: Options): NodeJS.ReadWriteStream;
declare function wkhtmltopdf(
inputStream: NodeJS.ReadStream,
options?: Options,
callback?: (err: Error | null, stream?: NodeJS.ReadWriteStream) => void,
): Readable;

declare namespace wkhtmltopdf {
/**
Expand Down
30 changes: 20 additions & 10 deletions types/wkhtmltopdf/wkhtmltopdf-tests.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import wkhtmltopdf = require("wkhtmltopdf");

// URL
wkhtmltopdf("http://google.com/", { pageSize: "Letter" }); // $ExpectType NodeJS.ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://google.com/", { pageSize: "Letter" });

// HTML
wkhtmltopdf("<h1>Test</h1><p>Hello world</p>"); // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("<h1>Test</h1><p>Hello world</p>");

// output to a file directly
wkhtmltopdf("http://apple.com/", { output: "out.pdf" }); // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://apple.com/", { output: "out.pdf" });

// Optional callback
wkhtmltopdf("http://google.com/", { pageSize: "Letter" }, (err: Error, stream: NodeJS.ReadWriteStream) => {}); // $ExpectType void
// $ExpectType Readable
wkhtmltopdf("http://google.com/", { pageSize: "Letter" }, (err: Error | null, stream?: NodeJS.ReadWriteStream) => {});

// Repeatable options
wkhtmltopdf("http://google.com/", { // $ExpectType NodeJS.ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://google.com/", {
allow: ["path1", "path2"],
customHeader: [
["name1", "value1"],
Expand All @@ -22,23 +27,27 @@ wkhtmltopdf("http://google.com/", { // $ExpectType NodeJS.ReadWriteStream
});

// Ignore warning strings
wkhtmltopdf("http://apple.com/", { // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://apple.com/", {
output: "out.pdf",
ignore: ["QFont::setPixelSize: Pixel size <= 0 (0)"],
});

// RegExp also acceptable
wkhtmltopdf("http://apple.com/", { // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://apple.com/", {
output: "out.pdf",
ignore: [/QFont::setPixelSize/],
});

// Test debug types
wkhtmltopdf("http://apple.com/", { // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://apple.com/", {
debug: true,
});

wkhtmltopdf("http://apple.com/", { // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://apple.com/", {
output: "test.pdf",
debug: (data: Buffer) => {
const dataString = data.toString();
Expand All @@ -56,7 +65,8 @@ wkhtmltopdf.shell; // $ExpectType string
wkhtmltopdf.command; // $ExpectType string

// Footer and header spacing type
wkhtmltopdf("http://apple.com/", { // $ExpectType ReadWriteStream
// $ExpectType Readable
wkhtmltopdf("http://apple.com/", {
headerSpacing: 0,
footerSpacing: 0,
});