dustjs-helpers
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -1,2 +0,2 @@ | ||
/*! dustjs-helpers - v1.2.0 | ||
/*! dustjs-helpers - v1.3.0 | ||
* https://github.com/linkedin/dustjs-helpers | ||
@@ -6,14 +6,5 @@ * Copyright (c) 2014 Aleksander Williams; Released under the MIT License */ | ||
// Note: all error conditions are logged to console and failed silently | ||
//using the built in logging method of dust when accessible | ||
var _log = dust.log ? function(mssg) { dust.log(mssg, "INFO"); } : function() {}; | ||
/* make a safe version of console if it is not available | ||
* currently supporting: | ||
* _console.log | ||
* */ | ||
var _console = (typeof console !== 'undefined')? console: { | ||
log: function(){ | ||
/* a noop*/ | ||
} | ||
}; | ||
function isSelect(context) { | ||
@@ -61,3 +52,3 @@ var value = context.current(); | ||
else { | ||
_console.log ("No key specified for filter in:" + filterOpType + " helper "); | ||
_log("No key specified for filter in:" + filterOpType + " helper "); | ||
return chunk; | ||
@@ -76,3 +67,3 @@ } | ||
else { | ||
_console.log( "Missing body block in the " + filterOpType + " helper "); | ||
_log("No key specified for filter in:" + filterOpType + " helper "); | ||
return chunk; | ||
@@ -197,3 +188,3 @@ } | ||
if (to === 'console') { | ||
_console.log(dump); | ||
_log(dump); | ||
return chunk; | ||
@@ -233,3 +224,3 @@ } | ||
else { | ||
_console.log( "Missing body block in the if helper!" ); | ||
_log("Missing body block in the if helper!"); | ||
return chunk; | ||
@@ -244,3 +235,3 @@ } | ||
else { | ||
_console.log( "No condition given in the if helper!" ); | ||
_log("No condition given in the if helper!"); | ||
} | ||
@@ -266,3 +257,6 @@ return chunk; | ||
mathOut = null, | ||
operError = function(){_console.log("operand is required for this math method"); return null;}; | ||
operError = function(){ | ||
_log("operand is required for this math method"); | ||
return null; | ||
}; | ||
key = dust.helpers.tap(key, chunk, context); | ||
@@ -274,3 +268,3 @@ operand = dust.helpers.tap(operand, chunk, context); | ||
if(operand === 0 || operand === -0) { | ||
_console.log("operand for divide operation is 0/-0: expect Nan!"); | ||
_log("operand for divide operation is 0/-0: expect Nan!"); | ||
} | ||
@@ -290,3 +284,3 @@ mathOut = parseFloat(key) % parseFloat(operand); | ||
if(operand === 0 || operand === -0) { | ||
_console.log("operand for divide operation is 0/-0: expect Nan/Infinity!"); | ||
_log("operand for divide operation is 0/-0: expect Nan/Infinity!"); | ||
} | ||
@@ -308,3 +302,3 @@ mathOut = parseFloat(key) / parseFloat(operand); | ||
default: | ||
_console.log( "method passed is not supported" ); | ||
_log("method passed is not supported"); | ||
} | ||
@@ -330,3 +324,3 @@ | ||
else { | ||
_console.log( "Key is a required parameter for math helper along with method/operand!" ); | ||
_log("Key is a required parameter for math helper along with method/operand!"); | ||
} | ||
@@ -354,3 +348,3 @@ return chunk; | ||
else { | ||
_console.log( "Missing body block in the select helper "); | ||
_log("Missing body block in the select helper "); | ||
return chunk; | ||
@@ -361,3 +355,3 @@ } | ||
else { | ||
_console.log( "No key given in the select helper!" ); | ||
_log("No key given in the select helper!"); | ||
} | ||
@@ -528,4 +522,10 @@ return chunk; | ||
dust.helpers = helpers; | ||
for (var key in helpers) { | ||
dust.helpers[key] = helpers[key]; | ||
} | ||
})(typeof exports !== 'undefined' ? module.exports = require('dustjs-linkedin') : dust); | ||
if(typeof exports !== 'undefined') { | ||
module.exports = dust; | ||
} | ||
})(typeof exports !== 'undefined' ? require('dustjs-linkedin') : dust); |
@@ -1,4 +0,4 @@ | ||
/*! dustjs-helpers - v1.2.0 | ||
/*! dustjs-helpers - v1.3.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 _console.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):(_console.log("Missing body block in the "+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 _console="undefined"!=typeof console?console:{log: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?(_console.log(e),a):a.write(e)},"if":function(chunk,context,bodies,params){var body=bodies.block,skip=bodies["else"];if(params&¶ms.cond){var cond=params.cond;if(cond=dust.helpers.tap(cond,chunk,context),eval(cond))return body?chunk.render(bodies.block,context):(_console.log("Missing body block in the if helper!"),chunk);if(skip)return chunk.render(bodies["else"],context)}else _console.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)&&_console.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)&&_console.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:_console.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 _console.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})):(_console.log("Missing body block in the select helper "),a)}return _console.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})},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})):void 0},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)}};dust.helpers=helpers}("undefined"!=typeof exports?module.exports=require("dustjs-linkedin"):dust); | ||
!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):a.write(e)},"if":function(chunk,context,bodies,params){var body=bodies.block,skip=bodies["else"];if(params&¶ms.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})},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})):void 0},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){ | ||
// Note: all error conditions are logged to console and failed silently | ||
//using the built in logging method of dust when accessible | ||
var _log = dust.log ? function(mssg) { dust.log(mssg, "INFO"); } : function() {}; | ||
/* make a safe version of console if it is not available | ||
* currently supporting: | ||
* _console.log | ||
* */ | ||
var _console = (typeof console !== 'undefined')? console: { | ||
log: function(){ | ||
/* a noop*/ | ||
} | ||
}; | ||
function isSelect(context) { | ||
@@ -57,3 +48,3 @@ var value = context.current(); | ||
else { | ||
_console.log ("No key specified for filter in:" + filterOpType + " helper "); | ||
_log("No key specified for filter in:" + filterOpType + " helper "); | ||
return chunk; | ||
@@ -72,3 +63,3 @@ } | ||
else { | ||
_console.log( "Missing body block in the " + filterOpType + " helper "); | ||
_log("No key specified for filter in:" + filterOpType + " helper "); | ||
return chunk; | ||
@@ -193,3 +184,3 @@ } | ||
if (to === 'console') { | ||
_console.log(dump); | ||
_log(dump); | ||
return chunk; | ||
@@ -229,3 +220,3 @@ } | ||
else { | ||
_console.log( "Missing body block in the if helper!" ); | ||
_log("Missing body block in the if helper!"); | ||
return chunk; | ||
@@ -240,3 +231,3 @@ } | ||
else { | ||
_console.log( "No condition given in the if helper!" ); | ||
_log("No condition given in the if helper!"); | ||
} | ||
@@ -262,3 +253,6 @@ return chunk; | ||
mathOut = null, | ||
operError = function(){_console.log("operand is required for this math method"); return null;}; | ||
operError = function(){ | ||
_log("operand is required for this math method"); | ||
return null; | ||
}; | ||
key = dust.helpers.tap(key, chunk, context); | ||
@@ -270,3 +264,3 @@ operand = dust.helpers.tap(operand, chunk, context); | ||
if(operand === 0 || operand === -0) { | ||
_console.log("operand for divide operation is 0/-0: expect Nan!"); | ||
_log("operand for divide operation is 0/-0: expect Nan!"); | ||
} | ||
@@ -286,3 +280,3 @@ mathOut = parseFloat(key) % parseFloat(operand); | ||
if(operand === 0 || operand === -0) { | ||
_console.log("operand for divide operation is 0/-0: expect Nan/Infinity!"); | ||
_log("operand for divide operation is 0/-0: expect Nan/Infinity!"); | ||
} | ||
@@ -304,3 +298,3 @@ mathOut = parseFloat(key) / parseFloat(operand); | ||
default: | ||
_console.log( "method passed is not supported" ); | ||
_log("method passed is not supported"); | ||
} | ||
@@ -326,3 +320,3 @@ | ||
else { | ||
_console.log( "Key is a required parameter for math helper along with method/operand!" ); | ||
_log("Key is a required parameter for math helper along with method/operand!"); | ||
} | ||
@@ -350,3 +344,3 @@ return chunk; | ||
else { | ||
_console.log( "Missing body block in the select helper "); | ||
_log("Missing body block in the select helper "); | ||
return chunk; | ||
@@ -357,3 +351,3 @@ } | ||
else { | ||
_console.log( "No key given in the select helper!" ); | ||
_log("No key given in the select helper!"); | ||
} | ||
@@ -524,4 +518,10 @@ return chunk; | ||
dust.helpers = helpers; | ||
for (var key in helpers) { | ||
dust.helpers[key] = helpers[key]; | ||
} | ||
})(typeof exports !== 'undefined' ? module.exports = require('dustjs-linkedin') : dust); | ||
if(typeof exports !== 'undefined') { | ||
module.exports = dust; | ||
} | ||
})(typeof exports !== 'undefined' ? require('dustjs-linkedin') : dust); |
{ | ||
"name": "dustjs-helpers", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"author": { | ||
@@ -57,6 +57,7 @@ "name": "Aleksander Williams", | ||
], | ||
"dependencies": { | ||
"dustjs-linkedin": "~2.3.0" | ||
"peerDependencies": { | ||
"dustjs-linkedin": "~2.4.0" | ||
}, | ||
"devDependencies": { | ||
"dustjs-linkedin": "~2.4.0", | ||
"jasmine-node": "~1.13.0", | ||
@@ -67,2 +68,4 @@ "grunt": "~0.4.2", | ||
"grunt-template-jasmine-istanbul": "~0.2.5", | ||
"grunt-contrib-connect": "~0.5.0", | ||
"grunt-contrib-watch": "~0.5.3", | ||
"grunt-contrib-uglify": "~0.3.0", | ||
@@ -69,0 +72,0 @@ "grunt-contrib-copy": "~0.5.0", |
@@ -39,3 +39,17 @@ # Dust Helpers [![Build Status](https://secure.travis-ci.org/linkedin/dustjs-helpers.png)](http://travis-ci.org/linkedin/dustjs-helpers) | ||
## 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 | ||
Running `grunt test` or `grunt testPhantom` generates coverage report under `tmp/coverage` folder. Open `index.html` file in a browser to view the coverage. | ||
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. |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
51780
54
14
962
+ Addeddustjs-linkedin@2.4.2(transitive)
- Removeddustjs-linkedin@~2.3.0
- Removeddustjs-linkedin@2.3.6(transitive)