Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added types to package #11

Merged
merged 3 commits into from
Jan 25, 2022
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
3 changes: 2 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run lint
- run: npm run lint
- run: npm run tsd
301 changes: 301 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
// Type definitions for pdf-image 2.0
// Project: https://github.com/mooz/node-pdf-image#readme
// Definitions by: NickLatkovich <https://github.com/nicklatkovich>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Minimum TypeScript Version: 3.4

export type ConvertOptionKey =
| "-adaptive-blur"
| "-adaptive-resize"
| "-adaptive-sharpen"
| "-adjoin"
| "-affine"
| "-alpha"
| "-annotate"
| "-antialias"
| "-append"
| "-authenticate"
| "-auto-gamma"
| "-auto-level"
| "-auto-orient"
| "-auto-threshold"
| "-background"
| "-bench"
| "-bias"
| "-black-threshold"
| "-blue-primary"
| "-blue-shift"
| "-blur"
| "-border"
| "-bordercolor"
| "-brightness-contrast"
| "-canny"
| "-caption"
| "-cdl"
| "-channel"
| "-charcoal"
| "-chop"
| "-clahe"
| "-clamp"
| "-clip"
| "-clip-mask"
| "-clip-path"
| "-clone"
| "-clut"
| "-connected-components"
| "-contrast-stretch"
| "-coalesce"
| "-colorize"
| "-color-matrix"
| "-colors"
| "-colorspace"
| "-combine"
| "-comment"
| "-compare"
| "-complexoperator"
| "-compose"
| "-composite"
| "-compress"
| "-contrast"
| "-convolve"
| "-copy"
| "-crop"
| "-cycle"
| "-decipher"
| "-debug"
| "-define"
| "-deconstruct"
| "-delay"
| "-delete"
| "-density"
| "-depth"
| "-despeckle"
| "-direction"
| "-display"
| "-dispose"
| "-distribute-cache"
| "-distort"
| "-dither"
| "-draw"
| "-duplicate"
| "-edge"
| "-emboss"
| "-encipher"
| "-encoding"
| "-endian"
| "-enhance"
| "-equalize"
| "-evaluate"
| "-evaluate-sequence"
| "-extent"
| "-extract"
| "-family"
| "-features"
| "-fft"
| "-fill"
| "-filter"
| "-flatten"
| "-flip"
| "-floodfill"
| "-flop"
| "-font"
| "-format"
| "-frame"
| "-function"
| "-fuzz"
| "-fx"
| "-gamma"
| "-gaussian-blur"
| "-geometry"
| "-gravity"
| "-grayscale"
| "-green-primary"
| "-help"
| "-hough-lines"
| "-identify"
| "-ift"
| "-implode"
| "-insert"
| "-intensity"
| "-intent"
| "-interlace"
| "-interline-spacing"
| "-interpolate"
| "-interword-spacing"
| "-kerning"
| "-kmeans"
| "-kuwahara"
| "-label"
| "-lat"
| "-layers"
| "-level"
| "-limit"
| "-linear-stretch"
| "-liquid-rescale"
| "-list"
| "-log"
| "-loop"
| "-mattecolor"
| "-median"
| "-mean-shift"
| "-metric"
| "-mode"
| "-modulate"
| "-moments"
| "-monitor"
| "-monochrome"
| "-morph"
| "-morphology"
| "-motion-blur"
| "-negate"
| "-noise"
| "-normalize"
| "-opaque"
| "-ordered-dither"
| "-orient"
| "-page"
| "-paint"
| "-perceptible"
| "-ping"
| "-pointsize"
| "-polaroid"
| "-poly"
| "-posterize"
| "-precision"
| "-preview"
| "-print"
| "-process"
| "-profile"
| "-quality"
| "-quantize"
| "-quiet"
| "-radial-blur"
| "-raise"
| "-random-threshold"
| "-range-threshold"
| "-read-mask"
| "-red-primary"
| "-regard-warnings"
| "-region"
| "-remap"
| "-render"
| "-repage"
| "-resample"
| "-resize"
| "-respect-parentheses"
| "-roll"
| "-rotate"
| "-sample"
| "-sampling-factor"
| "-scale"
| "-scene"
| "-seed"
| "-segment"
| "-selective-blur"
| "-separate"
| "-sepia-tone"
| "-set"
| "-shade"
| "-shadow"
| "-sharpen"
| "-shave"
| "-shear"
| "-sigmoidal-contrast"
| "-smush"
| "-size"
| "-sketch"
| "-solarize"
| "-splice"
| "-spread"
| "-statistic"
| "-strip"
| "-stroke"
| "-strokewidth"
| "-stretch"
| "-style"
| "-swap"
| "-swirl"
| "-synchronize"
| "-taint"
| "-texture"
| "-threshold"
| "-thumbnail"
| "-tile"
| "-tile-offset"
| "-tint"
| "-transform"
| "-transparent"
| "-transparent-color"
| "-transpose"
| "-transverse"
| "-treedepth"
| "-trim"
| "-type"
| "-undercolor"
| "-unique-colors"
| "-units"
| "-unsharp"
| "-verbose"
| "-version"
| "-view"
| "-vignette"
| "-virtual-pixel"
| "-wave"
| "-wavelet-denoise"
| "-weight"
| "-white-point"
| "-white-threshold"
| "-write"
| "-write-mask";

