Skip to content

Commit

Permalink
Add Typescript typings, bump to 0.6.0 (#39)
Browse files Browse the repository at this point in the history
* Add typings

* Update README

* Update readme with main branch
  • Loading branch information
thiagoelg authored Feb 6, 2022
1 parent 1c87abf commit 3ee690c
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 30 deletions.
27 changes: 3 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,12 @@ Node Printer Prebuild
============
Native bind printers on POSIX and Windows OS from Node.js, electron and node-webkit.

[![npm version](https://badge.fury.io/js/@thiagoelg%2Fnode-printer.svg)](https://www.npmjs.com/package/@thiagoelg/node-printer) [![Prebuild Binaries and Publish](https://github.com/thiagoelg/node-printer/actions/workflows/prebuild-main.yml/badge.svg)](https://github.com/thiagoelg/node-printer/actions/workflows/prebuild-main.yml)

> It just works with Node 12 because of @thiagoelg in his [PR](https://github.com/tojocky/node-printer/pull/261)
> Prebuild and CI integration courtesy of @ekoeryanto in his [FORK](https://github.com/ekoeryanto/node-printer)
<table>
<thead>
<tr>
<th>Linux</th>
<th>Windows</th>
<th>Dependencies</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">
<a href="https://travis-ci.com/thiagoelg/node-printer"><img src="https://travis-ci.com/thiagoelg/node-printer.svg?branch=master"></a>
</td>
<td align="center">
<a href="https://ci.appveyor.com/project/thiagoelg/node-printer"><img src="https://ci.appveyor.com/api/projects/status/re16g0ikobhl9ghq/branch/master?svg=true"></a>
</td>
<td align="center">
<a href="https://david-dm.org/thiagoelg/node-printer"><img src="https://david-dm.org/thiagoelg/node-printer.svg"></a>
</td>
</tr>
</tbody>
</table>

If you have a problem, ask question to [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tojocky/node-printer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) or find/create a new [Github issue](https://github.com/thiagoelg/node-printer/issues)

___
Expand Down Expand Up @@ -65,7 +44,7 @@ npm install @thiagoelg/node-printer

### How to use:

See [examples](https://github.com/tojocky/node-printer/tree/master/examples)
See [examples](https://github.com/thiagoelg/node-printer/tree/main/examples)

### Author(s):

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@thiagoelg/node-printer",
"description": "Node.js printer bindings",
"version": "0.5.8",
"version": "0.6.0",
"homepage": "https://github.com/thiagoelg/node-printer",
"author": {
"name": "Ion Lupascu",
Expand Down Expand Up @@ -47,7 +47,8 @@
"main": "./lib/printer",
"dependencies": {
"nan": "^2.15.0",
"prebuild-install": "^7.0.1",
"patch-package": "^6.4.7"
}
"patch-package": "^6.4.7",
"prebuild-install": "^7.0.1"
},
"types": "types/index.d.ts"
}
22 changes: 22 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"types/index.d.ts",
]
}
56 changes: 56 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
export function getPrinters(): PrinterDetails[];
export function getPrinter(printerName: string): PrinterDetails;
export function getPrinterDriverOptions(printerName: string): PrinterDriverOptions;
export function getSelectedPaperSize(printerName: string): string;
export function getDefaultPrinterName(): string | undefined;
export function printDirect(options: PrintDirectOptions): void;
export function printFile(options: PrintFileOptions): void;
export function getSupportedPrintFormats(): string[];
export function getJob(printerName: string, jobId: number): JobDetails;
export function setJob(printerName: string, jobId: number, command: 'CANCEL' | string): void;
export function getSupportedJobCommands(): string[];

export interface PrintDirectOptions {
data: string | Buffer;
printer?: string | undefined;
type?: 'RAW' | 'TEXT' | 'PDF' | 'JPEG' | 'POSTSCRIPT' | 'COMMAND' | 'AUTO' | undefined;
options?: { [key: string]: string } | undefined;
success?: PrintOnSuccessFunction | undefined;
error?: PrintOnErrorFunction | undefined;
}

export interface PrintFileOptions {
filename: string;
printer?: string | undefined;
success?: PrintOnSuccessFunction | undefined;
error?: PrintOnErrorFunction | undefined;
}

export type PrintOnSuccessFunction = (jobId: string) => any;
export type PrintOnErrorFunction = (err: Error) => any;

export interface PrinterDetails {
name: string;
isDefault: boolean;
options: { [key: string]: string; };
}

export interface PrinterDriverOptions {
[key: string]: { [key: string]: boolean; };
}

export interface JobDetails {
id: number;
name: string;
printerName: string;
user: string;
format: string;
priority: number;
size: number;
status: JobStatus[];
completedTime: Date;
creationTime: Date;
processingTime: Date;
}

export type JobStatus = 'PAUSED' | 'PRINTING' | 'PRINTED' | 'CANCELLED' | 'PENDING' | 'ABORTED';

0 comments on commit 3ee690c

Please sign in to comment.