|
6 | 6 | * http://adamwdraper.github.com/Numeral-js/
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -(function () { |
| 9 | +var numeral = function () { |
10 | 10 |
|
11 | 11 | /************************************
|
12 | 12 | Constants
|
|
20 | 20 | zeroFormat = null,
|
21 | 21 | defaultFormat = '0,0';
|
22 | 22 |
|
| 23 | + var NUMBER_GROUP_LENGTH = 3, |
| 24 | + NUMBER_GROUP_SEPARATOR = ",", |
| 25 | + DECIMAL_SEPARATOR = ".", |
| 26 | + NUM_REGEX = new RegExp("(\\d)(?=(\\d{" + NUMBER_GROUP_LENGTH + "})+(?!\\d))", "g"); |
23 | 27 |
|
24 | 28 | /************************************
|
25 | 29 | Constructors
|
|
356 | 360 | w = d.split('.')[0];
|
357 | 361 |
|
358 | 362 | if (d.split('.')[1].length) {
|
359 |
| - d = languages[currentLanguage].delimiters.decimal + d.split('.')[1]; |
| 363 | + d = (DECIMAL_SEPARATOR || languages[currentLanguage].delimiters.decimal) + d.split('.')[1]; |
360 | 364 | } else {
|
361 | 365 | d = '';
|
362 | 366 | }
|
|
375 | 379 | }
|
376 | 380 |
|
377 | 381 | if (thousands > -1) {
|
378 |
| - w = w.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + languages[currentLanguage].delimiters.thousands); |
| 382 | + w = w.toString().replace(NUM_REGEX, '$1' |
| 383 | + + (NUMBER_GROUP_SEPARATOR || languages[currentLanguage].delimiters.thousands)); |
379 | 384 | }
|
380 | 385 |
|
381 | 386 | if (format.indexOf('.') === 0) {
|
|
574 | 579 | Numeral Prototype
|
575 | 580 | ************************************/
|
576 | 581 |
|
| 582 | + numeral.setup = function (decimalSeparator, numberGroupSeparator, numberGroupLength) { |
| 583 | + if (decimalSeparator !== DECIMAL_SEPARATOR) DECIMAL_SEPARATOR = decimalSeparator; |
| 584 | + if (numberGroupSeparator !== NUMBER_GROUP_SEPARATOR) |
| 585 | + NUMBER_GROUP_SEPARATOR = numberGroupSeparator; |
| 586 | + if (numberGroupLength !== NUMBER_GROUP_LENGTH) { |
| 587 | + NUMBER_GROUP_LENGTH = numberGroupLength; |
| 588 | + NUM_REGEX = new RegExp("(\\d)(?=(\\d{" + NUMBER_GROUP_LENGTH + "})+(?!\\d))", "g"); |
| 589 | + } |
| 590 | + }; |
577 | 591 |
|
578 | 592 | numeral.fn = Numeral.prototype = {
|
579 | 593 |
|
|
653 | 667 |
|
654 | 668 | this.numeral = numeral;
|
655 | 669 |
|
656 |
| -}).call(this); |
| 670 | +}; |
0 commit comments