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

dustjs-helpers

Package Overview
Dependencies
Maintainers
4
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dustjs-helpers - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

CHANGELOG.md

80

dist/dust-helpers.js

@@ -1,2 +0,2 @@

/*! dustjs-helpers - v1.4.0
/*! dustjs-helpers - v1.5.0
* https://github.com/linkedin/dustjs-helpers

@@ -6,5 +6,16 @@ * Copyright (c) 2014 Aleksander Williams; Released under the MIT License */

//using the built in logging method of dust when accessible
var _log = dust.log ? function(mssg) { dust.log(mssg, "INFO"); } : function() {};
// Use dust's built-in logging when available
var _log = dust.log ? function(msg, level) {
level = level || "INFO";
dust.log(msg, level);
} : function() {};
var _deprecatedCache = {};
function _deprecated(target) {
if(_deprecatedCache[target]) { return; }
_log("Deprecation warning: " + target + " is deprecated and will be removed in a future version of dustjs-helpers", "WARN");
_log("For help and a deprecation timeline, see https://github.com/linkedin/dustjs-helpers/wiki/Deprecated-Features#" + target.replace(/\W+/g, ""), "WARN");
_deprecatedCache[target] = true;
}
function isSelect(context) {

@@ -40,7 +51,7 @@ var value = context.current();

filterOpType = params.filterOpType || '';
// when @eq, @lt etc are used as standalone helpers, key is required and hence check for defined
if ( typeof params.key !== "undefined") {
if (params.hasOwnProperty("key")) {
actualKey = dust.helpers.tap(params.key, chunk, context);
}
else if (isSelect(context)) {
} else if (isSelect(context)) {
actualKey = context.current().selectKey;

@@ -51,4 +62,3 @@ // supports only one of the blocks in the select to be selected

}
}
else {
} else {
_log("No key specified for filter in:" + filterOpType + " helper ");

@@ -66,9 +76,7 @@ return chunk;

return chunk.render(body, context);
}
else {
_log("No key specified for filter in:" + filterOpType + " helper ");
} else {
_log("No body specified for " + filterOpType + " helper ");
return chunk;
}
}
else if (bodies['else']) {
} else if (bodies['else']) {
return chunk.render(bodies['else'], context);

@@ -79,11 +87,10 @@ }

