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

@cloudfour/hbs-helpers

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cloudfour/hbs-helpers - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

17

lib/and.js

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

/**
* Output a block (or its inverse) based on whether or not both of the suppied
* Output a block (or its inverse) based on whether or not both of the supplied
* arguments are truthy.

@@ -17,12 +17,11 @@ *

* @example
* var a = true;
* var b = 1;
* var c = false;
*
* var a = true;
* var b = 1;
* var c = false;
*
* {{#and a b}}✔︎{{else}}✘{{/and}} //=> ✔︎
* {{#and b c}}✔︎{{else}}✘{{/and}} //=> ✘
* {{#and a b}}✔︎{{else}}✘{{/and}} //=> ✔︎
* {{#and b c}}✔︎{{else}}✘{{/and}} //=> ✘
*/
module.exports = function and (left, right, options) {
function and (left, right, options) {
if (arguments.length < 3) {

@@ -34,1 +33,3 @@ throw new Error('The "and" helper needs two arguments.');

}
module.exports = and;

@@ -23,20 +23,19 @@ 'use strict';

* @example
* <ul>
* {{#around pages 5 2 offset=-1}}
* <li><a href="/page/{{num}}">Page {{num}}</a></li>
* {{/around}}
* </ul>
*
* <ul>
* {{#around pages 5 2 offset=-1}}
* <li><a href="/page/{{num}}">Page {{num}}</a></li>
* {{/around}}
* </ul>
*
* {{! Output: }}
* <ul>
* <li><a href="/page/3">Page 3</a></li>
* <li><a href="/page/4">Page 4</a></li>
* <li><a href="/page/5">Page 5</a></li>
* <li><a href="/page/6">Page 6</a></li>
* <li><a href="/page/7">Page 7</a></li>
* </ul>
* {{! Output: }}
* <ul>
* <li><a href="/page/3">Page 3</a></li>
* <li><a href="/page/4">Page 4</a></li>
* <li><a href="/page/5">Page 5</a></li>
* <li><a href="/page/6">Page 6</a></li>
* <li><a href="/page/7">Page 7</a></li>
* </ul>
*/
module.exports = function around (items, center, padding, block) {
function around (items, center, padding, block) {
var result = '';

@@ -73,1 +72,3 @@ var options = (block && block.hash) ? R.merge(defaults, block.hash) : R.clone(defaults);

};
module.exports = around;

@@ -10,11 +10,10 @@ 'use strict';

* @example
* var numbers = [1, 2, 3];
* var products = [{rating: 1}, {rating: 2}, {rating: 3}];
*
* var numbers = [1, 2, 3];
* var products = [{rating: 1}, {rating: 2}, {rating: 3}];
*
* {{average ratings}} //=> 2
* {{average products key="rating"}} //=> 2
* {{average ratings}} //=> 2
* {{average products key="rating"}} //=> 2
*/
module.exports = function average (arr, options) {
function average (arr, options) {
var isArray = Array.isArray(arr);

@@ -37,1 +36,3 @@ var key = options.hash.key;

}
module.exports = average;

@@ -13,7 +13,6 @@ 'use strict';

* @example:
*
* {{capitalize "hello world"}} //=> "Hello world"
* {{capitalize "hello world"}} //=> "Hello world"
*/
module.exports = function capitalize (str) {
function capitalize (str) {
if (R.isNil(str)) {

@@ -29,1 +28,3 @@ throw new Error('The "capitalize" helper requires one argument.')

};
module.exports = capitalize;

@@ -14,9 +14,8 @@ 'use strict';

* @example:
*
* {{capitalizeWords "hello world"}} //=> "Hello World"
* {{capitalizeWords "hello-cañapolísas"}} //=> "Hello-Cañapolísas"
* {{capitalizeWords "it's a nice day"}} //=> "It's A Nice Day"
* {{capitalizeWords "hello world"}} //=> "Hello World"
* {{capitalizeWords "hello-cañapolísas"}} //=> "Hello-Cañapolísas"
* {{capitalizeWords "it's a nice day"}} //=> "It's A Nice Day"
*/
module.exports = function capitalizeWords (str) {
function capitalizeWords (str) {
if (R.isNil(str)) {

@@ -32,1 +31,3 @@ throw new Error('The "capitalizeWords" helper requires one argument.')

};
module.exports = capitalizeWords;

@@ -5,2 +5,14 @@ 'use strict';

var operators = {
'==': R.equals,
'===': R.identical,
'!=': R.complement(R.equals),
'!==': R.complement(R.identical),
'<': R.lt,
'>': R.gt,
'<=': R.lte,
'>=': R.gte,
'typeof': R.type(R.__)
};
/**

@@ -14,25 +26,18 @@ * Compare two values using logical operators.

* @param {Object} options
* @return {String} formatted html
* @return {(String|Boolean)} formatted html if block, true/false if inline
* @example:
* {{#compare 1 "<" 2}}
* This is true.
* {{else}}
* This is false.
* {{/compare}}
*
* {{#compare 1 "<" 2}}
* This is true.
* {{else}}
* This is false.
* {{/compare}}
* {{#if (compare 1 "<" 2)}}
* Also works inline!
* {{/if}}
*/
module.exports = function compare (left, operator, right, options) {
var operators = {
'==': R.equals,
'===': R.identical,
'!=': R.complement(R.equals),
'!==': R.complement(R.identical),
'<': R.lt,
'>': R.gt,
'<=': R.lte,
'>=': R.gte,
'typeof': R.type(R.__)
};
function compare (left, operator, right, options) {
var result;
if (arguments.length < 3) {

@@ -52,4 +57,11 @@ throw new Error('The "compare" helper needs two arguments.');

return operators[operator](left, right) ?
options.fn(this) : options.inverse(this);
result = operators[operator](left, right);
if (R.isNil(options.fn)) {
return result;
}
return result ? options.fn(this) : options.inverse(this);
};
module.exports = compare;

@@ -12,6 +12,5 @@ 'use strict';

* @example
*
* {{concat "foo" "bar"}} //=> "foobar"
* {{concat "foo" "bar"}} //=> "foobar"
*/
module.exports = function concat () {
function concat () {
var items = R.dropLast(1, arguments);

@@ -25,1 +24,3 @@

}
module.exports = concat;

@@ -13,14 +13,15 @@ 'use strict';

* @example
* var doesExist = 'Hello';
*
* var doesExist = 'Hello';
*
* {{defaultTo doesExist "Goodbye"}} // => "Hello"
* {{defaultTo doesNotExist "Goodbye"}} // => "Goodbye"
* {{defaultTo doesNotExist}} // => ""
* {{defaultTo doesNotExist doesExist "Goodbye"}} // => "Hello"
* {{defaultTo doesExist "Goodbye"}} // => "Hello"
* {{defaultTo doesNotExist "Goodbye"}} // => "Goodbye"
* {{defaultTo doesNotExist}} // => ""
* {{defaultTo doesNotExist doesExist "Goodbye"}} // => "Hello"
*/
module.exports = function defaultTo () {
function defaultTo () {
var values = R.append('', R.dropLast(1, arguments));
return R.head(R.reject(R.isNil, values));
};
module.exports = defaultTo;

@@ -61,13 +61,12 @@ 'use strict';

* @example
* <img src="{{dummyImgSrc 150 50}}">
*
* <img src="{{dummyImgSrc 150 50}}">
* <img src="{{dummyImgSrc 150 50 text="foo"}}">
*
* <img src="{{dummyImgSrc 150 50 text="foo"}}">
* <img src="{{dummyImgSrc 150 50 bg="#000"}}">
*
* <img src="{{dummyImgSrc 150 50 bg="#000"}}">
*
* <img src="{{dummyImgSrc 150 50 fg="pink"}}">
* <img src="{{dummyImgSrc 150 50 fg="pink"}}">
*/
module.exports = function dummyImgSrc (width, height, options) {
function dummyImgSrc (width, height, options) {
if (!R.is(Number, width) || !R.is(Number, height)) {

@@ -81,1 +80,3 @@ throw new Error('The "dummyImgSrc" helper must be passed two numeric dimensions.');

};
module.exports = dummyImgSrc;

@@ -12,9 +12,8 @@ 'use strict';

* @example
*
* {{#iterate 10}}
* <li>Index: {{@index}} Count: {{@count}}</li>
* {{/iterate}}
* {{#iterate 10}}
* <li>Index: {{@index}} Count: {{@count}}</li>
* {{/iterate}}
*/
module.exports = function iterate (num, block) {
function iterate (num, block) {
return R.times(function (i) {

@@ -29,1 +28,3 @@ var data = block.data ? R.merge(

};
module.exports = iterate;

@@ -25,14 +25,13 @@ 'use strict';

* @example:
*
* {{math 1 "+" 2}} //=> 3
* {{math 2 "-" 1}} //=> 1
* {{math 2 "*" 3}} //=> 6
* {{math 9 "/" 3}} //=> 3
* {{math 17 "%" 3}} //=> 2
* {{math 2 "**" 3}} //=> 8
* {{math 1 "++"}} //=> 2
* {{math 2 "--"}} //=> 1
* {{math 1 "+" 2}} //=> 3
* {{math 2 "-" 1}} //=> 1
* {{math 2 "*" 3}} //=> 6
* {{math 9 "/" 3}} //=> 3
* {{math 17 "%" 3}} //=> 2
* {{math 2 "**" 3}} //=> 8
* {{math 1 "++"}} //=> 2
* {{math 2 "--"}} //=> 1
*/
module.exports = function math (left, operator, right, options) {
function math (left, operator, right, options) {
if (arguments.length < 3) {

@@ -56,1 +55,3 @@ throw new Error('The "math" helper needs at least two arguments.');

}
module.exports = math;

@@ -9,11 +9,10 @@ 'use strict';

* @example
*
* {{#maybe}}
* Heads!
* {{else}}
* Tails!
* {{/maybe}}
* {{#maybe}}
* Heads!
* {{else}}
* Tails!
* {{/maybe}}
*/
module.exports = function maybe (options) {
function maybe (options) {
if (Math.round(Math.random())) {

@@ -25,1 +24,3 @@ return options.fn(this);

};
module.exports = maybe;

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

/**
* Output a block (or its inverse) based on whether or not either of the suppied
* Output a block (or its inverse) based on whether or not either of the supplied
* arguments are truthy.

@@ -17,14 +17,13 @@ *

* @example
* var a = true;
* var b = 1;
* var c = false;
* var d = 0;
*
* var a = true;
* var b = 1;
* var c = false;
* var d = 0;
*
* {{#or a c}}✔︎{{else}}✘{{/or}} //=> ✔︎
* {{#or b c}}✔︎{{else}}✘{{/or}} //=> ✔︎
* {{#or c d}}✔︎{{else}}✘{{/or}} //=> ✘
* {{#or a c}}✔︎{{else}}✘{{/or}} //=> ✔︎
* {{#or b c}}✔︎{{else}}✘{{/or}} //=> ✔︎
* {{#or c d}}✔︎{{else}}✘{{/or}} //=> ✘
*/
module.exports = function or (left, right, options) {
function or (left, right, options) {
if (arguments.length < 3) {

@@ -36,1 +35,3 @@ throw new Error('The "or" helper needs two arguments.');

}
module.exports = or;

@@ -18,10 +18,9 @@ 'use strict';

* @example
*
* {{random}} //=> 1839473434
* {{random min=5 max=10}} //=> 7
* {{random "state"}} //=> WA
* {{random "dollar" max=20}} //=> $17.42
* {{random}} //=> 1839473434
* {{random min=5 max=10}} //=> 7
* {{random "state"}} //=> WA
* {{random "dollar" max=20}} //=> $17.42
*/
module.exports = function random () {
function random () {
var options = R.last(arguments);

@@ -43,1 +42,3 @@ var hash = options.hash || {};

};
module.exports = random;

@@ -14,10 +14,9 @@ 'use strict';

* @example
* var beatles = ["John", "Paul", "George", "Ringo"];
* {{randomItem beatles}} //=> "George"
*
* var beatles = ["John", "Paul", "George", "Ringo"];
* {{randomItem beatles}} //=> "George"
*
* {{randomItem "John" "Paul" "George" "Ringo"}} //=> "Ringo"
* {{randomItem "John" "Paul" "George" "Ringo"}} //=> "Ringo"
*/
module.exports = function randomItem () {
function randomItem () {
var items = R.dropLast(1, arguments);

@@ -35,1 +34,3 @@

};
module.exports = randomItem;

@@ -23,11 +23,10 @@ 'use strict';

* @example
* {{timestamp "2015-10-21" format="MMM Do, YYYY"}} //=> "Oct 21st, 2015"
*
* {{timestamp "2015-10-21" format="MMM Do, YYYY"}} //=> "Oct 21st, 2015"
* {{timestamp "Oct 21 15" inputFormat="MMM DD YY" format="YYYY-MM-DD"}} //=> "2015-10-21"
*
* {{timestamp "Oct 21 15" inputFormat="MMM DD YY" format="YYYY-MM-DD"}} //=> "2015-10-21"
*
* {{timestamp "2000-01-01" format="YYYY" utc=false}} //=> "1999"
* {{timestamp "2000-01-01" format="YYYY" utc=false}} //=> "1999"
*/
module.exports = function timestamp (context, block) {
function timestamp (context, block) {
var options, constructor, date;

@@ -57,1 +56,3 @@

};
module.exports = timestamp;

@@ -10,7 +10,6 @@ 'use strict';

* @example
*
* {{toFixed 1}} //=> 1.00
* {{toFixed 1}} //=> 1.00
*/
module.exports = function toFixed (num) {
function toFixed (num) {
var int = parseFloat(num);

@@ -22,1 +21,3 @@ if (isNaN(int)) {

};
module.exports = toFixed;

@@ -30,9 +30,8 @@ 'use strict';

* @example
*
* {{toFraction 1.25}} //=> "1¼"
* {{toFraction 3.1666}} //=> "3⅙"
* {{toFraction 2.7}} //=> 2.7
* {{toFraction 1.25}} //=> "1¼"
* {{toFraction 3.1666}} //=> "3⅙"
* {{toFraction 2.7}} //=> 2.7
*/
module.exports = function toFraction (value) {
function toFraction (value) {
var integer = Math.floor(value);

@@ -49,1 +48,3 @@ var decimal = value - integer;

};
module.exports = toFraction;

@@ -10,7 +10,6 @@ 'use strict';

* @example
*
* {{#each (toJSON '[1,2,3]')}}{{this}}{{/each}} //=> '123'
* {{#each (toJSON '[1,2,3]')}}{{this}}{{/each}} //=> '123'
*/
module.exports = function toJSON (str) {
function toJSON (str) {
str = str.toString();

@@ -25,1 +24,3 @@ try {

};
module.exports = toJSON;

@@ -10,7 +10,6 @@ 'use strict';

* @example
*
* {{toSlug "Well, hello there!"}} //=> "well-hello-there"
* {{toSlug "Well, hello there!"}} //=> "well-hello-there"
*/
module.exports = function toSlug (str) {
function toSlug (str) {
return str

@@ -25,1 +24,3 @@ .toString()

};
module.exports = toSlug;

@@ -11,7 +11,6 @@ 'use strict';

* @example
*
* {{toTitle "01 Introduction"}} //=> "Introduction"
* {{toTitle "01 Introduction"}} //=> "Introduction"
*/
module.exports = function toTitle (name) {
function toTitle (name) {
var pattern = /^[0-9]{0,4}[-_]?\s+?/;

@@ -21,1 +20,3 @@ name = name.toString();

};
module.exports = toTitle;
{
"name": "@cloudfour/hbs-helpers",
"version": "0.8.0",
"version": "0.9.0",
"description": "Handlebars helpers used for various Cloud Four projects.",

@@ -5,0 +5,0 @@ "author": "Cloud Four (http://cloudfour.com)",

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