Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Concise and fast javascript templating compatible with nodejs and other javascript environments
The 'dot' npm package is a fast and lightweight template engine in JavaScript. It allows you to create dynamic HTML templates with embedded JavaScript logic. It is known for its simplicity and performance, making it suitable for both client-side and server-side rendering.
Basic Template Rendering
This feature allows you to create a basic template and render it with dynamic data. The template string contains placeholders that are replaced with actual data when the template is rendered.
const doT = require('dot');
const template = doT.template('Hello, {{=it.name}}!');
const result = template({ name: 'World' });
console.log(result); // Output: Hello, World!
Conditional Rendering
This feature allows you to include conditional logic within your templates. The template string can contain conditional statements that control whether certain parts of the template are rendered.
const doT = require('dot');
const template = doT.template('{{? it.show }}Hello, {{=it.name}}!{{?}}');
const result = template({ show: true, name: 'World' });
console.log(result); // Output: Hello, World!
Looping
This feature allows you to loop over arrays within your templates. The template string can contain loop statements that iterate over arrays and render each item.
const doT = require('dot');
const template = doT.template('{{~it.items :item:index}}<li>{{=item}}</li>{{~}}');
const result = template({ items: ['Item 1', 'Item 2', 'Item 3'] });
console.log(result); // Output: <li>Item 1</li><li>Item 2</li><li>Item 3</li>
EJS (Embedded JavaScript) is a simple templating language that lets you generate HTML markup with plain JavaScript. It is similar to 'dot' in that it allows embedding JavaScript logic within templates, but EJS is more feature-rich and widely used.
Handlebars is a popular templating engine that provides a cleaner syntax for templates and includes features like partials and helpers. It is more powerful and flexible compared to 'dot', but also more complex.
Mustache is a logic-less templating engine that enforces a strict separation of logic and presentation. It is simpler and more restrictive compared to 'dot', making it easier to maintain but less flexible.
Created in search of the fast and concise JavaScript templating function with emphasis on performance under V8 and nodejs.
doT can be used with nodejs and other javascript environments.
doT.js is a blend of jQote2 and underscore.js templating functions with some additions.
jQote2 technique provides for fast performance and also enables flushing data to the stream at any point in the generated template function, this is handy when using on server.
Features: custom delimiters, runtime evaluation, runtime interpolation, compile-time evaluation, encoding, control whitespace - strip or preserve, streaming friendly
Usage: Default delimiters: {{= }} for interpolation, {{ }} for evaluation, {{! }} for interpolation with encoding, {{# }} for compile-time evaluation/includes, {{# #}} for compile-time defines
Other delimiters may be configured.
To control whitespace use 'strip' option, true - to strip, false - to preserve.
Sample:
// 1. Compile template function
var tempFn = doT.template("<h1>Here is a sample template {{=it.foo}} </h1>");
// 2. Use template function as many times as you like
var resultText = tempFn({foo: 'with doT'});
License: Licensed under the MIT License. (See LICENSE-DOT)
FAQs
Concise and fast javascript templating compatible with nodejs and other javascript environments
The npm package dot receives a total of 462,276 weekly downloads. As such, dot popularity was classified as popular.
We found that dot 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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.