vendor: 33,602 bytes, lines 1-1013
1/*! @preserve 2 * numeral.js 3 * version : 2.0.6 4 * author : Adam Draper 5 * license : MIT 6 * http://adamwdraper.github.com/Numeral-js/ 7 */ 8 9(function (global, factory) { 10 if (typeof define === 'function' && define.amd) { 11 define(factory); 12 } else if (typeof module === 'object' && module.exports) { 13 module.exports = factory(); 14 } else { 15 global.numeral = factory(); 16 } 17}(this, function () { 18 /************************************ 19 Variables 20 ************************************/ 21 22 var numeral, 23 _, 24 VERSION = '2.0.6', 25 formats = {}, 26 locales = {}, 27 defaults = { 28 currentLocale: 'en', 29 zeroFormat: null, 30 nullFormat: null, 31 defaultFormat: '0,0', 32 scalePercentBy100: true 33 }, 34 options = { 35 currentLocale: defaults.currentLocale, 36 zeroFormat: defaults.zeroFormat, 37 nullFormat: defaults.nullFormat, 38 defaultFormat: defaults.defaultFormat, 39 scalePercentBy100: defaults.scalePercentBy100 40 }; 41 42 43 /************************************ 44 Constructors 45 ************************************/ 46 47 // Numeral prototype object 48 function Numeral(input, number) { 49 this._input = input; 50 51 this._value = number; 52 } 53 54 numeral = function(input) { 55 var value, 56 kind, 57 unformatFunction, 58 regexp; 59 60 if (numeral.isNumeral(input)) { 61 value = input.value(); 62 } else if (input === 0 || typeof input === 'undefined') { 63 value = 0; 64 } else if (input === null || _.isNaN(input)) { 65 value = null; 66 } else if (typeof input === 'string') { 67 if (options.zeroFormat && input === options.zeroFormat) { 68 value = 0; 69 } else if (options.nullFormat && input === options.nullFormat || !input.replace(/[^0-9]+/g, '').length) { 70 value = null; 71 } else { 72 for (kind in formats) { 73 regexp = typeof formats[kind].regexps.unformat === 'function' ? formats[kind].regexps.unformat() : formats[kind].regexps.unformat; 74 75 if (regexp && input.match(regexp)) { 76 unformatFunction = formats[kind].unformat; 77 78 break; 79 } 80 } 81 82 unformatFunction = unformatFunction || numeral._.stringToNumber; 83 84 value = unformatFunction(input); 85 } 86 } else { 87 value = Number(input)|| null; 88 } 89 90 return new Numeral(input, value); 91 }; 92 93 // version number 94 numeral.version = VERSION; 95 96 // compare numeral object 97 numeral.isNumeral = function(obj) { 98 return obj instanceof Numeral; 99 }; 100 101 // helper functions 102 numeral._ = _ = { 103 // formats numbers separators, decimals places, signs, abbreviations 104 numberToFormat: function(value, format, roundingFunction) { 105 var locale = locales[numeral.options.currentLocale], 106 negP = false, 107 optDec = false, 108 leadingCount = 0, 109 abbr = '', 110 trillion = 1000000000000, 111 billion = 1000000000, 112 million = 1000000, 113 thousand = 1000, 114 decimal = '', 115 neg = false, 116 abbrForce, // force abbreviation 117 abs, 118 min, 119 max, 120 power, 121 int, 122 precision, 123 signed, 124 thousands, 125 output; 126 127 // make sure we never format a null value 128 value = value || 0; 129 130 abs = Math.abs(value); 131 132 // see if we should use parentheses for negative number or if we should prefix with a sign 133 // if both are present we default to parentheses 134 if (numeral._.includes(format, '(')) { 135 negP = true; 136 format = format.replace(/[\(|\)]/g, ''); 137 } else if (numeral._.includes(format, '+') || numeral._.includes(format, '-')) { 138 signed = numeral._.includes(format, '+') ? format.indexOf('+') : value < 0 ? format.indexOf('-') : -1; 139 format = format.replace(/[\+|\-]/g, ''); 140 } 141 142 // see if abbreviation is wanted 143 if (numeral._.includes(format, 'a')) { 144 abbrForce = format.match(/a(k|m|b|t)?/); 145 146 abbrForce = abbrForce ? abbrForce[1] : false; 147 148 // check for space before abbreviation 149 if (numeral._.includes(format, ' a')) { 150 abbr = ' '; 151 } 152 153 format = format.replace(new RegExp(abbr + 'a[kmbt]?'), ''); 154 155 if (abs >= trillion && !abbrForce || abbrForce === 't') { 156 // trillion 157 abbr += locale.abbreviations.trillion; 158 value = value / trillion; 159 } else if (abs < trillion && abs >= billion && !abbrForce || abbrForce === 'b') { 160 // billion 161 abbr += locale.abbreviations.billion; 162 value = value / billion; 163 } else if (abs < billion && abs >= million && !abbrForce || abbrForce === 'm') { 164 // million 165 abbr += locale.abbreviations.million; 166 value = value / million; 167 } else if (abs < million && abs >= thousand && !abbrForce || abbrForce === 'k') { 168 // thousand 169 abbr += locale.abbreviations.thousand; 170 value = value / thousand; 171 } 172 } 173 174 // check for optional decimals 175 if (numeral._.includes(format, '[.]')) { 176 optDec = true; 177 format = format.replace('[.]', '.'); 178 } 179 180 // break number and format 181 int = value.toString().split('.')[0]; 182 precision = format.split('.')[1]; 183 thousands = format.indexOf(','); 184 leadingCount = (format.split('.')[0].split(',')[0].match(/0/g) || []).length; 185 186 if (precision) { 187 if (numeral._.includes(precision, '[')) { 188 precision = precision.replace(']', ''); 189 precision = precision.split('['); 190 decimal = numeral._.toFixed(value, (precision[0].length + precision[1].length), roundingFunction, precision[1].length); 191 } else { 192 decimal = numeral._.toFixed(value, precision.length, roundingFunction); 193 } 194 195 int = decimal.split('.')[0]; 196 197 if (numeral._.includes(decimal, '.')) { 198 decimal = locale.delimiters.decimal + decimal.split('.')[1]; 199 } else { 200 decimal = ''; 201 } 202 203 if (optDec && Number(decimal.slice(1)) === 0) { 204 decimal = ''; 205 } 206 } else { 207 int = numeral._.toFixed(value, 0, roundingFunction); 208 } 209 210 // check abbreviation again after rounding 211 if (abbr && !abbrForce && Number(int) >= 1000 && abbr !== locale.abbreviations.trillion) { 212 int = String(Number(int) / 1000); 213 214 switch (abbr) { 215 case locale.abbreviations.thousand: 216 abbr = locale.abbreviations.million; 217 break; 218 case locale.abbreviations.million: 219 abbr = locale.abbreviations.billion; 220 break; 221 case locale.abbreviations.billion: 222 abbr = locale.abbreviations.trillion; 223 break; 224 } 225 } 226 227 228 // format number 229 if (numeral._.includes(int, '-')) { 230 int = int.slice(1); 231 neg = true; 232 } 233 234 if (int.length < leadingCount) { 235 for (var i = leadingCount - int.length; i > 0; i--) { 236 int = '0' + int; 237 } 238 } 239 240 if (thousands > -1) { 241 int = int.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + locale.delimiters.thousands); 242 } 243 244 if (format.indexOf('.') === 0) { 245 int = ''; 246 } 247 248 output = int + decimal + (abbr ? abbr : ''); 249 250 if (negP) { 251 output = (negP && neg ? '(' : '') + output + (negP && neg ? ')' : ''); 252 } else { 253 if (signed >= 0) { 254 output = signed === 0 ? (neg ? '-' : '+') + output : output + (neg ? '-' : '+'); 255 } else if (neg) { 256 output = '-' + output; 257 } 258 } 259 260 return output; 261 }, 262 // unformats numbers separators, decimals places, signs, abbreviations 263 stringToNumber: function(string) { 264 var locale = locales[options.currentLocale], 265 stringOriginal = string, 266 abbreviations = { 267 thousand: 3, 268 million: 6, 269 billion: 9, 270 trillion: 12 271 }, 272 abbreviation, 273 value, 274 i, 275 regexp; 276 277 if (options.zeroFormat && string === options.zeroFormat) { 278 value = 0; 279 } else if (options.nullFormat && string === options.nullFormat || !string.replace(/[^0-9]+/g, '').length) { 280 value = null; 281 } else { 282 value = 1; 283 284 if (locale.delimiters.decimal !== '.') { 285 string = string.replace(/\./g, '').replace(locale.delimiters.decimal, '.'); 286 } 287 288 for (abbreviation in abbreviations) { 289 regexp = new RegExp('[^a-zA-Z]' + locale.abbreviations[abbreviation] + '(?:\\)|(\\' + locale.currency.symbol + ')?(?:\\))?)?$'); 290 291 if (stringOriginal.match(regexp)) { 292 value *= Math.pow(10, abbreviations[abbreviation]); 293 break; 294 } 295 } 296 297 // check for negative number 298 value *= (string.split('-').length + Math.min(string.split('(').length - 1, string.split(')').length - 1)) % 2 ? 1 : -1; 299 300 // remove non numbers 301 string = string.replace(/[^0-9\.]+/g, ''); 302 303 value *= Number(string); 304 } 305 306 return value; 307 }, 308 isNaN: function(value) { 309 return typeof value === 'number' && isNaN(value); 310 }, 311 includes: function(string, search) { 312 return string.indexOf(search) !== -1; 313 }, 314 insert: function(string, subString, start) { 315 return string.slice(0, start) + subString + string.slice(start); 316 }, 317 reduce: function(array, callback /*, initialValue*/) { 318 if (this === null) { 319 throw new TypeError('Array.prototype.reduce called on null or undefined'); 320 } 321 322 if (typeof callback !== 'function') { 323 throw new TypeError(callback + ' is not a function'); 324 } 325 326 var t = Object(array), 327 len = t.length >>> 0, 328 k = 0, 329 value; 330 331 if (arguments.length === 3) { 332 value = arguments[2]; 333 } else { 334 while (k < len && !(k in t)) { 335 k++; 336 } 337 338 if (k >= len) { 339 throw new TypeError('Reduce of empty array with no initial value'); 340 } 341 342 value = t[k++]; 343 } 344 for (; k < len; k++) { 345 if (k in t) { 346 value = callback(value, t[k], k, t); 347 } 348 } 349 return value; 350 }, 351 /** 352 * Computes the multiplier necessary to make x >= 1, 353 * effectively eliminating miscalculations caused by 354 * finite precision. 355 */ 356 multiplier: function (x) { 357 var parts = x.toString().split('.'); 358 359 return parts.length < 2 ? 1 : Math.pow(10, parts[1].length); 360 }, 361 /** 362 * Given a variable number of arguments, returns the maximum 363 * multiplier that must be used to normalize an operation involving 364 * all of them. 365 */ 366 correctionFactor: function () { 367 var args = Array.prototype.slice.call(arguments); 368 369 return args.reduce(function(accum, next) { 370 var mn = _.multiplier(next); 371 return accum > mn ? accum : mn; 372 }, 1); 373 }, 374 /** 375 * Implementation of toFixed() that treats floats more like decimals 376 * 377 * Fixes binary rounding issues (eg. (0.615).toFixed(2) === '0.61') that present 378 * problems for accounting- and finance-related software. 379 */ 380 toFixed: function(value, maxDecimals, roundingFunction, optionals) { 381 var splitValue = value.toString().split('.'), 382 minDecimals = maxDecimals - (optionals || 0), 383 boundedPrecision, 384 optionalsRegExp, 385 power, 386 output; 387 388 // Use the smallest precision value possible to avoid errors from floating point representation 389 if (splitValue.length === 2) { 390 boundedPrecision = Math.min(Math.max(splitValue[1].length, minDecimals), maxDecimals); 391 } else { 392 boundedPrecision = minDecimals; 393 } 394 395 power = Math.pow(10, boundedPrecision); 396 397 // Multiply up by precision, round accurately, then divide and use native toFixed(): 398 output = (roundingFunction(value + 'e+' + boundedPrecision) / power).toFixed(boundedPrecision); 399 400 if (optionals > maxDecimals - boundedPrecision) { 401 optionalsRegExp = new RegExp('\\.?0{1,' + (optionals - (maxDecimals - boundedPrecision)) + '}$'); 402 output = output.replace(optionalsRegExp, ''); 403 } 404 405 return output; 406 } 407 }; 408 409 // avaliable options 410 numeral.options = options; 411 412 // avaliable formats 413 numeral.formats = formats; 414 415 // avaliable formats 416 numeral.locales = locales; 417 418 // This function sets the current locale. If 419 // no arguments are passed in, it will simply return the current global 420 // locale key. 421 numeral.locale = function(key) { 422 if (key) { 423 options.currentLocale = key.toLowerCase(); 424 } 425 426 return options.currentLocale; 427 }; 428 429 // This function provides access to the loaded locale data. If 430 // no arguments are passed in, it will simply return the current 431 // global locale object. 432 numeral.localeData = function(key) { 433 if (!key) { 434 return locales[options.currentLocale]; 435 } 436 437 key = key.toLowerCase(); 438 439 if (!locales[key]) { 440 throw new Error('Unknown locale : ' + key); 441 } 442 443 return locales[key]; 444 }; 445 446 numeral.reset = function() { 447 for (var property in defaults) { 448 options[property] = defaults[property]; 449 } 450 }; 451 452 numeral.zeroFormat = function(format) { 453 options.zeroFormat = typeof(format) === 'string' ? format : null; 454 }; 455 456 numeral.nullFormat = function (format) { 457 options.nullFormat = typeof(format) === 'string' ? format : null; 458 }; 459 460 numeral.defaultFormat = function(format) { 461 options.defaultFormat = typeof(format) === 'string' ? format : '0.0'; 462 }; 463 464 numeral.register = function(type, name, format) { 465 name = name.toLowerCase(); 466 467 if (this[type + 's'][name]) { 468 throw new TypeError(name + ' ' + type + ' already registered.'); 469 } 470 471 this[type + 's'][name] = format; 472 473 return format; 474 }; 475 476 477 numeral.validate = function(val, culture) { 478 var _decimalSep, 479 _thousandSep, 480 _currSymbol, 481 _valArray, 482 _abbrObj, 483 _thousandRegEx, 484 localeData, 485 temp; 486 487 //coerce val to string 488 if (typeof val !== 'string') { 489 val += ''; 490 491 if (console.warn) { 492 console.warn('Numeral.js: Value is not string. It has been co-erced to: ', val); 493 } 494 } 495 496 //trim whitespaces from either sides 497 val = val.trim(); 498 499 //if val is just digits return true 500 if (!!val.match(/^\d+$/)) { 501 return true; 502 } 503 504 //if val is empty return false 505 if (val === '') { 506 return false; 507 } 508 509 //get the decimal and thousands separator from numeral.localeData 510 try { 511 //check if the culture is understood by numeral. if not, default it to current locale 512 localeData = numeral.localeData(culture); 513 } catch (e) { 514 localeData = numeral.localeData(numeral.locale()); 515 } 516 517 //setup the delimiters and currency symbol based on culture/locale 518 _currSymbol = localeData.currency.symbol; 519 _abbrObj = localeData.abbreviations; 520 _decimalSep = localeData.delimiters.decimal; 521 if (localeData.delimiters.thousands === '.') { 522 _thousandSep = '\\.'; 523 } else { 524 _thousandSep = localeData.delimiters.thousands; 525 } 526 527 // validating currency symbol 528 temp = val.match(/^[^\d]+/); 529 if (temp !== null) { 530 val = val.substr(1); 531 if (temp[0] !== _currSymbol) { 532 return false; 533 } 534 } 535 536 //validating abbreviation symbol 537 temp = val.match(/[^\d]+$/); 538 if (temp !== null) { 539 val = val.slice(0, -1); 540 if (temp[0] !== _abbrObj.thousand && temp[0] !== _abbrObj.million && temp[0] !== _abbrObj.billion && temp[0] !== _abbrObj.trillion) { 541 return false; 542 } 543 } 544 545 _thousandRegEx = new RegExp(_thousandSep + '{2}'); 546 547 if (!val.match(/[^\d.,]/g)) { 548 _valArray = val.split(_decimalSep); 549 if (_valArray.length > 2) { 550 return false; 551 } else { 552 if (_valArray.length < 2) { 553 return ( !! _valArray[0].match(/^\d+.*\d$/) && !_valArray[0].match(_thousandRegEx)); 554 } else { 555 if (_valArray[0].length === 1) { 556 return ( !! _valArray[0].match(/^\d+$/) && !_valArray[0].match(_thousandRegEx) && !! _valArray[1].match(/^\d+$/)); 557 } else { 558 return ( !! _valArray[0].match(/^\d+.*\d$/) && !_valArray[0].match(_thousandRegEx) && !! _valArray[1].match(/^\d+$/)); 559 } 560 } 561 } 562 } 563 564 return false; 565 }; 566 567 568 /************************************ 569 Numeral Prototype 570 ************************************/ 571 572 numeral.fn = Numeral.prototype = { 573 clone: function() { 574 return numeral(this); 575 }, 576 format: function(inputString, roundingFunction) { 577 var value = this._value, 578 format = inputString || options.defaultFormat, 579 kind, 580 output, 581 formatFunction; 582 583 // make sure we have a roundingFunction 584 roundingFunction = roundingFunction || Math.round; 585 586 // format based on value 587 if (value === 0 && options.zeroFormat !== null) { 588 output = options.zeroFormat; 589 } else if (value === null && options.nullFormat !== null) { 590 output = options.nullFormat; 591 } else { 592 for (kind in formats) { 593 if (format.match(formats[kind].regexps.format)) { 594 formatFunction = formats[kind].format; 595 596 break; 597 } 598 } 599 600 formatFunction = formatFunction || numeral._.numberToFormat; 601 602 output = formatFunction(value, format, roundingFunction); 603 } 604 605 return output; 606 }, 607 value: function() { 608 return this._value; 609 }, 610 input: function() { 611 return this._input; 612 }, 613 set: function(value) { 614 this._value = Number(value); 615 616 return this; 617 }, 618 add: function(value) { 619 var corrFactor = _.correctionFactor.call(null, this._value, value); 620 621 function cback(accum, curr, currI, O) { 622 return accum + Math.round(corrFactor * curr); 623 } 624 625 this._value = _.reduce([this._value, value], cback, 0) / corrFactor; 626 627 return this; 628 }, 629 subtract: function(value) { 630 var corrFactor = _.correctionFactor.call(null, this._value, value); 631 632 function cback(accum, curr, currI, O) { 633 return accum - Math.round(corrFactor * curr); 634 } 635 636 this._value = _.reduce([value], cback, Math.round(this._value * corrFactor)) / corrFactor; 637 638 return this; 639 }, 640 multiply: function(value) { 641 function cback(accum, curr, currI, O) { 642 var corrFactor = _.correctionFactor(accum, curr); 643 return Math.round(accum * corrFactor) * Math.round(curr * corrFactor) / Math.round(corrFactor * corrFactor); 644 } 645 646 this._value = _.reduce([this._value, value], cback, 1); 647 648 return this; 649 }, 650 divide: function(value) { 651 function cback(accum, curr, currI, O) { 652 var corrFactor = _.correctionFactor(accum, curr); 653 return Math.round(accum * corrFactor) / Math.round(curr * corrFactor); 654 } 655 656 this._value = _.reduce([this._value, value], cback); 657 658 return this; 659 }, 660 difference: function(value) { 661 return Math.abs(numeral(this._value).subtract(value).value()); 662 } 663 }; 664 665 /************************************ 666 Default Locale && Format 667 ************************************/ 668 669 numeral.register('locale', 'en', { 670 delimiters: { 671 thousands: ',', 672 decimal: '.' 673 }, 674 abbreviations: { 675 thousand: 'k', 676 million: 'm', 677 billion: 'b', 678 trillion: 't' 679 }, 680 ordinal: function(number) { 681 var b = number % 10; 682 return (~~(number % 100 / 10) === 1) ? 'th' : 683 (b === 1) ? 'st' : 684 (b === 2) ? 'nd' : 685 (b === 3) ? 'rd' : 'th'; 686 }, 687 currency: { 688 symbol: '$' 689 } 690 }); 691 692 693 694(function() { 695 numeral.register('format', 'bps', { 696 regexps: { 697 format: /(BPS)/, 698 unformat: /(BPS)/ 699 }, 700 format: function(value, format, roundingFunction) { 701 var space = numeral._.includes(format, ' BPS') ? ' ' : '', 702 output; 703 704 value = value * 10000; 705 706 // check for space before BPS 707 format = format.replace(/\s?BPS/, ''); 708 709 output = numeral._.numberToFormat(value, format, roundingFunction); 710 711 if (numeral._.includes(output, ')')) { 712 output = output.split(''); 713 714 output.splice(-1, 0, space + 'BPS'); 715 716 output = output.join(''); 717 } else { 718 output = output + space + 'BPS'; 719 } 720 721 return output; 722 }, 723 unformat: function(string) { 724 return +(numeral._.stringToNumber(string) * 0.0001).toFixed(15); 725 } 726 }); 727})(); 728 729 730(function() { 731 var decimal = { 732 base: 1000, 733 suffixes: ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] 734 }, 735 binary = { 736 base: 1024, 737 suffixes: ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] 738 }; 739 740 var allSuffixes = decimal.suffixes.concat(binary.suffixes.filter(function (item) { 741 return decimal.suffixes.indexOf(item) < 0; 742 })); 743 var unformatRegex = allSuffixes.join('|'); 744 // Allow support for BPS (http://www.investopedia.com/terms/b/basispoint.asp) 745 unformatRegex = '(' + unformatRegex.replace('B', 'B(?!PS)') + ')'; 746 747 numeral.register('format', 'bytes', { 748 regexps: { 749 format: /([0\s]i?b)/, 750 unformat: new RegExp(unformatRegex) 751 }, 752 format: function(value, format, roundingFunction) { 753 var output, 754 bytes = numeral._.includes(format, 'ib') ? binary : decimal, 755 suffix = numeral._.includes(format, ' b') || numeral._.includes(format, ' ib') ? ' ' : '', 756 power, 757 min, 758 max; 759 760 // check for space before 761 format = format.replace(/\s?i?b/, ''); 762 763 for (power = 0; power <= bytes.suffixes.length; power++) { 764 min = Math.pow(bytes.base, power); 765 max = Math.pow(bytes.base, power + 1); 766 767 if (value === null || value === 0 || value >= min && value < max) { 768 suffix += bytes.suffixes[power]; 769 770 if (min > 0) { 771 value = value / min; 772 } 773 774 break; 775 } 776 } 777 778 output = numeral._.numberToFormat(value, format, roundingFunction); 779 780 return output + suffix; 781 }, 782 unformat: function(string) { 783 var value = numeral._.stringToNumber(string), 784 power, 785 bytesMultiplier; 786 787 if (value) { 788 for (power = decimal.suffixes.length - 1; power >= 0; power--) { 789 if (numeral._.includes(string, decimal.suffixes[power])) { 790 bytesMultiplier = Math.pow(decimal.base, power); 791 792 break; 793 } 794 795 if (numeral._.includes(string, binary.suffixes[power])) { 796 bytesMultiplier = Math.pow(binary.base, power); 797 798 break; 799 } 800 } 801 802 value *= (bytesMultiplier || 1); 803 } 804 805 return value; 806 } 807 }); 808})(); 809 810 811(function() { 812 numeral.register('format', 'currency', { 813 regexps: { 814 format: /(\$)/ 815 }, 816 format: function(value, format, roundingFunction) { 817 var locale = numeral.locales[numeral.options.currentLocale], 818 symbols = { 819 before: format.match(/^([\+|\-|\(|\s|\$]*)/)[0], 820 after: format.match(/([\+|\-|\)|\s|\$]*)$/)[0] 821 }, 822 output, 823 symbol, 824 i; 825 826 // strip format of spaces and $ 827 format = format.replace(/\s?\$\s?/, ''); 828 829 // format the number 830 output = numeral._.numberToFormat(value, format, roundingFunction); 831 832 // update the before and after based on value 833 if (value >= 0) { 834 symbols.before = symbols.before.replace(/[\-\(]/, ''); 835 symbols.after = symbols.after.replace(/[\-\)]/, ''); 836 } else if (value < 0 && (!numeral._.includes(symbols.before, '-') && !numeral._.includes(symbols.before, '('))) { 837 symbols.before = '-' + symbols.before; 838 } 839 840 // loop through each before symbol 841 for (i = 0; i < symbols.before.length; i++) { 842 symbol = symbols.before[i]; 843 844 switch (symbol) { 845 case '$': 846 output = numeral._.insert(output, locale.currency.symbol, i); 847 break; 848 case ' ': 849 output = numeral._.insert(output, ' ', i + locale.currency.symbol.length - 1); 850 break; 851 } 852 } 853 854 // loop through each after symbol 855 for (i = symbols.after.length - 1; i >= 0; i--) { 856 symbol = symbols.after[i]; 857 858 switch (symbol) { 859 case '$': 860 output = i === symbols.after.length - 1 ? output + locale.currency.symbol : numeral._.insert(output, locale.currency.symbol, -(symbols.after.length - (1 + i))); 861 break; 862 case ' ': 863 output = i === symbols.after.length - 1 ? output + ' ' : numeral._.insert(output, ' ', -(symbols.after.length - (1 + i) + locale.currency.symbol.length - 1)); 864 break; 865 } 866 } 867 868 869 return output; 870 } 871 }); 872})(); 873 874 875(function() { 876 numeral.register('format', 'exponential', { 877 regexps: { 878 format: /(e\+|e-)/, 879 unformat: /(e\+|e-)/ 880 }, 881 format: function(value, format, roundingFunction) { 882 var output, 883 exponential = typeof value === 'number' && !numeral._.isNaN(value) ? value.toExponential() : '0e+0', 884 parts = exponential.split('e'); 885 886 format = format.replace(/e[\+|\-]{1}0/, ''); 887 888 output = numeral._.numberToFormat(Number(parts[0]), format, roundingFunction); 889 890 return output + 'e' + parts[1]; 891 }, 892 unformat: function(string) { 893 var parts = numeral._.includes(string, 'e+') ? string.split('e+') : string.split('e-'), 894 value = Number(parts[0]), 895 power = Number(parts[1]); 896 897 power = numeral._.includes(string, 'e-') ? power *= -1 : power; 898 899 function cback(accum, curr, currI, O) { 900 var corrFactor = numeral._.correctionFactor(accum, curr), 901 num = (accum * corrFactor) * (curr * corrFactor) / (corrFactor * corrFactor); 902 return num; 903 } 904 905 return numeral._.reduce([value, Math.pow(10, power)], cback, 1); 906 } 907 }); 908})(); 909 910 911(function() { 912 numeral.register('format', 'ordinal', { 913 regexps: { 914 format: /(o)/ 915 }, 916 format: function(value, format, roundingFunction) { 917 var locale = numeral.locales[numeral.options.currentLocale], 918 output, 919 ordinal = numeral._.includes(format, ' o') ? ' ' : ''; 920 921 // check for space before 922 format = format.replace(/\s?o/, ''); 923 924 ordinal += locale.ordinal(value); 925 926 output = numeral._.numberToFormat(value, format, roundingFunction); 927 928 return output + ordinal; 929 } 930 }); 931})(); 932 933 934(function() { 935 numeral.register('format', 'percentage', { 936 regexps: { 937 format: /(%)/, 938 unformat: /(%)/ 939 }, 940 format: function(value, format, roundingFunction) { 941 var space = numeral._.includes(format, ' %') ? ' ' : '', 942 output; 943 944 if (numeral.options.scalePercentBy100) { 945 value = value * 100; 946 } 947 948 // check for space before % 949 format = format.replace(/\s?\%/, ''); 950 951 output = numeral._.numberToFormat(value, format, roundingFunction); 952 953 if (numeral._.includes(output, ')')) { 954 output = output.split(''); 955 956 output.splice(-1, 0, space + '%'); 957 958 output = output.join(''); 959 } else { 960 output = output + space + '%'; 961 } 962 963 return output; 964 }, 965 unformat: function(string) { 966 var number = numeral._.stringToNumber(string); 967 if (numeral.options.scalePercentBy100) { 968 return number * 0.01; 969 } 970 return number; 971 } 972 }); 973})(); 974 975 976(function() { 977 numeral.register('format', 'time', { 978 regexps: { 979 format: /(:)/, 980 unformat: /(:)/ 981 }, 982 format: function(value, format, roundingFunction) { 983 var hours = Math.floor(value / 60 / 60), 984 minutes = Math.floor((value - (hours * 60 * 60)) / 60), 985 seconds = Math.round(value - (hours * 60 * 60) - (minutes * 60)); 986 987 return hours + ':' + (minutes < 10 ? '0' + minutes : minutes) + ':' + (seconds < 10 ? '0' + seconds : seconds); 988 }, 989 unformat: function(string) { 990 var timeArray = string.split(':'), 991 seconds = 0; 992 993 // turn hours and minutes into seconds and add them all up 994 if (timeArray.length === 3) { 995 // hours 996 seconds = seconds + (Number(timeArray[0]) * 60 * 60); 997 // minutes 998 seconds = seconds + (Number(timeArray[1]) * 60); 999 // seconds 1000 seconds = seconds + Number(timeArray[2]); 1001 } else if (timeArray.length === 2) { 1002 // minutes 1003 seconds = seconds + (Number(timeArray[0]) * 60); 1004 // seconds 1005 seconds = seconds + Number(timeArray[1]); 1006 } 1007 return Number(seconds); 1008 } 1009 }); 1010})(); 1011 1012return numeral; 1013}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.