Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
hmpo-template-mixins
Advanced tools
A middleware that exposes a series of Mustache mixins on res.locals to ease usage of forms, translations, and some general needs.
A middleware that exposes a series of Mustache mixins on res.locals
to ease usage of forms, translations, and some other things.
It takes an optional options object argument.
npm install [--save] hmpo-template-mixins;
const express = require('express');
const i18n = require('i18n-future');
const mixins = require('hmpo-template-mixins');
app.set('view engine', 'html');
app.set('views', path.join(__dirname, '/views'));
app.use(i18n.middleware());
app.use(mixins({ sharedTranslationsKey: 'passport.renew' }));
app.use(function (req, res) {
// NOTE: res.locals.partials has been set.
res.render('example-template');
});
If rendering as part of an HMPO controller's middleware chain then the field configuration will automatically be set to res.locals.options.fields
by the controller, and will be loaded from here by the mixins.
Alternatively, if not using HMPO controllers, you can explicitly set field configuration with instantiating the middleware by passing a fields
option. This should not be used for dynamic field configuration.
By default any function set to req.translate
will be used for translation if it exists. For example, that generated using i18n-future middleware.
Allows you override the directory that the module checks for partials in - Default: the root of this project
Allows you to alter the file extension of the templates - Default: 'html'
Prefixes keys for translation - Default: '' (empty string)
Defines a custom translation method - Default: req.translate
t
selected
lowercase
uppercase
capscase
hyphenate
date
time
currency
currencyOrFree
url
select
input-text
input-text-compound
input-text-code
input-number
input-phone
radio-group
checkbox
checkbox-compound
checkbox-required
checkbox-group
input-submit
textarea
input-date
input-date-group
error-group
error-group-end
className
: A string or array of string class names.labelClassName
: A string or array of string class names for the label, hint, and error section.labelTextClassName
: A string or array of string class names for the label text.label
: The intended value of the HTML label
attribute.type
: The value of the HTML input type
attribute.required
: Value applied to aria-required
HTML attribute.hint
: This adds context to the label, which it is a part of, for input text, radio groups and textarea. It is used within the input by aria-describedby for screen readers.hintClassName
: A string or array of string class names for the hint,maxlength
: Applicable to text-based fields and mapped to the maxlength
HTML attribute.options
: Applicable to HTML select
and radio
controls and used to generate the items of either HTML element.selected
: Applicable to select
, checkbox
, and radio
controls. Will render the selected HTML option/element selected or checked.legend
: Applicable to radio
button controls, which are wrapped in a HTML fieldset
with a legend
element.legendClassName
: Applied as a class name to HTML legend
attribute.toggle
: Can be used to toggle the display of the HTML element with a matching id
. See passports-frontend-toolkit for details.attributes
: A hash of key/value pairs applicable to a HTML textarea
field. Each key/value is assigned as an attribute of the textarea
. For example spellcheck="true"
.child
: Render a child partial beneath each option in an optionGroup
. Accepts a custom mustache template string, a custom partial in the format partials/{your-partial-name}
or a template mixin key which will be rendered within a panel element partial.date
mixinDates should be provided to the date lambda in ISO format
{{#date}}2017-06-03T12:34:56.000Z{/date}
3 June 2017
A moment format can be supplied. The default format is D MMMM YYYY.
{{#date}}2017-06-3T12:34:56.000Z|DD MMM YYYY HH:MMa{/date}
03 Jun 2017 12:34pm
time
mixinThe time formatter wraps a formatted time to correct for GDS standard:
{{#time}}3:00pm{{/time}}
3pm
{{#time}}11 May 2017 at 12:00pm{{/time}}
11 May 2017 at midday
{{#time}}12:00am{{/time}}
Midnight
Comma separated options can be provided to only do transforms for midday, midnight, or shortened time:
{{#time}}12:00pm|short,midnight{{/time}}
12pm
FAQs
A middleware that exposes a series of Mustache mixins on res.locals to ease usage of forms, translations, and some general needs.
We found that hmpo-template-mixins demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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 researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.