From 0ee8ebdf1599cd4e94e72b64338ac62f8806d91b Mon Sep 17 00:00:00 2001 From: Jacob Kjeldahl Date: Mon, 25 Feb 2019 11:24:44 +0100 Subject: [PATCH] Adds check for empty thousandsseperator A check is added for empty thousands seperator so it is possible to render numbers without a thoudsands seperator --- src/pivot.coffee | 2 +- tests/pivot_spec.coffee | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pivot.coffee b/src/pivot.coffee index 45c28261..9c2fbb74 100644 --- a/src/pivot.coffee +++ b/src/pivot.coffee @@ -19,7 +19,7 @@ callWithJQuery ($) -> x1 = x[0] x2 = if x.length > 1 then decimalSep + x[1] else '' rgx = /(\d+)(\d{3})/ - x1 = x1.replace(rgx, '$1' + thousandsSep + '$2') while rgx.test(x1) + x1 = x1.replace(rgx, '$1' + thousandsSep + '$2') while rgx.test(x1) if thousandsSep return x1 + x2 numberFormat = (opts) -> diff --git a/tests/pivot_spec.coffee b/tests/pivot_spec.coffee index 3028f86c..08adfd45 100644 --- a/tests/pivot_spec.coffee +++ b/tests/pivot_spec.coffee @@ -532,6 +532,11 @@ describe "$.pivotUtilities", -> expect nf 1234567.89123456 .toEqual "1a234a567b89" + it "adds blank thousands separator", -> + nf = numberFormat(thousandsSep: "", decimalSep: "b") + expect nf 1234567.89123456 + .toEqual "1234567b89" + it "adds prefixes and suffixes", -> nf = numberFormat(prefix: "a", suffix: "b") expect nf 1234567.89123456