From 4719544d49c55cf46097c324de6d6f3788c7dd1c Mon Sep 17 00:00:00 2001 From: harttle Date: Thu, 15 Dec 2016 22:38:48 +0800 Subject: [PATCH] fix: number convertion for plus filter, closes #18 --- filters.js | 2 +- test/filters.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/filters.js b/filters.js index 3ea8e75b8..4054fb28c 100644 --- a/filters.js +++ b/filters.js @@ -40,7 +40,7 @@ var filters = { 'minus': bindFixed((v, arg) => v - arg), 'modulo': bindFixed((v, arg) => v % arg), 'newline_to_br': v => v.replace(/\n/g, '
'), - 'plus': bindFixed((v, arg) => v + arg), + 'plus': bindFixed((v, arg) => Number(v) + Number(arg)), 'prepend': (v, arg) => arg + v, 'remove': (v, arg) => v.split(arg).join(''), 'remove_first': (v, l) => v.replace(l, ''), diff --git a/test/filters.js b/test/filters.js index 0aef8554b..80adf457e 100644 --- a/test/filters.js +++ b/test/filters.js @@ -133,6 +133,7 @@ describe('filters', function() { it('should return "12" for 16,4', () => test('{{ 16 | minus: 4 }}', '12')); it('should return "171.357" for 183.357,12', () => test('{{ 183.357 | minus: 12 }}', '171.357')); + it('should convert string to number', () => test('{{ "4" | minus: 1 }}', '3')); }); describe('modulo', function() { @@ -159,6 +160,7 @@ describe('filters', function() { it('should return "20" for 16,4', () => test('{{ 16 | plus: 4 }}', '20')); it('should return "195.357" for 183.357,12', () => test('{{ 183.357 | plus: 12 }}', '195.357')); + it('should convert string to number', () => test('{{ "4" | plus: 2 }}', '6')); }); it('should support prepend', function() {