npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@solcode/invoice-creator-api-package

v1.1.1

Published

[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/solcode)

Downloads

1

Readme

"Buy Me A Coffee"

🧾 Invoice client-side PDF generator

This NPM package takes care of filling the HTML template (handlebars), letting you use the HTML preview, and of course, generating a PDF.

🤔 Why?

I've written this package due to my need for generating a custom template invoices.

🧰 Installation

Node

npm i @solcode/invoice-creator-api-package

Yarn

yarn add @solcode/invoice-creator-api-package

🎬 Introduction & Usage

This NPM package represents a generator class that consists of 2 main functions.

| Action | Function | Parameters | | ------------- | ------------------| -------------| | Constructor | new Generator() | template, data | | Fill template with data | renderTemplate() | | | Download PDF client-side | downloadPDF() | generateRenderedPdf = true |

📝 Template

Template is a handlebars (or vanilla HTML5) string, but since the PDF generation is limited in some ways, there are a few additional requirements for the HTML, such as:

  • src attribute of img tags needs to have base64 encoded data instead of URLs (otherwise, images won't load in PDFs)
  • same rule applies for SVGs, they need to be inline

You can use https://www.base64-image.de for converting images to base64 data.

💿 Data

Data is nothing more than a simple JSON object that matches handlebars variables inside of the template. Eg.:

{{ total }} // handlebar variable inside of HTML

// and this would be the JSON
const data = {
    total: 200
}

➡️ Example

Take a look at this simple example down there.

import Generator from '@solcode/invoice-creator-api-package'

const template = '<p>this is my {{ title }}</p>'
const data = {
    title: 'test'
}

const generatorObject = new Generator(template, data) // returns Generator object
generatorObject.renderTemplate() // renders the template and save it to generator's property renderedTemplate

// if we wanna see preview of html we can get it by
let previewHtml = generatorObject.renderedTemplate
console.log(previewHtml) // we can display it how we want then

generatorObject.downloadPDF() // generates and downloads PDF

📎 License

This piece of code is open-source under MIT license.

🛣 Roadmap

  • creating template variables standard
  • class abstraction over data json object

💻 Contributing

If you feel that you have a great idea which could improve this piece of code, fork it, commit your changes and make a pull request, so we can take a look at it, thanks! 😎

❤️ Feel free to support us

Even that we have our clients, a little support would really help us to speed up free & open-source projects like this.

"Buy Me A Coffee"

BTC Address (3KkrgnJfN8zCGTqWPfjRAKLeUSPD2z79aG)