Skip to content

Commit 7fc89dc

Browse files
authored
Indian separators (#291)
* update demo for new option * indian separators option * update packages * add test, update tests * add new option to README
1 parent 086d3a1 commit 7fc89dc

12 files changed

+99
-55
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ interface CountUpOptions {
5050
decimalPlaces?: number; // number of decimal places (0)
5151
duration?: number; // animation duration in seconds (2)
5252
useGrouping?: boolean; // example: 1,000 vs 1000 (true)
53+
useIndianSeparators?: boolean; // example: 1,00,000 vs 100,000 (false)
5354
useEasing?: boolean; // ease animation (true)
5455
smartEasingThreshold?: number; // smooth easing for large numbers above this if useEasing (999)
5556
smartEasingAmount?: number; // amount to be eased for numbers above threshold (333)

demo/demo-nomodule.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ window.onload = function () {
9797
}
9898
}
9999
var stringifyArray = function (arr) { return '[\'' + arr.join('\', \'') + '\']'; };
100+
100101
// COUNTUP AND CODE VISUALIZER
102+
101103
function createCountUp() {
102104
establishOptionsFromInputs();
103105
demo = new countUp.CountUp('myTargetElement', endVal, options);
@@ -129,6 +131,7 @@ window.onload = function () {
129131
duration: Number(el('duration').value),
130132
useEasing: el('useEasing').checked,
131133
useGrouping: el('useGrouping').checked,
134+
useIndianSeparators: el('useIndianSeparators').checked,
132135
easingFn: typeof getEasingFn() === 'undefined' ? null : getEasingFn(),
133136
separator: el('separator').value,
134137
decimal: el('decimal').value,
@@ -169,6 +172,7 @@ window.onload = function () {
169172
opts += (options.useEasing) ? '' : indentedLine("useEasing: " + options.useEasing);
170173
opts += (options.useEasing && options.easingFn) ? indentedLine("easingFn") : '';
171174
opts += (options.useGrouping) ? '' : indentedLine("useGrouping: " + options.useGrouping);
175+
opts += (options.useIndianSeparators) ? indentedLine("useIndianSeparators: " + options.useIndianSeparators) : '';
172176
opts += (options.separator !== ',') ? indentedLine("separator: '" + options.separator + "'") : '';
173177
opts += (options.decimal !== '.') ? indentedLine("decimal: '" + options.decimal + "'") : '';
174178
opts += (options.prefix.length) ? indentedLine("prefix: '" + options.prefix + "'") : '';

demo/demo.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ window.onload = function () {
9494
}
9595
}
9696
var stringifyArray = function (arr) { return '[\'' + arr.join('\', \'') + '\']'; };
97+
9798
// COUNTUP AND CODE VISUALIZER
99+
98100
function createCountUp() {
99101
establishOptionsFromInputs();
100102
demo = new CountUp('myTargetElement', endVal, options);
@@ -132,6 +134,7 @@ window.onload = function () {
132134
duration: Number(el('duration').value),
133135
useEasing: el('useEasing').checked,
134136
useGrouping: el('useGrouping').checked,
137+
useIndianSeparators: el('useIndianSeparators').checked,
135138
easingFn: typeof getEasingFn() === 'undefined' ? null : getEasingFn(),
136139
separator: el('separator').value,
137140
decimal: el('decimal').value,
@@ -172,6 +175,7 @@ window.onload = function () {
172175
opts += (options.useEasing) ? '' : indentedLine("useEasing: " + options.useEasing);
173176
opts += (options.useEasing && options.easingFn) ? indentedLine("easingFn") : '';
174177
opts += (options.useGrouping) ? '' : indentedLine("useGrouping: " + options.useGrouping);
178+
opts += (options.useIndianSeparators) ? indentedLine("useIndianSeparators: " + options.useIndianSeparators) : '';
175179
opts += (options.separator !== ',') ? indentedLine("separator: '" + options.separator + "'") : '';
176180
opts += (options.decimal !== '.') ? indentedLine("decimal: '" + options.decimal + "'") : '';
177181
opts += (options.prefix.length) ? indentedLine("prefix: '" + options.prefix + "'") : '';

dist/countUp.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface CountUpOptions {
33
decimalPlaces?: number;
44
duration?: number;
55
useGrouping?: boolean;
6+
useIndianSeparators?: boolean;
67
useEasing?: boolean;
78
smartEasingThreshold?: number;
89
smartEasingAmount?: number;

dist/countUp.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ var CountUp = /** @class */ (function () {
1515
var _this = this;
1616
this.endVal = endVal;
1717
this.options = options;
18-
this.version = '2.3.2';
18+
this.version = '2.4.0';
1919
this.defaults = {
2020
startVal: 0,
2121
decimalPlaces: 0,
2222
duration: 2,
2323
useEasing: true,
2424
useGrouping: true,
25+
useIndianSeparators: false,
2526
smartEasingThreshold: 999,
2627
smartEasingAmount: 333,
2728
separator: ',',
@@ -89,10 +90,16 @@ var CountUp = /** @class */ (function () {
8990
x2 = x.length > 1 ? _this.options.decimal + x[1] : '';
9091
if (_this.options.useGrouping) {
9192
x3 = '';
93+
var factor = 3, j = 0;
9294
for (var i = 0, len = x1.length; i < len; ++i) {
93-
if (i !== 0 && (i % 3) === 0) {
95+
if (_this.options.useIndianSeparators && i === 4) {
96+
factor = 2;
97+
j = 1;
98+
}
99+
if (i !== 0 && (j % factor) === 0) {
94100
x3 = _this.options.separator + x3;
95101
}
102+
j++;
96103
x3 = x1[len - i - 1] + x3;
97104
}
98105
x1 = x3;

dist/countUp.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/countUp.umd.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
var _this = this;
2222
this.endVal = endVal;
2323
this.options = options;
24-
this.version = '2.3.2';
24+
this.version = '2.4.0';
2525
this.defaults = {
2626
startVal: 0,
2727
decimalPlaces: 0,
2828
duration: 2,
2929
useEasing: true,
3030
useGrouping: true,
31+
useIndianSeparators: false,
3132
smartEasingThreshold: 999,
3233
smartEasingAmount: 333,
3334
separator: ',',
@@ -95,10 +96,16 @@
9596
x2 = x.length > 1 ? _this.options.decimal + x[1] : '';
9697
if (_this.options.useGrouping) {
9798
x3 = '';
99+
var factor = 3, j = 0;
98100
for (var i = 0, len = x1.length; i < len; ++i) {
99-
if (i !== 0 && (i % 3) === 0) {
101+
if (_this.options.useIndianSeparators && i === 4) {
102+
factor = 2;
103+
j = 1;
104+
}
105+
if (i !== 0 && (j % factor) === 0) {
100106
x3 = _this.options.separator + x3;
101107
}
108+
j++;
102109
x3 = x1[len - i - 1] + x3;
103110
}
104111
x1 = x3;

0 commit comments

Comments
 (0)