export type ConvertOptions = { [key in ConvertOptionKey]?: string };

export interface Options {
pdfFileBaseName?: string;
convertOptions?: ConvertOptions;
convertExtension?: string;
graphicsMagick?: boolean;
outputDirectory?: string;
}

export type OptionalSpread<CombinedImage extends boolean> =
CombinedImage extends true
? [Options & { combinedImage: CombinedImage }]
: [] | [Options & { combinedImage?: CombinedImage }];

export interface PDFInfo {
Creator: string;
Producer: string;
CreationDate: string;
Tagged: string;
UserProperties: string;
Suspects: string;
Form: string;
JavaScript: string;
Pages: string;
Encrypted: string;
"Page size": string;
"Page rot": string;
"File size": string;
Optimized: string;
"PDF version": string;
[key: string]: string;
}

export class PDFImage<CombinedImage extends boolean = false> {
constructor(path: string, ...options: OptionalSpread<CombinedImage>);
combineImages(imagePaths: readonly string[]): Promise<string>;
constructCombineCommandForFile(imagePaths: readonly string[]): string;
constructConvertCommandForPage(pageNumber: number): string;
constructConvertOptions(): string;
constructGetInfoCommand(): string;
convertFile(): Promise<CombinedImage extends true ? string : string[]>;
convertPage(pageNumber: number): Promise<string>;
getInfo(): Promise<PDFInfo>;
getOutputImagePathForFile(): string;
getOutputImagePathForPage(pageNumber: number): string;
parseGetInfoCommandOutput(output: string): { [key: string]: string };
setConvertExtension(convertExtension?: string): void;
setConvertOptions(convertOptions?: Readonly<ConvertOptions>): void;
setPdfFileBaseName(pdfFileBaseName?: string): void;
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ PDFImage.prototype = {
);
},
constructConvertOptions() {
return Object.keys(this.convertOptions).sort().map(function (optionName) {
return Object.keys(this.convertOptions).sort().map((optionName) => {
if (this.convertOptions[optionName] !== null) {
return `${optionName} ${this.convertOptions[optionName]}`;
}
Expand Down
15 changes: 15 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { PDFImage } from './index';

// $ExpectType PDFImage<false>
new PDFImage("path");

// $ExpectType Promise<string[]>
new PDFImage("path").convertFile();

// $ExpectType Promise<string>
new PDFImage("path", { combinedImage: true }).convertFile();

// $ExpectType Promise<string | string[]>
new PDFImage<boolean>("path", { combinedImage: true }).convertFile();

new PDFImage("path", { convertOptions: { "-adaptive-blur": "" } });
Loading