function coerce (value, type, context) {
if (value) {
switch (type || typeof(value)) {
function coerce(value, type, context) {
if (typeof value !== "undefined") {
switch (type || typeof value) {
case 'number': return +value;
case 'string': return String(value);
case 'boolean': {
case 'boolean':
value = (value === 'false' ? false : value);
return Boolean(value);
}
case 'date': return new Date(value);

@@ -151,8 +158,7 @@ case 'context': return context.get(value);

}
if(body) {
return bodies.block(chunk, context);
if (body) {
return body(chunk, context);
} else {
return chunk;
}
else {
return chunk;
}
},

@@ -162,8 +168,10 @@

var body = bodies.block;
if(body) {
return bodies.block(chunk, context.push(context.stack.index));
}
else {
return chunk;
}
// Will be removed in 1.6
_deprecated("{@idx}");
if(body) {
return body(chunk, context.push(context.stack.index));
}
else {
return chunk;
}
},

@@ -218,8 +226,12 @@

"if": function( chunk, context, bodies, params ){
"if": function( chunk, context, bodies, params ) {
var body = bodies.block,
skip = bodies['else'];
if( params && params.cond){
var cond = params.cond;
cond = dust.helpers.tap(cond, chunk, context);
skip = bodies['else'],
cond;
if(params && params.cond) {
// Will be removed in 1.6
_deprecated("{@if}");
cond = dust.helpers.tap(params.cond, chunk, context);
// eval expressions with given dust references

@@ -226,0 +238,0 @@ if(eval(cond)){

@@ -1,4 +0,4 @@

/*! dustjs-helpers - v1.4.0
/*! dustjs-helpers - v1.5.0
* https://github.com/linkedin/dustjs-helpers
* Copyright (c) 2014 Aleksander Williams; Released under the MIT License */
!function(dust){function isSelect(a){var b=a.current();return"object"==typeof b&&b.isSelect===!0}function jsonFilter(a,b){return"function"==typeof b?b.toString().replace(/(^\s+|\s+$)/gm,"").replace(/\n/gm,"").replace(/,\s*/gm,", ").replace(/\)\{/gm,") {"):b}function filter(a,b,c,d,e){d=d||{};var f,g,h=c.block,i=d.filterOpType||"";if("undefined"!=typeof d.key)f=dust.helpers.tap(d.key,a,b);else{if(!isSelect(b))return _log("No key specified for filter in:"+i+" helper "),a;f=b.current().selectKey,b.current().isResolved&&(e=function(){return!1})}return g=dust.helpers.tap(d.value,a,b),e(coerce(g,d.type,b),coerce(f,d.type,b))?(isSelect(b)&&(b.current().isResolved=!0),h?a.render(h,b):(_log("No key specified for filter in:"+i+" helper "),a)):c["else"]?a.render(c["else"],b):a}function coerce(a,b,c){if(a)switch(b||typeof a){case"number":return+a;case"string":return String(a);case"boolean":return a="false"===a?!1:a,Boolean(a);case"date":return new Date(a);case"context":return c.get(a)}return a}var _log=dust.log?function(a){dust.log(a,"INFO")}:function(){},helpers={tap:function(a,b,c){if("function"!=typeof a)return a;var d,e="";return d=b.tap(function(a){return e+=a,""}).render(a,c),b.untap(),d.constructor!==b.constructor?d:""===e?!1:e},sep:function(a,b,c){var d=c.block;return b.stack.index===b.stack.of-1?a:d?c.block(a,b):a},idx:function(a,b,c){var d=c.block;return d?c.block(a,b.push(b.stack.index)):a},contextDump:function(a,b,c,d){var e,f=d||{},g=f.to||"output",h=f.key||"current";return g=dust.helpers.tap(g,a,b),h=dust.helpers.tap(h,a,b),e="full"===h?JSON.stringify(b.stack,jsonFilter,2):JSON.stringify(b.stack.head,jsonFilter,2),"console"===g?(_log(e),a):(e=e.replace(/</g,"\\u003c"),a.write(e))},"if":function(chunk,context,bodies,params){var body=bodies.block,skip=bodies["else"];if(params&&params.cond){var cond=params.cond;if(cond=dust.helpers.tap(cond,chunk,context),eval(cond))return body?chunk.render(bodies.block,context):(_log("Missing body block in the if helper!"),chunk);if(skip)return chunk.render(bodies["else"],context)}else _log("No condition given in the if helper!");return chunk},math:function(a,b,c,d){if(d&&"undefined"!=typeof d.key&&d.method){var e=d.key,f=d.method,g=d.operand,h=d.round,i=null;switch(e=dust.helpers.tap(e,a,b),g=dust.helpers.tap(g,a,b),f){case"mod":(0===g||g===-0)&&_log("operand for divide operation is 0/-0: expect Nan!"),i=parseFloat(e)%parseFloat(g);break;case"add":i=parseFloat(e)+parseFloat(g);break;case"subtract":i=parseFloat(e)-parseFloat(g);break;case"multiply":i=parseFloat(e)*parseFloat(g);break;case"divide":(0===g||g===-0)&&_log("operand for divide operation is 0/-0: expect Nan/Infinity!"),i=parseFloat(e)/parseFloat(g);break;case"ceil":i=Math.ceil(parseFloat(e));break;case"floor":i=Math.floor(parseFloat(e));break;case"round":i=Math.round(parseFloat(e));break;case"abs":i=Math.abs(parseFloat(e));break;default:_log("method passed is not supported")}return null!==i?(h&&(i=Math.round(i)),c&&c.block?a.render(c.block,b.push({isSelect:!0,isResolved:!1,selectKey:i})):a.write(i)):a}return _log("Key is a required parameter for math helper along with method/operand!"),a},select:function(a,b,c,d){var e=c.block;if(d&&"undefined"!=typeof d.key){var f=dust.helpers.tap(d.key,a,b);return e?a.render(c.block,b.push({isSelect:!0,isResolved:!1,selectKey:f})):(_log("Missing body block in the select helper "),a)}return _log("No key given in the select helper!"),a},eq:function(a,b,c,d){return d?(d.filterOpType="eq",filter(a,b,c,d,function(a,b){return b===a})):a},ne:function(a,b,c,d){return d?(d.filterOpType="ne",filter(a,b,c,d,function(a,b){return b!==a})):a},lt:function(a,b,c,d){return d?(d.filterOpType="lt",filter(a,b,c,d,function(a,b){return a>b})):a},lte:function(a,b,c,d){return d?(d.filterOpType="lte",filter(a,b,c,d,function(a,b){return a>=b})):a},gt:function(a,b,c,d){return d?(d.filterOpType="gt",filter(a,b,c,d,function(a,b){return b>a})):a},gte:function(a,b,c,d){return d?(d.filterOpType="gte",filter(a,b,c,d,function(a,b){return b>=a})):a},"default":function(a,b,c,d){return d&&(d.filterOpType="default"),filter(a,b,c,d,function(){return!0})},size:function(a,b,c,d){var e,f,g,h=0;if(d=d||{},e=d.key,e&&e!==!0)if(dust.isArray(e))h=e.length;else if(!isNaN(parseFloat(e))&&isFinite(e))h=e;else if("object"==typeof e){f=0;for(g in e)Object.hasOwnProperty.call(e,g)&&f++;h=f}else h=(e+"").length;else h=0;return a.write(h)}};for(var key in helpers)dust.helpers[key]=helpers[key];"undefined"!=typeof exports&&(module.exports=dust)}("undefined"!=typeof exports?require("dustjs-linkedin"):dust);
!function(dust){function _deprecated(a){_deprecatedCache[a]||(_log("Deprecation warning: "+a+" is deprecated and will be removed in a future version of dustjs-helpers","WARN"),_log("For help and a deprecation timeline, see https://github.com/linkedin/dustjs-helpers/wiki/Deprecated-Features#"+a.replace(/\W+/g,""),"WARN"),_deprecatedCache[a]=!0)}function isSelect(a){var b=a.current();return"object"==typeof b&&b.isSelect===!0}function jsonFilter(a,b){return"function"==typeof b?b.toString().replace(/(^\s+|\s+$)/gm,"").replace(/\n/gm,"").replace(/,\s*/gm,", ").replace(/\)\{/gm,") {"):b}function filter(a,b,c,d,e){d=d||{};var f,g,h=c.block,i=d.filterOpType||"";if(d.hasOwnProperty("key"))f=dust.helpers.tap(d.key,a,b);else{if(!isSelect(b))return _log("No key specified for filter in:"+i+" helper "),a;f=b.current().selectKey,b.current().isResolved&&(e=function(){return!1})}return g=dust.helpers.tap(d.value,a,b),e(coerce(g,d.type,b),coerce(f,d.type,b))?(isSelect(b)&&(b.current().isResolved=!0),h?a.render(h,b):(_log("No body specified for "+i+" helper "),a)):c["else"]?a.render(c["else"],b):a}function coerce(a,b,c){if("undefined"!=typeof a)switch(b||typeof a){case"number":return+a;case"string":return String(a);case"boolean":return a="false"===a?!1:a,Boolean(a);case"date":return new Date(a);case"context":return c.get(a)}return a}var _log=dust.log?function(a,b){b=b||"INFO",dust.log(a,b)}:function(){},_deprecatedCache={},helpers={tap:function(a,b,c){if("function"!=typeof a)return a;var d,e="";return d=b.tap(function(a){return e+=a,""}).render(a,c),b.untap(),d.constructor!==b.constructor?d:""===e?!1:e},sep:function(a,b,c){var d=c.block;return b.stack.index===b.stack.of-1?a:d?d(a,b):a},idx:function(a,b,c){var d=c.block;return _deprecated("{@idx}"),d?d(a,b.push(b.stack.index)):a},contextDump:function(a,b,c,d){var e,f=d||{},g=f.to||"output",h=f.key||"current";return g=dust.helpers.tap(g,a,b),h=dust.helpers.tap(h,a,b),e="full"===h?JSON.stringify(b.stack,jsonFilter,2):JSON.stringify(b.stack.head,jsonFilter,2),"console"===g?(_log(e),a):(e=e.replace(/</g,"\\u003c"),a.write(e))},"if":function(chunk,context,bodies,params){var body=bodies.block,skip=bodies["else"],cond;if(params&&params.cond){if(_deprecated("{@if}"),cond=dust.helpers.tap(params.cond,chunk,context),eval(cond))return body?chunk.render(bodies.block,context):(_log("Missing body block in the if helper!"),chunk);if(skip)return chunk.render(bodies["else"],context)}else _log("No condition given in the if helper!");return chunk},math:function(a,b,c,d){if(d&&"undefined"!=typeof d.key&&d.method){var e=d.key,f=d.method,g=d.operand,h=d.round,i=null;switch(e=dust.helpers.tap(e,a,b),g=dust.helpers.tap(g,a,b),f){case"mod":(0===g||g===-0)&&_log("operand for divide operation is 0/-0: expect Nan!"),i=parseFloat(e)%parseFloat(g);break;case"add":i=parseFloat(e)+parseFloat(g);break;case"subtract":i=parseFloat(e)-parseFloat(g);break;case"multiply":i=parseFloat(e)*parseFloat(g);break;case"divide":(0===g||g===-0)&&_log("operand for divide operation is 0/-0: expect Nan/Infinity!"),i=parseFloat(e)/parseFloat(g);break;case"ceil":i=Math.ceil(parseFloat(e));break;case"floor":i=Math.floor(parseFloat(e));break;case"round":i=Math.round(parseFloat(e));break;case"abs":i=Math.abs(parseFloat(e));break;default:_log("method passed is not supported")}return null!==i?(h&&(i=Math.round(i)),c&&c.block?a.render(c.block,b.push({isSelect:!0,isResolved:!1,selectKey:i})):a.write(i)):a}return _log("Key is a required parameter for math helper along with method/operand!"),a},select:function(a,b,c,d){var e=c.block;if(d&&"undefined"!=typeof d.key){var f=dust.helpers.tap(d.key,a,b);return e?a.render(c.block,b.push({isSelect:!0,isResolved:!1,selectKey:f})):(_log("Missing body block in the select helper "),a)}return _log("No key given in the select helper!"),a},eq:function(a,b,c,d){return d?(d.filterOpType="eq",filter(a,b,c,d,function(a,b){return b===a})):a},ne:function(a,b,c,d){return d?(d.filterOpType="ne",filter(a,b,c,d,function(a,b){return b!==a})):a},lt:function(a,b,c,d){return d?(d.filterOpType="lt",filter(a,b,c,d,function(a,b){return a>b})):a},lte:function(a,b,c,d){return d?(d.filterOpType="lte",filter(a,b,c,d,function(a,b){return a>=b})):a},gt:function(a,b,c,d){return d?(d.filterOpType="gt",filter(a,b,c,d,function(a,b){return b>a})):a},gte:function(a,b,c,d){return d?(d.filterOpType="gte",filter(a,b,c,d,function(a,b){return b>=a})):a},"default":function(a,b,c,d){return d&&(d.filterOpType="default"),filter(a,b,c,d,function(){return!0})},size:function(a,b,c,d){var e,f,g,h=0;if(d=d||{},e=d.key,e&&e!==!0)if(dust.isArray(e))h=e.length;else if(!isNaN(parseFloat(e))&&isFinite(e))h=e;else if("object"==typeof e){f=0;for(g in e)Object.hasOwnProperty.call(e,g)&&f++;h=f}else h=(e+"").length;else h=0;return a.write(h)}};for(var key in helpers)dust.helpers[key]=helpers[key];"undefined"!=typeof exports&&(module.exports=dust)}("undefined"!=typeof exports?require("dustjs-linkedin"):dust);
(function(dust){
//using the built in logging method of dust when accessible
var _log = dust.log ? function(mssg) { dust.log(mssg, "INFO"); } : function() {};
// Use dust's built-in logging when available
var _log = dust.log ? function(msg, level) {
level = level || "INFO";
dust.log(msg, level);
} : function() {};
var _deprecatedCache = {};
function _deprecated(target) {
if(_deprecatedCache[target]) { return; }
_log("Deprecation warning: " + target + " is deprecated and will be removed in a future version of dustjs-helpers", "WARN");
_log("For help and a deprecation timeline, see https://github.com/linkedin/dustjs-helpers/wiki/Deprecated-Features#" + target.replace(/\W+/g, ""), "WARN");
_deprecatedCache[target] = true;
}
function isSelect(context) {

@@ -36,7 +47,7 @@ var value = context.current();

filterOpType = params.filterOpType || '';
// when @eq, @lt etc are used as standalone helpers, key is required and hence check for defined
if ( typeof params.key !== "undefined") {
if (params.hasOwnProperty("key")) {
actualKey = dust.helpers.tap(params.key, chunk, context);
}
else if (isSelect(context)) {
} else if (isSelect(context)) {
actualKey = context.current().selectKey;

@@ -47,4 +58,3 @@ // supports only one of the blocks in the select to be selected

}
}
else {
} else {
_log("No key specified for filter in:" + filterOpType + " helper ");

@@ -62,9 +72,7 @@ return chunk;

return chunk.render(body, context);
}
else {
_log("No key specified for filter in:" + filterOpType + " helper ");
} else {
_log("No body specified for " + filterOpType + " helper ");
return chunk;
}
}
else if (bodies['else']) {
} else if (bodies['else']) {
return chunk.render(bodies['else'], context);

@@ -75,11 +83,10 @@ }

function coerce (value, type, context) {
if (value) {
switch (type || typeof(value)) {
function coerce(value, type, context) {
if (typeof value !== "undefined") {
switch (type || typeof value) {
case 'number': return +value;
case 'string': return String(value);
case 'boolean': {
case 'boolean':
value = (value === 'false' ? false : value);
return Boolean(value);
}
case 'date': return new Date(value);

@@ -147,8 +154,7 @@ case 'context': return context.get(value);

}
if(body) {
return bodies.block(chunk, context);
if (body) {
return body(chunk, context);
} else {
return chunk;
}
else {
return chunk;
}
},

@@ -158,8 +164,10 @@

var body = bodies.block;
if(body) {
return bodies.block(chunk, context.push(context.stack.index));
}
else {
return chunk;
}
// Will be removed in 1.6
_deprecated("{@idx}");
if(body) {
return body(chunk, context.push(context.stack.index));
}
else {
return chunk;
}
},

@@ -214,8 +222,12 @@

"if": function( chunk, context, bodies, params ){
"if": function( chunk, context, bodies, params ) {
var body = bodies.block,
skip = bodies['else'];
if( params && params.cond){
var cond = params.cond;
cond = dust.helpers.tap(cond, chunk, context);
skip = bodies['else'],
cond;
if(params && params.cond) {
// Will be removed in 1.6
_deprecated("{@if}");
cond = dust.helpers.tap(params.cond, chunk, context);
// eval expressions with given dust references

@@ -222,0 +234,0 @@ if(eval(cond)){

{
"name": "dustjs-helpers",
"version": "1.4.0",
"version": "1.5.0",
"author": {

@@ -55,9 +55,13 @@ "name": "Aleksander Williams",

"views",
"helpers"
"helpers",
"dust",
"dustjs",
"dust.js",
"linkedin"
],
"peerDependencies": {
"dustjs-linkedin": "2.4 - 2.5"
"dustjs-linkedin": "2.5 - 2.6"
},
"devDependencies": {
"dustjs-linkedin": "2.4 - 2.5",
"dustjs-linkedin": "2.5 - 2.6",
"jasmine-node": "~1.13.0",

@@ -64,0 +68,0 @@ "grunt": "~0.4.2",

# Dust Helpers [![Build Status](https://secure.travis-ci.org/linkedin/dustjs-helpers.png)](http://travis-ci.org/linkedin/dustjs-helpers)
Additional functionality for [dustjs-linkedin](http://linkedin.github.com/dustjs/) package
Read more here : <https://github.com/linkedin/dustjs-helpers>
This repository holds context helpers for Dust.
## Getting Started
A quick tutorial for how to use Dust <https://github.com/linkedin/dustjs/wiki/Dust-Tutorial>
Context helpers are augments to the core Dust template syntax.
It's possible to write your own helpers and extend the functionality of Dust's templating system.
## Contributing
* Open https://github.com/linkedin/dustjs-helpers in a browser and fork it. Then clone your fork:
The helpers we provide as part of this repository fulfill some of the most common use cases encountered while using Dust.
We provide official support for these helpers as part of the core Dust library.
git clone https://github.com/<your github account>/dustjs-helpers dustjs-helpers
cd dustjs-helpers
Read the wiki for more information: <https://github.com/linkedin/dustjs-helpers/wiki>
* Set up a branch for what you are working on
## Getting Started
The helpers depend on and augment Dust.js.If you need a refresher, read a [quick tutorial on using Dust](https://github.com/linkedin/dustjs/wiki/Dust-Tutorial).
git checkout -b myBranchName
You can look at a [list of the helpers](https://github.com/linkedin/dustjs-helpers/wiki/Helpers) contained in this package, along with usage examples, on the wiki.
* Install Grunt-cli, it lets you run `grunt` commands. For more information see <http://gruntjs.com/getting-started>
npm install -g grunt-cli
* Install node dependencies needed for development in this project
npm install
* Make your changes on the branch and run jshint\tests to make sure changes are OK
grunt test
* Commit your changes and push them to github
git add .
git commit -m "My changes to dustjs-helpers repo"
git push origin myBranchName
* Go to github and post a pull request, see <https://help.github.com/articles/creating-a-pull-request>
## Debugging
To debug code in a browser run `grunt dev` task. It will generate jasmine spec runner and serve it on `http://localhost:3000/_SpecRunner.html` URL.
Generated spec runner references unminified dust-helpers.js and dust-full.js files. This will allow you to easily step through the code and set up breakpoints.
This task also watches changes to lib directory, so you can simply refresh the page to see the changes without a need to re-run `grunt dev` task. Press `Ctrl + C` to disconnect from server.
## Using watch
`grunt watch` will monitor dust-helpers.js and test spec files. Whenever change is made to those files, it will jshint them and run unit tests in Phantom (will not run them in node or rhino).
It is handy way to keep testing your changes without a need to manually run `grunt testPhantom` task.
Be sure to run `grunt test` before sending pull request. It will test your change in all environments and make sure that a travis build for your pull request succeeds.
## Testing minified code in browser
Use `grunt testClient` to test prod version code in any browser. Similarly to `grunt dev` task it will host spec runner on `http://localhost:3000/_SpecRunner.html` URL.
## Coverage report
Task `grunt coverage` runs jasmine unit tests against unminified source code and generates coverage report under `tmp/coverage` folder.
Open `index.html` file in a browser to view the coverage.
The [changelog](https://github.com/linkedin/dustjs-helpers/blob/master/CHANGELOG.md) documents all added, deprecated, and removed functionality.
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