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

letter-generator

v2.2.1

Published

Generate letters (plain text or PDF) from templates. Used by the Datenanfragen.de project.

Downloads

174

Readme

Letter Generator

This repository contains the source code for Letters Generation (plain text or PDF) from templates

Installation

You can install this tools via yarn:

yarn add letter-generator

Usage

1 - Create a template

You can use a template to generate your text with variables and flags

// The text contains the static text, flags and variables
// The variables should follow this form: {variable_name}
// The flags should follow this form: [flag_name>The text contained in the flag]
// In addition to your manually defined flags, for each variable var_name, a flag has:var_name will be added
// automatically and set to whether the variable is set and non-empty.
const templateText = "Here is a wonderful template.[flag_1> I don't want this to be printed out.][has:webpage>\nCheck out the {webpage} website!]\n[flag_2>I want this to be printed out.]";

// You should map the flag_name used in the template text with their visibilities (Boolean)
const flags = { flag_1: false, flag_2: true };

// You should map the variable_name used in the template text with their values
const variables = { webpage: 'Datenanfragen.de' };

// Create the template from our values and generate the output text as string
const template = new Template(templateText, flags, variables);
console.log(template.getText());
// Here is a wonderful template.
// Check out the Datenanfragen.de website!
// I want this to be printed out.

2 - Creating a Letter

You'll have to pass an object to the letter constructor containing those informations:

const props = {
    // The sender address, either as a string or as an array of the individual lines.
    sender_address: ['Jane Doe', '123 Some Lane', '12345 Some City', 'Some Country'],

    // The recipient address, individual or array
    recipient_address: ['John Doe', '667 One Street', '98765 Another City', 'A Country'],  

    // The information block usually displayed at the top-right of the letter. Can either be a string, a string[] or anything recognized by pdfmake.
    information_block: 'A block of information',

    // The Letter subject
    // In this case we use the text generated with the template but you can use a string
    subject: content,

    // The content of the letter. Can either be a string or anything recognized by pdfmake.
    content: 'Content of my letter',

    // OPTIONAL
    // The signature to be included after the content.
    signature: { type: 'text', name: 'Name' } // To just add the name
        //{ type: 'image', name: 'Name', value: '<BASE64 ENCODED IMAGE>'} to include an image with the name underneath
}

3 - Rendering the Letter

You can now create the letter object and use it:
The default layout is the DIN 5008-a layout

// Use default layout
const letter = new Letter(props);

// You can also give the letter a function that returns a pdfmake layout as second parameter:
const letter_with_layout = new Letter(props, layout_function);

Once your Letter is generated you can create a PdfRender from it:

const render = new PdfRenderer(letter);
render.triggerOpenInNewWindow();
render.triggerDownload();

Contributing

First of all, thank you very much for taking the time to contribute! Contributions are incredibly valuable for a project like ours.

We warmly welcome issues and pull requests through GitHub.

Please be aware that by contributing, you agree for your work to be released under the MIT license, as specified in the LICENSE file.

If you are interested in contributing in other ways besides coding, we can also really use your help. Have a look at our contribute page for more details.