From fc2f188d4d8f06aab31979b293d95580e19cbdf1 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Wed, 7 Sep 2011 09:19:53 +0200 Subject: style(filter): Couple of missing spaces, semi-colons, add empty lines --- src/filters.js | 18 +++++++++--------- test/FiltersSpec.js | 3 +++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/filters.js b/src/filters.js index 0437f0e0..c39e02f9 100644 --- a/src/filters.js +++ b/src/filters.js @@ -71,8 +71,8 @@ angularFilter.currency = function(amount, currencySymbol){ var formats = this.$service('$locale').NUMBER_FORMATS; this.$element.toggleClass('ng-format-negative', amount < 0); if (isUndefined(currencySymbol)) currencySymbol = formats.CURRENCY_SYM; - return formatNumber(amount, formats.PATTERNS[1], formats.GROUP_SEP, formats.DECIMAL_SEP, 2) - .replace(/\u00A4/g, currencySymbol); + return formatNumber(amount, formats.PATTERNS[1], formats.GROUP_SEP, formats.DECIMAL_SEP, 2). + replace(/\u00A4/g, currencySymbol); }; /** @@ -121,14 +121,14 @@ angularFilter.number = function(number, fractionSize) { var formats = this.$service('$locale').NUMBER_FORMATS; return formatNumber(number, formats.PATTERNS[0], formats.GROUP_SEP, formats.DECIMAL_SEP, fractionSize); -} +}; function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) { if (isNaN(number) || !isFinite(number)) return ''; var isNegative = number < 0; number = Math.abs(number); - var numStr = number + '', + var numStr = number + '', formatedText = '', parts = []; @@ -137,7 +137,7 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) { } else { var fractionLen = (numStr.split(DECIMAL_SEP)[1] || '').length; - //determine fractionSize if it is not specified + // determine fractionSize if it is not specified if (isUndefined(fractionSize)) { fractionSize = Math.min(Math.max(pattern.minFrac, fractionLen), pattern.maxFrac); } @@ -249,10 +249,10 @@ var DATE_FORMATS = { Z: timeZoneGetter }; -var GET_TIME_ZONE = /[A-Z]{3}(?![+\-])/; -var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/ -var OPERA_TOSTRING_PATTERN = /^[\d].*Z$/; -var NUMBER_STRING = /^\d+$/; +var GET_TIME_ZONE = /[A-Z]{3}(?![+\-])/, + DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/, + OPERA_TOSTRING_PATTERN = /^[\d].*Z$/, + NUMBER_STRING = /^\d+$/; /** diff --git a/test/FiltersSpec.js b/test/FiltersSpec.js index 83d8aac0..672540c5 100644 --- a/test/FiltersSpec.js +++ b/test/FiltersSpec.js @@ -96,6 +96,7 @@ describe('filter', function() { dealoc(context); }); + it('should do basic currency filtering', function() { expect(currency(0)).toEqual('$0.00'); expect(html.hasClass('ng-format-negative')).toBeFalsy(); @@ -105,6 +106,7 @@ describe('filter', function() { expect(html.hasClass('ng-format-negative')).toBeFalsy(); }); + it('should return empty string for non-numbers', function() { expect(currency()).toBe(''); expect(html.hasClass('ng-format-negative')).toBeFalsy(); @@ -113,6 +115,7 @@ describe('filter', function() { }); }); + describe('number', function() { var context, number; -- cgit v1.2.3