Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hof-component-date

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hof-component-date - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

12

lib/date.js

@@ -34,2 +34,10 @@ 'use strict';

const conditionalTranslate = (key, translate) => {
let result = translate(key);
if (result === key) {
result = null;
}
return result;
};
module.exports = (key, options) => {

@@ -102,4 +110,6 @@ if (!key) {

}));
const legend = conditionalTranslate(`fields.${key}.legend`, req.translate);
const hint = conditionalTranslate(`fields.${key}.hint`, req.translate);
const error = req.form.errors && req.form.errors[key];
res.render(template, { key, error }, (err, html) => {
res.render(template, { key, legend, hint, error }, (err, html) => {
if (err) {

@@ -106,0 +116,0 @@ next(err);

2

package.json
{
"name": "hof-component-date",
"version": "1.1.1",
"version": "1.2.0",
"description": "A hof middleware for rendering and processing 3 part date fields",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -145,5 +145,5 @@ 'use strict';

it('calls res.render with template and key', () => {
it('calls res.render with template, key, legend and hint. Where the latter two are null', () => {
date.hooks['pre-render'](req, res, next);
expect(res.render).to.have.been.calledWith(path.resolve(__dirname, '../templates/date.html'), { error: undefined, key: 'date-field' });
expect(res.render).to.have.been.calledWith(path.resolve(__dirname, '../templates/date.html'), { error: undefined, key: 'date-field', legend: null, hint: null });
});

@@ -157,5 +157,13 @@

date.hooks['pre-render'](req, res, next);
expect(res.render).to.have.been.calledWith(path.resolve(__dirname, '../templates/date.html'), { error, key: 'date-field' });
expect(res.render).to.have.been.calledWith(path.resolve(__dirname, '../templates/date.html'), { error, key: 'date-field', legend: null, hint: null });
});
it('calls res.render with template, key, legend and hint with values NOT null', () => {
req.translate = sinon.stub();
req.translate.withArgs('fields.date-field.legend').returns('you legend');
req.translate.withArgs('fields.date-field.hint').returns('some hint');
date.hooks['pre-render'](req, res, next);
expect(res.render).to.have.been.calledWith(path.resolve(__dirname, '../templates/date.html'), { error: undefined, key: 'date-field', legend: 'you legend', hint: 'some hint' });
});
it('calls next with an error if res.render calls callback with err', () => {

@@ -162,0 +170,0 @@ res.render.yields('err');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc