@budibase/handlebars-helpers
Advanced tools
Comparing version 0.12.2 to 0.13.0
@@ -53,3 +53,3 @@ /*! | ||
hbs.registerHelper(group); | ||
return hbs.helpers; | ||
return group; | ||
}; | ||
@@ -56,0 +56,0 @@ } |
@@ -21,3 +21,3 @@ 'use strict'; | ||
* @api public | ||
* @example {{ after [1, 2, 3] 1}} -> [3] | ||
* @example {{ after ['a', 'b', 'c', 'd'] 2}} -> ['c', 'd'] | ||
*/ | ||
@@ -59,3 +59,3 @@ | ||
* {{before array 2}} | ||
* <!-- results in: '['a', 'b']' --> | ||
* <!-- results in: '['a']' --> | ||
* ``` | ||
@@ -66,3 +66,3 @@ * @param {Array} `array` | ||
* @api public | ||
* @example {{ before [1, 2, 3] 2}} -> [1, 2] | ||
* @example {{ before ['a', 'b', 'c', 'd'] 3}} -> ['a', 'b'] | ||
*/ | ||
@@ -74,3 +74,3 @@ | ||
if (Array.isArray(array)) { | ||
return array.slice(0, -n); | ||
return array.slice(0, n - 1); | ||
} | ||
@@ -101,3 +101,3 @@ return ''; | ||
for (var i = 0; i < array.length; i++) { | ||
result += options.fn({item: array[i], index: i}); | ||
result += options.fn({ item: array[i], index: i }); | ||
} | ||
@@ -130,3 +130,2 @@ } | ||
if (Array.isArray(array)) { | ||
var content = ''; | ||
@@ -142,3 +141,2 @@ var results = []; | ||
} else { | ||
// filter on a string value | ||
@@ -171,3 +169,3 @@ results = array.filter(function(v) { | ||
* @api public | ||
* @example {{first [1, 2, 3, 4] 2}} -> [1, 2] | ||
* @example {{first [1, 2, 3, 4] 2}} -> 1,2 | ||
*/ | ||
@@ -237,4 +235,4 @@ | ||
item.isFirst = i === 0; | ||
item.isLast = i === (len - 1); | ||
buffer += options.fn(item, {data: data}); | ||
item.isLast = i === len - 1; | ||
buffer += options.fn(item, { data: data }); | ||
} | ||
@@ -266,3 +264,3 @@ return buffer; | ||
* @api public | ||
* @example {{#inArray [1, 2, 3] 2}} 2 exists {{else}} 2 does not exist {{/inArray}} -> 2 exists | ||
* @example {{#inArray [1, 2, 3] 2}} 2 exists {{else}} 2 does not exist {{/inArray}} -> ' 2 exists ' | ||
*/ | ||
@@ -347,3 +345,3 @@ | ||
* @api public | ||
* @example {{join [1, 2, 3]}} -> '1, 2, 3' | ||
* @example {{join [1, 2, 3]}} -> 1, 2, 3 | ||
*/ | ||
@@ -372,3 +370,3 @@ | ||
* @api public | ||
* @example {{equalsLength '[1,2,3]' 3}} -> true | ||
* @example {{equalsLength [1, 2, 3] 3}} -> true | ||
*/ | ||
@@ -439,3 +437,3 @@ | ||
* @api public | ||
* @example {{length '[1, 2, 3]'}} -> 3 | ||
* @example {{length [1, 2, 3]}} -> 3 | ||
*/ | ||
@@ -449,3 +447,7 @@ | ||
// this is an inline array, split it | ||
if (typeof array === 'string' && array.startsWith('[') && array.endsWith(']')) { | ||
if ( | ||
typeof array === 'string' && | ||
array.startsWith('[') && | ||
array.endsWith(']') | ||
) { | ||
return array.split(',').length; | ||
@@ -583,3 +585,3 @@ } | ||
* @api public | ||
* @example {{#some [1, 'b', 3] isString}} string found {{else}} No string found {{/some}} -> string found | ||
* @example {{#some [1, "b", 3] isString}} string found {{else}} No string found {{/some}} -> ' string found ' | ||
*/ | ||
@@ -645,3 +647,3 @@ | ||
* @api public | ||
* @example {{ sortBy [{a: 'zzz'}, {a: 'aaa'}] 'a' }} -> [{'a':'aaa'}, {'a':'zzz'}] | ||
* @example {{ sortBy [{'a': 'zzz'}, {'a': 'aaa'}] 'a' }} -> [{'a':'aaa'},{'a':'zzz'}] | ||
*/ | ||
@@ -660,3 +662,3 @@ | ||
} | ||
if (typeof prop === 'function') { | ||
@@ -758,3 +760,3 @@ return array.sort(prop); | ||
* @api public | ||
* @example {{ withFirst [1, 2, 3] }} {{this}} {{/withFirst}} | ||
* @example {{#withFirst [1, 2, 3] }}{{this}}{{/withFirst}} -> 1 | ||
*/ | ||
@@ -793,3 +795,3 @@ | ||
* {{.}} | ||
* {{each}} | ||
* {{/each}} | ||
* <br> | ||
@@ -807,3 +809,3 @@ * {{/withGroup}} | ||
* @api public | ||
* @example {{#withGroup [1, 2, 3, 4] 2}} {{#each this}} {{.}} {{each}} <br> {{/withGroup}} -> 1,2<br> 3,4<br> | ||
* @example {{#withGroup [1, 2, 3, 4] 2}}{{#each this}}{{.}}{{/each}}<br>{{/withGroup}} -> 12<br>34<br> | ||
* */ | ||
@@ -818,3 +820,3 @@ | ||
for (var i = 0; i < array.length; i++) { | ||
if (i > 0 && (i % size) === 0) { | ||
if (i > 0 && i % size === 0) { | ||
result += options.fn(subcontext); | ||
@@ -846,3 +848,3 @@ subcontext = []; | ||
* @block | ||
* @example {{#withLast [1, 2, 3, 4]}} {{this}} {{/withLast}} -> 4 | ||
* @example {{#withLast [1, 2, 3, 4]}}{{this}}{{/withLast}} -> 4 | ||
*/ | ||
@@ -864,3 +866,4 @@ | ||
array = array.slice(-idx); | ||
var len = array.length, i = -1; | ||
var len = array.length, | ||
i = -1; | ||
var result = ''; | ||
@@ -890,3 +893,3 @@ while (++i < len) { | ||
* @api public | ||
* @example {{#withSort ['b', 'a', 'c']}} {{this}} {{/withSort}} -> abc | ||
* @example {{#withSort ['b', 'a', 'c']}}{{this}}{{/withSort}} -> abc | ||
*/ | ||
@@ -902,3 +905,3 @@ | ||
options = prop; | ||
array = array.sort(); | ||
@@ -918,3 +921,3 @@ if (getValue(options, 'hash.reverse')) { | ||
b = getValue(b, prop); | ||
return a > b ? 1 : (a < b ? -1 : 0); | ||
return a > b ? 1 : a < b ? -1 : 0; | ||
}); | ||
@@ -926,3 +929,4 @@ | ||
var alen = array.length, j = -1; | ||
var alen = array.length, | ||
j = -1; | ||
while (++j < alen) { | ||
@@ -940,7 +944,7 @@ result += options.fn(array[j]); | ||
* | ||
* ```handlebars | ||
* <!-- array: ['a', 'a', 'c', 'b', 'e', 'e'] --> | ||
* {{#each (unique array)}}{{.}}{{/each}} | ||
* <!-- results in: 'acbe' --> | ||
* ``` | ||
* ```handlebars | ||
* <!-- array: ['a', 'a', 'c', 'b', 'e', 'e'] --> | ||
* {{#each (unique array)}}{{.}}{{/each}} | ||
* <!-- results in: 'acbe' --> | ||
* ``` | ||
* @param {Array} `array` | ||
@@ -950,3 +954,3 @@ * @param {Object} `options` | ||
* @api public | ||
* @example {{#each (unique ['a', 'a', 'c', 'b', 'e', 'e']) }} {{.}} {{/each}} -> acbe | ||
* @example {{#each (unique ['a', 'a', 'c', 'b', 'e', 'e']) }}{{.}}{{/each}} -> acbe | ||
*/ | ||
@@ -953,0 +957,0 @@ |
@@ -58,3 +58,3 @@ 'use strict'; | ||
* @api public | ||
* @example {{compare 10 '<' 5 }} -> true | ||
* @example {{compare 10 '<' 5 }} -> false | ||
*/ | ||
@@ -99,3 +99,5 @@ | ||
default: { | ||
throw new Error('helper {{compare}}: invalid operator: `' + operator + '`'); | ||
throw new Error( | ||
'helper {{compare}}: invalid operator: `' + operator + '`' | ||
); | ||
} | ||
@@ -148,3 +150,3 @@ } | ||
* @api public | ||
* @example {{default null null 'default'}} -> default | ||
* @example {{default null null 'default'}} -> default | ||
*/ | ||
@@ -172,3 +174,3 @@ | ||
* @api public | ||
* @example {{#eq 3 3}} equal{{else}} not equal{{/eq}} -> equal | ||
* @example {{#eq 3 3}}equal{{else}}not equal{{/eq}} -> equal | ||
*/ | ||
@@ -197,3 +199,3 @@ | ||
* @api public | ||
* @example {{#gt 4 3}} greater than{{else}} not greater than{{/gt}} -> greater than | ||
* @example {{#gt 4 3}} greater than{{else}} not greater than{{/gt}} -> ' greater than' | ||
*/ | ||
@@ -223,3 +225,3 @@ | ||
* @api public | ||
* @example {{#gte 4 3}} greater than or equal{{else}} not greater than{{/gte}} -> greater than or equal | ||
* @example {{#gte 4 3}} greater than or equal{{else}} not greater than{{/gte}} -> ' greater than or equal' | ||
*/ | ||
@@ -245,3 +247,3 @@ | ||
* @api public | ||
* @example {{#has 'foobar' 'foo'}} has it{{else}} doesn't{{/has}} -> has it | ||
* @example {{#has 'foobar' 'foo'}}has it{{else}}doesn't{{/has}} -> has it | ||
*/ | ||
@@ -269,3 +271,6 @@ | ||
if ((Array.isArray(value) || util.isString(value)) && util.isString(pattern)) { | ||
if ( | ||
(Array.isArray(value) || util.isString(value)) && | ||
util.isString(pattern) | ||
) { | ||
if (value.indexOf(pattern) > -1) { | ||
@@ -328,3 +333,3 @@ return util.fn(true, this, options); | ||
* @api public | ||
* @example {{#ifEven 2}} even {{else}} odd {{/ifEven}} -> even | ||
* @example {{#ifEven 2}} even {{else}} odd {{/ifEven}} -> ' even ' | ||
*/ | ||
@@ -338,3 +343,3 @@ | ||
* Conditionally renders a block if the remainder is zero when | ||
* `a` operand is divided by `b`. If an inverse block is specified | ||
* `b` operand is divided by `a`. If an inverse block is specified | ||
* it will be rendered when the remainder is **not zero**. | ||
@@ -348,3 +353,3 @@ * | ||
* @api public | ||
* @example {{#ifNth 10 2}} remainder {{else}} no remainder {{/ifNth}} -> remainder | ||
* @example {{#ifNth 2 10}}remainder{{else}}no remainder{{/ifNth}} -> remainder | ||
*/ | ||
@@ -373,3 +378,3 @@ | ||
* @api public | ||
* @example {{#ifOdd 3}} odd {{else}} even {{/ifOdd}} -> odd | ||
* @example {{#ifOdd 3}}odd{{else}}even{{/ifOdd}} -> odd | ||
*/ | ||
@@ -392,3 +397,3 @@ | ||
* @api public | ||
* @example {{#is 3 3}} is {{else}} is not {{/is}} -> is | ||
* @example {{#is 3 3}} is {{else}} is not {{/is}} -> ' is ' | ||
*/ | ||
@@ -416,3 +421,3 @@ | ||
* @api public | ||
* @example {{#isnt 3 3}} isnt {{else}} is {{/isnt}} -> is | ||
* @example {{#isnt 3 3}} isnt {{else}} is {{/isnt}} -> ' is ' | ||
*/ | ||
@@ -440,3 +445,3 @@ | ||
* @api public | ||
* @example {{#lt 2 3}} less than {{else}} more than or equal {{/lt}} -> less than | ||
* @example {{#lt 2 3}} less than {{else}} more than or equal {{/lt}} -> ' less than ' | ||
*/ | ||
@@ -466,3 +471,3 @@ | ||
* @api public | ||
* @example {{#lte 2 3}} less than or equal {{else}} more than {{/lte}} -> less than or equal | ||
* @example {{#lte 2 3}} less than or equal {{else}} more than {{/lte}} -> ' less than or equal ' | ||
*/ | ||
@@ -489,3 +494,3 @@ | ||
* @api public | ||
* @example {{#neither null null}} both falsey {{else}} both not falsey {{/neither}} -> both falsey | ||
* @example {{#neither null null}}both falsey{{else}}both not falsey{{/neither}} -> both falsey | ||
*/ | ||
@@ -505,3 +510,3 @@ | ||
* @api public | ||
* @example {{#not undefined }} falsey {{else}} not falsey {{/not}} -> falsey | ||
* @example {{#not undefined }}falsey{{else}}not falsey{{/not}} -> falsey | ||
*/ | ||
@@ -529,3 +534,3 @@ | ||
* @api public | ||
* @example {{#or 1 2 undefined }} at least one truthy {{else}} all falsey {{/or}} -> at least one truthy | ||
* @example {{#or 1 2 undefined }} at least one truthy {{else}} all falsey {{/or}} -> ' at least one truthy ' | ||
*/ | ||
@@ -557,3 +562,3 @@ | ||
* @api public | ||
* @example {{#unlessEq 2 1 }} not equal {{else}} equal {{/unlessEq}} -> not equal | ||
* @example {{#unlessEq 2 1 }} not equal {{else}} equal {{/unlessEq}} -> ' not equal ' | ||
*/ | ||
@@ -579,3 +584,3 @@ | ||
* @api public | ||
* @example {{#unlessGt 20 1 }} not greater than {{else}} greater than {{/unlessGt}} -> greater than | ||
* @example {{#unlessGt 20 1 }} not greater than {{else}} greater than {{/unlessGt}} -> ' greater than ' | ||
*/ | ||
@@ -601,3 +606,3 @@ | ||
* @api public | ||
* @example {{#unlessLt 20 1 }} greater than or equal {{else}} less than {{/unlessLt}} -> greater than or equal | ||
* @example {{#unlessLt 20 1 }}greater than or equal{{else}}less than{{/unlessLt}} -> greater than or equal | ||
*/ | ||
@@ -623,3 +628,3 @@ | ||
* @api public | ||
* @example {{#unlessGteq 20 1 }} less than {{else}} greater than or equal to {{/unlessGteq}} -> greater than or equal to | ||
* @example {{#unlessGteq 20 1 }} less than {{else}}greater than or equal to{{/unlessGteq}} -> greater than or equal to | ||
*/ | ||
@@ -645,3 +650,3 @@ | ||
* @api public | ||
* @example {{#unlessLteq 20 1 }} greater than {{else}} less than or equal to {{/unlessLteq}} -> greater than | ||
* @example {{#unlessLteq 20 1 }} greater than {{else}} less than or equal to {{/unlessLteq}} -> ' greater than ' | ||
*/ | ||
@@ -648,0 +653,0 @@ |
@@ -20,3 +20,3 @@ 'use strict'; | ||
* @api public | ||
* @example {{ bytes 1386 }} -> 1.4Kb | ||
* @example {{ bytes 1386 1 }} -> 1.4 kB | ||
*/ | ||
@@ -131,3 +131,3 @@ | ||
* @api public | ||
* @example {{ toExponential 10123 2 }} -> 101e+4 | ||
* @example {{ toExponential 10123 2 }} -> 1.01e+4 | ||
*/ | ||
@@ -134,0 +134,0 @@ |
@@ -127,3 +127,3 @@ 'use strict'; | ||
* @api public | ||
* @example {{ chop ' ABC '}} -> 'ABC' | ||
* @example {{ chop ' ABC '}} -> ABC | ||
*/ | ||
@@ -210,3 +210,3 @@ | ||
* @api public | ||
* @example {{ellipsis 'foo bar baz', 7}} -> foo bar… | ||
* @example {{ellipsis 'foo bar baz' 7}} -> foo bar… | ||
*/ | ||
@@ -393,3 +393,3 @@ | ||
* ```handlebars | ||
* {{{{#raw}}}} | ||
* {{{{raw}}}} | ||
* {{foo}} | ||
@@ -404,3 +404,3 @@ * {{{{/raw}}}} | ||
* @api public | ||
* @example {{{{#raw}}}} {{foo}} {{{{/raw}}}} -> {{foo}} | ||
* @example {{{{raw}}}}{{foo}}{{{{/raw}}}} -> \{{foo}} | ||
*/ | ||
@@ -434,3 +434,3 @@ | ||
* @api public | ||
* @example {{remove 'a b a b a b' 'a '}} -> b b b | ||
* @example {{remove 'a b a b a b' 'a '}} -> b b b | ||
*/ | ||
@@ -455,3 +455,3 @@ | ||
* @api public | ||
* @example {{remove 'a b a b a b' 'a'}} -> b a b a b | ||
* @example {{removeFirst 'a b a b a b' 'a'}} -> ' b a b a b' | ||
*/ | ||
@@ -477,3 +477,3 @@ | ||
* @api public | ||
* @example {{replace 'a b a b a b' 'a' 'z'}} -> z b z b z b | ||
* @example {{replace 'a b a b a b' 'a' 'z'}} -> z b z b z b | ||
*/ | ||
@@ -500,3 +500,3 @@ | ||
* @api public | ||
* @example {{replace 'a b a b a b' 'a' 'z'}} -> z b a b a b | ||
* @example {{replaceFirst 'a b a b a b' 'a' 'z'}} -> z b a b a b | ||
*/ | ||
@@ -524,6 +524,3 @@ | ||
helpers.reverse = function(str) { | ||
if (typeof(str) !== 'string') return ''; | ||
return str.split('').reverse().join(''); | ||
}; | ||
helpers.reverse = require('./array').reverse; | ||
@@ -540,3 +537,3 @@ /** | ||
* @api public | ||
* @example {{sentence 'hello world. goodbye world.'}} -> Hello world. Goodbye world. | ||
* @example {{sentence 'hello world. goodbye world.'}} -> Hello world. Goodbye world. | ||
*/ | ||
@@ -581,3 +578,3 @@ | ||
* @api public | ||
* @example {{split 'a,b,c'}} -> ['a', 'b', 'c'] | ||
* @example {{split 'a,b,c'}} -> ['a', 'b', 'c'] | ||
*/ | ||
@@ -608,3 +605,3 @@ | ||
* @api public | ||
* @example {{#startsWith 'Goodbye' 'Hello, world!'}} Yep {{else}} Nope {{/startsWith}} -> Nope | ||
* @example {{#startsWith 'Goodbye' 'Hello, world!'}}Yep{{else}}Nope{{/startsWith}} -> Nope | ||
*/ | ||
@@ -634,3 +631,3 @@ | ||
* @api public | ||
* @example {{#titleize 'this is title case' }} -> This Is Title Case | ||
* @example {{titleize 'this is title case' }} -> This Is Title Case | ||
*/ | ||
@@ -699,3 +696,3 @@ | ||
* @api public | ||
* @example {{trimRight ' ABC ' }} -> ' ABC ' | ||
* @example {{trimRight ' ABC ' }} -> ' ABC' | ||
*/ | ||
@@ -724,3 +721,3 @@ | ||
* @api public | ||
* @example {{truncate 'foo bar baz' 7 }} -> foo bar | ||
* @example {{truncate 'foo bar baz' 7 }} -> foo bar | ||
*/ | ||
@@ -758,3 +755,3 @@ | ||
* @api public | ||
* @example {{truncateWords 'foo bar baz' 1 }} -> foo | ||
* @example {{truncateWords 'foo bar baz' 1 }} -> foo… | ||
*/ | ||
@@ -770,6 +767,7 @@ | ||
var arr = str.split(/[ \t]/); | ||
if (num > arr.length) { | ||
arr = arr.slice(0, num); | ||
if (num >= arr.length) { | ||
return str; | ||
} | ||
arr = arr.slice(0, num); | ||
var val = arr.join(' ').trim(); | ||
@@ -776,0 +774,0 @@ return val + suffix; |
@@ -17,3 +17,3 @@ 'use strict'; | ||
* @api public | ||
* @example {{ encodeURI 'https://myurl?Hello There' }} -> https://myurl?Hello%20There | ||
* @example {{ encodeURI 'https://myurl?Hello There' }} -> https%3A%2F%2Fmyurl%3FHello%20There | ||
*/ | ||
@@ -34,3 +34,3 @@ | ||
* @api public | ||
* @example {{ escape 'https://myurl?Hello+There' }} -> https://myurl?Hello%20There | ||
* @example {{ escape 'https://myurl?Hello+There' }} -> https%3A%2F%2Fmyurl%3FHello%2BThere | ||
*/ | ||
@@ -50,3 +50,3 @@ | ||
* @api public | ||
* @example {{ decodeURI 'https://myurl?Hello%20There' }} -> https://myurl?=Hello There | ||
* @example {{ decodeURI 'https://myurl?Hello%20There' }} -> https://myurl?Hello There | ||
*/ | ||
@@ -94,3 +94,3 @@ | ||
* @api public | ||
* @example {{ stripQueryString 'https://myurl/api/test?foo=bar' }} -> 'https://myurl/api/test' | ||
* @example {{ stripQuerystring 'https://myurl/api/test?foo=bar' }} -> 'https://myurl/api/test' | ||
*/ | ||
@@ -116,3 +116,3 @@ | ||
* @api public | ||
* @example {{ stripProtocol 'https://myurl/api/test' }} -> 'myurl/api/test' | ||
* @example {{ stripProtocol 'https://myurl/api/test' }} -> '//myurl/api/test' | ||
*/ | ||
@@ -119,0 +119,0 @@ |
{ | ||
"name": "@budibase/handlebars-helpers", | ||
"description": "More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.", | ||
"version": "0.12.2", | ||
"version": "0.13.0", | ||
"homepage": "https://github.com/Budibase/handlebars-helpers", | ||
@@ -72,6 +72,5 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"scripts": { | ||
"lint": "./node_modules/.bin/eslint *.js lib/**/*.js test/**/*.js", | ||
"test": "./node_modules/.bin/rimraf .nyc_output && ./node_modules/.bin/nyc ./node_modules/.bin/mocha", | ||
"update:readmemd": "verb", | ||
"clean": "./node_modules/.bin/rimraf .nyc_output" | ||
"lint": "eslint *.js lib/**/*.js test/**/*.js", | ||
"test": "mocha", | ||
"update:readmemd": "verb" | ||
}, | ||
@@ -104,4 +103,4 @@ "dependencies": { | ||
"mocha": "^8.4.0", | ||
"nyc": "^15.1.0", | ||
"rimraf": "^3.0.2", | ||
"sinon": "^17.0.1", | ||
"template-helpers": "^1.0.1", | ||
@@ -108,0 +107,0 @@ "templates": "^1.2.9", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4076
190758