1 | export default function(grouping, thousands) {
|
2 | return function(value, width) {
|
3 | var i = value.length,
|
4 | t = [],
|
5 | j = 0,
|
6 | g = grouping[0],
|
7 | length = 0;
|
8 |
|
9 | while (i > 0 && g > 0) {
|
10 | if (length + g + 1 > width) g = Math.max(1, width - length);
|
11 | t.push(value.substring(i -= g, i + g));
|
12 | if ((length += g + 1) > width) break;
|
13 | g = grouping[j = (j + 1) % grouping.length];
|
14 | }
|
15 |
|
16 | return t.reverse().join(thousands);
|
17 | };
|
18 | };
|