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

hmpo-template-mixins

Package Overview
Dependencies
Maintainers
3
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hmpo-template-mixins - npm Package Compare versions

Comparing version 7.5.1 to 7.6.0

lib/errors.js

2

index.js

@@ -6,2 +6,3 @@ 'use strict';

const mixins = require('./lib/mixins');
const errors = require('./lib/errors');

@@ -15,2 +16,3 @@ module.exports = options => {

fieldsMiddleware(req, res);
errors.middleware(req, res);
next();

@@ -17,0 +19,0 @@ };

2

lib/fields/index.js
'use strict';
const debug = require('debug')('hmpo:fields');
const debug = require('debug')('hmpo:mixins:fields');
const _ = require('underscore');

@@ -5,0 +5,0 @@ const path = require('path');

@@ -41,2 +41,3 @@ 'use strict';

date(txt) {
debug('DATE', txt, this);
txt = hoganRender(txt, this).split('|');

@@ -109,3 +110,11 @@ let value = txt[0];

res.locals.translate = () => function (key) {
return hoganRender(translate(options.sharedTranslationsKey + key), this);
if (options.sharedTranslationsKey) {
if (Array.isArray(key)) {
key = key.map(k => options.sharedTranslationsKey + k);
} else {
key = options.sharedTranslationsKey + key;
}
}
debug('translate', key);
return hoganRender(translate(key), this);
};

@@ -112,0 +121,0 @@

{
"name": "hmpo-template-mixins",
"version": "7.5.1",
"version": "7.6.0",
"description": "A middleware that exposes a series of Mustache mixins on res.locals to ease usage of forms, translations, and some general needs.",

@@ -37,2 +37,3 @@ "main": "index.js",

"dependencies": {
"debug": "^4.1.1",
"hogan.js": "^3.0.2",

@@ -44,9 +45,8 @@ "moment": "^2.13.0",

"chai": "^4.1.2",
"eslint": "^4.10.0",
"eslint": "^5.13.0",
"istanbul": "^0.4.3",
"mocha": "^5.1.1",
"sinon": "^4.0.2",
"sinon-chai": "^3.0.0",
"snyk": "^1.24.5"
"sinon": "^7.2.3",
"sinon-chai": "^3.0.0"
}
}

@@ -19,7 +19,7 @@ 'use strict';

it('is a function', function () {
it('is a function', () => {
lambdas.addLambdas.should.be.a('function');
});
it('returns a function', function () {
it('returns a function', () => {
lambdas.addLambdas().should.be.a('function');

@@ -29,3 +29,3 @@ lambdas.addLambdas().length.should.equal(2);

describe('adds lambdas and values into res.locals', function () {
describe('adds lambdas and values into res.locals', () => {
beforeEach(() => {

@@ -37,3 +37,3 @@ lambdas.addLambdas()(req, res);

if (typeof lambda === 'function') {
it(`lambda ${name}`, function () {
it(`lambda ${name}`, () => {
res.locals[name].should.be.a('function');

@@ -43,3 +43,3 @@ res.locals[name]().should.be.a('function');

} else {
it(`value ${name}`, function () {
it(`value ${name}`, () => {
res.locals[name].should.equal(lambda);

@@ -50,2 +50,29 @@ });

});
describe('adds translate function into res.locals', () => {
let translate;
beforeEach(() => {
translate = sinon.stub().returns('translated');
});
it('calls translate function', () => {
lambdas.addLambdas({ translate })(req, res);
res.locals.translate.should.be.a('function');
let result = res.locals.translate()('args');
translate.should.have.been.calledWithExactly('args');
result.should.equal('translated');
});
it('adds sharedTranslationsKey to keys', () => {
lambdas.addLambdas({ translate, sharedTranslationsKey: 'foo' })(req, res);
res.locals.translate()('args');
translate.should.have.been.calledWithExactly('foo.args');
});
it('adds sharedTranslationsKey to array of keys', () => {
lambdas.addLambdas({ translate, sharedTranslationsKey: 'foo' })(req, res);
res.locals.translate()(['arg1', 'arg2']);
translate.should.have.been.calledWithExactly(['foo.arg1', 'foo.arg2']);
});
});
});

@@ -52,0 +79,0 @@

Sorry, the diff of this file is not supported yet

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