Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const math = helpers.math({
* **[array](#array)** ([code](lib/array.js) | [unit tests](test/array.js))
* **[collection](#collection)** ([code](lib/collection.js) | [unit tests](test/collection.js))
* **[comparison](#comparison)** ([code](lib/comparison.js) | [unit tests](test/comparison.js))
* **[date](#date)** ([code](lib/date.js) | [unit tests](test/date.js))
* **[html](#html)** ([code](lib/html.js) | [unit tests](test/html.js))
* **[i18n](#i18n)** ([code](lib/i18n.js) | [unit tests](test/i18n.js))
* **[inflection](#inflection)** ([code](lib/inflection.js) | [unit tests](test/inflection.js))
Expand Down Expand Up @@ -171,19 +170,6 @@ Visit the: [code](lib/comparison.js) | [unit tests](test/comparison.js)
* **[unlessGteq](#unlessGteq)** ([code](lib/comparison.js#L575) | [tests](test/comparison.js#L586))
* **[unlessLteq](#unlessLteq)** ([code](lib/comparison.js#L595) | [tests](test/comparison.js#L601))

### [date helpers](#date)

Visit the: [code](lib/date.js) | [unit tests](test/date.js)

* **[year](#year)** ([code](lib/date.js#L24) | [tests](test/date.js#L11))
* **[date](#date)** ([code](lib/date.js#L88) | [tests](test/date.js#L33))
* **[moment](#moment)** ([code](lib/date.js#L55) | [no tests])
* **[formatDate](#formatDate)** ([code](lib/date.js#L103) | [tests](test/date.js#L65))
* **[niceDate](#niceDate)** ([code](lib/date.js#L119) | [tests](test/date.js#L80))
* **[getTime](#getTime)** ([code](lib/date.js#L133) | [tests](test/date.js#L91))



### [html helpers](#html)

Visit the: [code](lib/html.js) | [unit tests](test/html.js)
Expand Down Expand Up @@ -1322,23 +1308,6 @@ is less than or equal to `b`**.
* `options` **{Object}**: Handlebars provided options object
* `returns` **{String}**: Block, or inverse block if specified and falsey.

## date

### [{{year}}](lib/date.js#L15)

Get the current year.

**Example**

```handlebars
{{year}}
<!-- 2017 -->
```

### [{{moment}}](lib/date.js#L24)

Use [moment](http://momentjs.com) as a helper. See [helper-date](https://github.com/helpers/helper-date) for more details.

## html

### [{{attr}}](lib/html.js#L23)
Expand Down
13 changes: 7 additions & 6 deletions lib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ helpers.forEach = function(array, options) {
helpers.eachIndex = function(array, options) {
let result = '';
for (let i = 0; i < array.length; i++) {
result += options.fn({item: array[i], index: i});
result += options.fn({ item: array[i], index: i });
}
return result;
};
Expand All @@ -163,17 +163,20 @@ helpers.filter = function(array, value, options) {
let content = '';
let results = [];

value = utils.sanitizeValue(value);

// filter on a specific property
const prop = options.hash && (options.hash.property || options.hash.prop);
if (prop) {
results = array.filter(function(val) {
return value === utils.get(val, prop);
let sanitizedValue = utils.sanitizeValue(val);
return value === utils.get(sanitizedValue, prop);
});
} else {

// filter on a string value
results = array.filter(function(v) {
return value === v;
let sanitizedValue = utils.sanitizeValue(v);
return value === sanitizedValue;
});
}

Expand Down Expand Up @@ -760,7 +763,6 @@ helpers.withLast = function(array, idx, options) {
* @block
* @api public
*/

helpers.withSort = function(array, prop, options) {
if (utils.isUndefined(array)) return '';
let result = '';
Expand Down Expand Up @@ -810,7 +812,6 @@ helpers.withSort = function(array, prop, options) {
* @return {Array}
* @api public
*/

helpers.unique = function(array, options) {
if (utils.isUndefined(array)) return '';

Expand Down
30 changes: 29 additions & 1 deletion lib/comparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@ helpers.and = function() {
* @block
* @api public
*/

helpers.compare = function(a, operator, b, options) {
/*eslint eqeqeq: 0*/

if (arguments.length < 4) {
throw new Error('handlebars Helper {{compare}} expects 4 arguments');
}

if (operator !== 'typeof') {
a = utils.sanitizeValue(a);
b = utils.sanitizeValue(b);
}

let result;
switch (operator) {
case '==':
Expand Down Expand Up @@ -125,6 +129,9 @@ helpers.contains = function(collection, value, startIndex, options) {
options = startIndex;
startIndex = undefined;
}

collection = Array.isArray(collection) ? collection.map(value => utils.sanitizeValue(value)) : collection;

const val = utils.includes(collection, value, startIndex);
return utils.value(val, this, options);
};
Expand Down Expand Up @@ -166,6 +173,10 @@ helpers.eq = function(a, b, options) {
options = b;
b = options.hash.compare;
}

a = utils.sanitizeValue(a);
b = utils.sanitizeValue(b);

return utils.value(a === b, this, options);
};

Expand Down Expand Up @@ -249,6 +260,8 @@ helpers.has = function(value, pattern, options) {
}

if ((Array.isArray(value) || utils.isString(value)) && utils.isString(pattern)) {
value = Array.isArray(value) ? utils.sanitizeValue(value) : value;

if (value.indexOf(pattern) > -1) {
return utils.fn(true, this, options);
}
Expand Down Expand Up @@ -366,6 +379,10 @@ helpers.is = function(a, b, options) {
options = b;
b = options.hash.compare;
}

a = utils.sanitizeValue(a);
b = utils.sanitizeValue(b);

return utils.value(a == b, this, options);
};

Expand All @@ -388,6 +405,10 @@ helpers.isnt = function(a, b, options) {
options = b;
b = options.hash.compare;
}

a = utils.sanitizeValue(a);
b = utils.sanitizeValue(b);

return utils.value(a != b, this, options);
};

Expand Down Expand Up @@ -451,6 +472,9 @@ helpers.lte = function(a, b, options) {
*/

helpers.neither = function(a, b, options) {
a = utils.sanitizeValue(a);
b = utils.sanitizeValue(b);

return utils.value(!a && !b, this, options);
};

Expand Down Expand Up @@ -517,6 +541,10 @@ helpers.unlessEq = function(a, b, options) {
options = b;
b = options.hash.compare;
}

a = utils.sanitizeValue(a);
b = utils.sanitizeValue(b);

return utils.value(a !== b, this, options);
};

Expand Down
136 changes: 0 additions & 136 deletions lib/date.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module.exports = {
array: require('./array'),
collection: require('./collection'),
comparison: require('./comparison'),
date: require('./date'),
html: require('./html'),
i18n: require('./i18n'),
inflection: require('./inflection'),
Expand Down
Loading