Skip to content

Commit

Permalink
Merge pull request #12 from h1dd3nsn1p3r/development
Browse files Browse the repository at this point in the history
📦 Added: global.d.ts in npm.
  • Loading branch information
h1dd3nsn1p3r authored Jan 4, 2024
2 parents f28a812 + 1115200 commit 29f7987
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: "18"
- run: pnpm run build
- run: npm install
- run: npm run build
- uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ examples
src
.github
.gitignore
global.d.ts
pnpm-lock.yaml
tsconfig.json
tsup.config.ts
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ or ES6 import:
import { PDFInvoice } from '@h1dd3nsn1p3r/pdf-invoice';
```

`PDFInvoice` is a class that takes the payload as an argument. The payload is the data that you want to show on the invoice. For more information check the [Payload Data](https://github.com/h1dd3nsn1p3r/pdf-invoice/blob/development/examples/example.ts) example.
`PDFInvoice` is a class that takes the payload as an argument. The payload is the data that you want to show on the invoice. For more information check the [Payload data](https://github.com/h1dd3nsn1p3r/pdf-invoice/blob/development/examples/example.ts) example.

## Payload Data

Expand All @@ -63,7 +63,8 @@ const payload = {
date: "25/12/2023", // Default is current date.
dueDate: "25/12/2023", // Default is current date.
status: "Paid!",
currency: "", // Default is "$"
currency: "", // Default is "$",
path: "./invoice.pdf", // Required. Path where you would like to generate the PDF file.
},
items: [
{
Expand All @@ -86,7 +87,7 @@ const payload = {
},
],
qr: {
src: "https://www.festrolcorp.io",
data: "https://www.festrolcorp.io",
width: 100, // Default is 50.
},
note: {
Expand Down Expand Up @@ -144,6 +145,18 @@ const invoice = {

The invoice number is required. It might be a `integer` that you use to track your invoices. In most cases, it is a unique number that reference the `order ID` or invoice sequence number in your database. Rest of the fields are optional.

If path is supplied in the payload, then the PDF will be generated at that location. For example:

```js
const file = "invoice" + "-#" + 1729 + "-" + new Date().getTime(); // invoice-#1729-1630480000000
const location = path.join(__dirname, "/invoices/" + file + ".pdf");
const invoice = {
path: location, // Required.
}
```

If path is not supplied in the payload, then the PDF will be generated in current working directory with the name `invoice.pdf`.

### Customer

This is the information about your customer. It is an object with the following structure:
Expand Down Expand Up @@ -240,14 +253,21 @@ const handleInvoice = async(): Promise<void> => {
const invoice = new PDFInvoice(payload);
const pdf = await invoice.create(); // Returns promise, await it.

console.log(pdf); // Path to the PDF file.
console.log(pdf); // Full path to the PDF file.
}

handleInvoice();
```

Once you call the `create` method, it will return a promise. You can either use `async/await` or `.then()` to handle the promise. The `create` method will return the path to the PDF file if the PDF is generated successfully. Otherwise, it will throw an error.

## Types

This library is written in TypeScript. If you need to import the types, then you can import them from `global.d.ts` file. For example:

```js
import type { CompanyInfo, CustomerInfo, InvoiceInfo, ItemInfo, QRInfo, InvoicePayLoad } from '@h1dd3nsn1p3r/pdf-invoice/global.d.ts';
```

## Todo

Expand Down
22 changes: 0 additions & 22 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,3 @@ export interface SimplePDFInvoice {
defaultStyle(): any;
styles(): any;
}

export interface Configurations {
labels: {
invoice: string;
item: string;
price: string;
quantity: string;
tax: string;
total: string;
subtotal: string;
due: string;
to: string;
from: string;
};
style: {
primaryColor: string;
secondaryColor: string;
borderColor: string;
logoWidth: number;
logoFontSize: number;
};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@h1dd3nsn1p3r/pdf-invoice",
"version": "1.0.3",
"version": "1.0.4",
"author": "h1dd3nsn1p3r",
"description": "Simple yet powerful node JS library that generates PDF invoice on the fly.",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions src/class/invoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class PDFInvoice implements SimplePDFInvoice {
const doc = printer.createPdfKitDocument(docDefinition);

doc.pipe(fs.createWriteStream(this.path));

doc.end();

doc.on("end", () => {
Expand Down

0 comments on commit 29f7987

Please sign in to comment.