Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
letter-generator
Advanced tools
Generate letters (plain text or PDF) from templates. Used by the Datenanfragen.de project.
This repository contains the source code for Letters Generation (plain text or PDF) from templates
You can install this tools via yarn
:
yarn add letter-generator
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.
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
}
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();
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.
FAQs
Generate letters (plain text or PDF) from templates. Used by the Datenanfragen.de project.
The npm package letter-generator receives a total of 82 weekly downloads. As such, letter-generator popularity was classified as not popular.
We found that letter-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.