Example #1
0
 /** @internal */
 static _format(value, style, digits, currency = null, currencyAsSymbol = false) {
     if (isBlank(value))
         return null;
     if (!isNumber(value)) {
         throw new InvalidPipeArgumentException(NumberPipe_1, value);
     }
     var minInt = 1, minFraction = 0, maxFraction = 3;
     if (isPresent(digits)) {
         var parts = RegExpWrapper.firstMatch(_re, digits);
         if (isBlank(parts)) {
             throw new BaseException(`${digits} is not a valid digit info for number pipes`);
         }
         if (isPresent(parts[1])) {
             minInt = NumberWrapper.parseIntAutoRadix(parts[1]);
         }
         if (isPresent(parts[3])) {
             minFraction = NumberWrapper.parseIntAutoRadix(parts[3]);
         }
         if (isPresent(parts[5])) {
             maxFraction = NumberWrapper.parseIntAutoRadix(parts[5]);
         }
     }
     return NumberFormatter.format(value, defaultLocale, style, {
         minimumIntegerDigits: minInt,
         minimumFractionDigits: minFraction,
         maximumFractionDigits: maxFraction,
         currency: currency,
         currencyAsSymbol: currencyAsSymbol
     });
 }
 NumberPipe._format = function (value, style, digits, currency, currencyAsSymbol) {
     if (currency === void 0) { currency = null; }
     if (currencyAsSymbol === void 0) { currencyAsSymbol = false; }
     if (lang_1.isBlank(value))
         return null;
     if (!lang_1.isNumber(value)) {
         throw new invalid_pipe_argument_exception_1.InvalidPipeArgumentException(NumberPipe, value);
     }
     var minInt = 1, minFraction = 0, maxFraction = 3;
     if (lang_1.isPresent(digits)) {
         var parts = lang_1.RegExpWrapper.firstMatch(_re, digits);
         if (lang_1.isBlank(parts)) {
             throw new exceptions_1.BaseException(digits + " is not a valid digit info for number pipes");
         }
         if (lang_1.isPresent(parts[1])) {
             minInt = lang_1.NumberWrapper.parseIntAutoRadix(parts[1]);
         }
         if (lang_1.isPresent(parts[3])) {
             minFraction = lang_1.NumberWrapper.parseIntAutoRadix(parts[3]);
         }
         if (lang_1.isPresent(parts[5])) {
             maxFraction = lang_1.NumberWrapper.parseIntAutoRadix(parts[5]);
         }
     }
     return intl_1.NumberFormatter.format(value, defaultLocale, style, {
         minimumIntegerDigits: minInt,
         minimumFractionDigits: minFraction,
         maximumFractionDigits: maxFraction,
         currency: currency,
         currencyAsSymbol: currencyAsSymbol
     });
 };
Example #3
0
 _Scanner.prototype.scanNumber = function (start) {
     assert(isDigit(this.peek));
     var simple = (this.index === start);
     this.advance(); // Skip initial digit.
     while (true) {
         if (isDigit(this.peek)) {
         }
         else if (this.peek == exports.$PERIOD) {
             simple = false;
         }
         else if (isExponentStart(this.peek)) {
             this.advance();
             if (isExponentSign(this.peek))
                 this.advance();
             if (!isDigit(this.peek))
                 this.error('Invalid exponent', -1);
             simple = false;
         }
         else {
             break;
         }
         this.advance();
     }
     var str = this.input.substring(start, this.index);
     // TODO
     var value = simple ? lang_1.NumberWrapper.parseIntAutoRadix(str) : lang_1.NumberWrapper.parseFloat(str);
     return newNumberToken(start, value);
 };
Example #4
0
 /**
  * Exercises change detection in a loop and then prints the average amount of
  * time in milliseconds how long a single round of change detection takes for
  * the current state of the UI. It runs a minimum of 5 rounds for a minimum
  * of 500 milliseconds.
  *
  * Optionally, a user may pass a `config` parameter containing a map of
  * options. Supported options are:
  *
  * `record` (boolean) - causes the profiler to record a CPU profile while
  * it exercises the change detector. Example:
  *
  * ```
  * ng.profiler.timeChangeDetection({record: true})
  * ```
  */
 timeChangeDetection(config) {
     var record = isPresent(config) && config['record'];
     var profileName = 'Change Detection';
     // Profiler is not available in Android browsers, nor in IE 9 without dev tools opened
     var isProfilerAvailable = isPresent(window.console.profile);
     if (record && isProfilerAvailable) {
         window.console.profile(profileName);
     }
     var start = DOM.performanceNow();
     var numTicks = 0;
     while (numTicks < 5 || (DOM.performanceNow() - start) < 500) {
         this.appRef.tick();
         numTicks++;
     }
     var end = DOM.performanceNow();
     if (record && isProfilerAvailable) {
         // need to cast to <any> because type checker thinks there's no argument
         // while in fact there is:
         //
         // https://developer.mozilla.org/en-US/docs/Web/API/Console/profileEnd
         window.console.profileEnd(profileName);
     }
     var msPerTick = (end - start) / numTicks;
     window.console.log(`ran ${numTicks} change detection cycles`);
     window.console.log(`${NumberWrapper.toFixed(msPerTick, 2)} ms per check`);
     return new ChangeDetectionPerfRecord(msPerTick, numTicks);
 }
 AngularProfiler.prototype.timeChangeDetection = function (config) {
     var record = lang_1.isPresent(config) && config['record'];
     var profileName = 'Change Detection';
     // Profiler is not available in Android browsers, nor in IE 9 without dev tools opened
     var isProfilerAvailable = lang_1.isPresent(browser_1.window.console.profile);
     if (record && isProfilerAvailable) {
         browser_1.window.console.profile(profileName);
     }
     var start = dom_adapter_1.DOM.performanceNow();
     var numTicks = 0;
     while (numTicks < 5 || (dom_adapter_1.DOM.performanceNow() - start) < 500) {
         this.appRef.tick();
         numTicks++;
     }
     var end = dom_adapter_1.DOM.performanceNow();
     if (record && isProfilerAvailable) {
         // need to cast to <any> because type checker thinks there's no argument
         // while in fact there is:
         //
         // https://developer.mozilla.org/en-US/docs/Web/API/Console/profileEnd
         browser_1.window.console.profileEnd(profileName);
     }
     var msPerTick = (end - start) / numTicks;
     browser_1.window.console.log("ran " + numTicks + " change detection cycles");
     browser_1.window.console.log(lang_1.NumberWrapper.toFixed(msPerTick, 2) + " ms per check");
 };
Example #6
0
 ListWrapper.map(this._metricNames, (metricName) => {
   var sample = ListWrapper.map(validSample, (measureValues) => measureValues.values[metricName]);
   var mean = Statistic.calculateMean(sample);
   var cv = Statistic.calculateCoefficientOfVariation(sample, mean);
   var formattedMean = ConsoleReporter._formatNum(mean)
   // Note: Don't use the unicode character for +- as it might cause
   // hickups for consoles...
   return NumberWrapper.isNaN(cv) ? formattedMean : `${formattedMean}+-${Math.floor(cv)}%`;
 })
Example #7
0
 /**
  * Converts the duration string to the number of milliseconds
  * @param duration
  * @returns {number}
  */
 parseDurationString(duration) {
     var maxValue = 0;
     // duration must have at least 2 characters to be valid. (number + type)
     if (duration == null || duration.length < 2) {
         return maxValue;
     }
     else if (duration.substring(duration.length - 2) == 'ms') {
         let value = NumberWrapper.parseInt(this.stripLetters(duration), 10);
         if (value > maxValue)
             maxValue = value;
     }
     else if (duration.substring(duration.length - 1) == 's') {
         let ms = NumberWrapper.parseFloat(this.stripLetters(duration)) * 1000;
         let value = Math.floor(ms);
         if (value > maxValue)
             maxValue = value;
     }
     return maxValue;
 }
Example #8
0
 Animation.prototype.parseDurationString = function (duration) {
     var maxValue = 0;
     // duration must have at least 2 characters to be valid. (number + type)
     if (duration == null || duration.length < 2) {
         return maxValue;
     }
     else if (duration.substring(duration.length - 2) == 'ms') {
         var value = lang_1.NumberWrapper.parseInt(this.stripLetters(duration), 10);
         if (value > maxValue)
             maxValue = value;
     }
     else if (duration.substring(duration.length - 1) == 's') {
         var ms = lang_1.NumberWrapper.parseFloat(this.stripLetters(duration)) * 1000;
         var value = math_1.Math.floor(ms);
         if (value > maxValue)
             maxValue = value;
     }
     return maxValue;
 };
Example #9
0
 return new MockStep((parent, current, control) => {
   var parentCountStr = DOM.getAttribute(current.element, wrapperId);
   if (isPresent(parentCountStr)) {
     var parentCount = NumberWrapper.parseInt(parentCountStr, 10);
     while (parentCount > 0) {
       control.addParent(new CompileElement(el(`<a id="${wrapperId}#${nextElementId++}"></a>`)));
       parentCount--;
     }
   }
   logEntry(log, parent, current);
 });
Example #10
0
 _Scanner.prototype.scanString = function () {
     assert(this.peek == exports.$SQ || this.peek == exports.$DQ);
     var start = this.index;
     var quote = this.peek;
     this.advance(); // Skip initial quote.
     var buffer;
     var marker = this.index;
     var input = this.input;
     while (this.peek != quote) {
         if (this.peek == exports.$BACKSLASH) {
             if (buffer == null)
                 buffer = new lang_1.StringJoiner();
             buffer.add(input.substring(marker, this.index));
             this.advance();
             var unescapedCode;
             if (this.peek == $u) {
                 // 4 character hex code for unicode character.
                 var hex = input.substring(this.index + 1, this.index + 5);
                 try {
                     unescapedCode = lang_1.NumberWrapper.parseInt(hex, 16);
                 }
                 catch (e) {
                     this.error("Invalid unicode escape [\\u" + hex + "]", 0);
                 }
                 for (var i = 0; i < 5; i++) {
                     this.advance();
                 }
             }
             else {
                 unescapedCode = unescape(this.peek);
                 this.advance();
             }
             buffer.add(lang_1.StringWrapper.fromCharCode(unescapedCode));
             marker = this.index;
         }
         else if (this.peek == exports.$EOF) {
             this.error('Unterminated quote', 0);
         }
         else {
             this.advance();
         }
     }
     var last = input.substring(marker, this.index);
     this.advance(); // Skip terminating quote.
     // Compute the unescaped string value.
     var unescaped = last;
     if (buffer != null) {
         buffer.add(last);
         unescaped = buffer.toString();
     }
     return newStringToken(start, unescaped);
 };
 _mergeElementOrInterpolation(t, translated, mapping) {
     let name = this._getName(t);
     let type = name[0];
     let index = NumberWrapper.parseInt(name.substring(1), 10);
     let originalNode = mapping[index];
     if (type == "t") {
         return this._mergeTextInterpolation(t, originalNode);
     }
     else if (type == "e") {
         return this._mergeElement(t, originalNode, mapping);
     }
     else {
         throw new BaseException("should not be reached");
     }
 }
 I18nHtmlParser.prototype._mergeElementOrInterpolation = function (t, translated, mapping) {
     var name = this._getName(t);
     var type = name[0];
     var index = lang_1.NumberWrapper.parseInt(name.substring(1), 10);
     var originalNode = mapping[index];
     if (type == "t") {
         return this._mergeTextInterpolation(t, originalNode);
     }
     else if (type == "e") {
         return this._mergeElement(t, originalNode, mapping);
     }
     else {
         throw new exceptions_1.BaseException("should not be reached");
     }
 };
Example #13
0
    events.forEach( (event) => {
      var ph = event['ph'];
      var name = event['name'];
      var microIterations = 1;
      var microIterationsMatch = RegExpWrapper.firstMatch(_MICRO_ITERATIONS_REGEX, name);
      if (isPresent(microIterationsMatch)) {
        name = microIterationsMatch[1];
        microIterations = NumberWrapper.parseInt(microIterationsMatch[2], 10);
      }

      if (StringWrapper.equals(ph, 'b') && StringWrapper.equals(name, markName)) {
        markStartEvent = event;
      } else if (StringWrapper.equals(ph, 'e') && StringWrapper.equals(name, markName)) {
        markEndEvent = event;
      }
      if (isPresent(markStartEvent) && isBlank(markEndEvent) && event['pid'] === markStartEvent['pid']) {
        if (StringWrapper.equals(ph, 'B') || StringWrapper.equals(ph, 'b')) {
          intervalStarts[name] = event;
        } else if ((StringWrapper.equals(ph, 'E') || StringWrapper.equals(ph, 'e')) && isPresent(intervalStarts[name])) {
          var startEvent = intervalStarts[name];
          var duration = (event['ts'] - startEvent['ts']);
          intervalStarts[name] = null;
          if (StringWrapper.equals(name, 'gc')) {
            result['gcTime'] += duration;
            var amount = (startEvent['args']['usedHeapSize'] - event['args']['usedHeapSize']) / 1000;
            result['gcAmount'] += amount;
            var majorGc = event['args']['majorGc'];
            if (isPresent(majorGc) && majorGc) {
              result['majorGcTime'] += duration;
            }
            if (isPresent(intervalStarts['script'])) {
              gcTimeInScript += duration;
            }
          } else if (StringWrapper.equals(name, 'render')) {
            result['renderTime'] += duration;
            if (isPresent(intervalStarts['script'])) {
              renderTimeInScript += duration;
            }
          } else if (StringWrapper.equals(name, 'script')) {
            result['scriptTime'] += duration;
          } else if (isPresent(this._microMetrics[name])) {
            result[name] += duration / microIterations;
          }
        }
      }
    });
Example #14
0
 _decodeEntity() {
     var start = this._getLocation();
     this._advance();
     if (this._attemptCharCode($HASH)) {
         let isHex = this._attemptCharCode($x) || this._attemptCharCode($X);
         let numberStart = this._getLocation().offset;
         this._attemptCharCodeUntilFn(isDigitEntityEnd);
         if (this.peek != $SEMICOLON) {
             throw this._createError(unexpectedCharacterErrorMsg(this.peek), this._getSpan());
         }
         this._advance();
         let strNum = this.input.substring(numberStart, this.index - 1);
         try {
             let charCode = NumberWrapper.parseInt(strNum, isHex ? 16 : 10);
             return StringWrapper.fromCharCode(charCode);
         }
         catch (e) {
             let entity = this.input.substring(start.offset + 1, this.index - 1);
             throw this._createError(unknownEntityErrorMsg(entity), this._getSpan(start));
         }
     }
     else {
         let startPosition = this._savePosition();
         this._attemptCharCodeUntilFn(isNamedEntityEnd);
         if (this.peek != $SEMICOLON) {
             this._restorePosition(startPosition);
             return '&';
         }
         this._advance();
         let name = this.input.substring(start.offset + 1, this.index - 1);
         let char = NAMED_ENTITIES[name];
         if (isBlank(char)) {
             throw this._createError(unknownEntityErrorMsg(name), this._getSpan(start));
         }
         return char;
     }
 }
Example #15
0
 events.forEach((event) => {
     var ph = event['ph'];
     var name = event['name'];
     var microIterations = 1;
     var microIterationsMatch = RegExpWrapper.firstMatch(_MICRO_ITERATIONS_REGEX, name);
     if (isPresent(microIterationsMatch)) {
         name = microIterationsMatch[1];
         microIterations = NumberWrapper.parseInt(microIterationsMatch[2], 10);
     }
     if (StringWrapper.equals(ph, 'b') && StringWrapper.equals(name, markName)) {
         markStartEvent = event;
     }
     else if (StringWrapper.equals(ph, 'e') && StringWrapper.equals(name, markName)) {
         markEndEvent = event;
     }
     let isInstant = StringWrapper.equals(ph, 'I') || StringWrapper.equals(ph, 'i');
     if (this._requestCount && StringWrapper.equals(name, 'sendRequest')) {
         result['requestCount'] += 1;
     }
     else if (this._receivedData && StringWrapper.equals(name, 'receivedData') && isInstant) {
         result['receivedData'] += event['args']['encodedDataLength'];
     }
     else if (StringWrapper.equals(name, 'navigationStart')) {
         // We count data + requests since the last navigationStart
         // (there might be chrome extensions loaded by selenium before our page, so there
         // will likely be more than one navigationStart).
         if (this._receivedData) {
             result['receivedData'] = 0;
         }
         if (this._requestCount) {
             result['requestCount'] = 0;
         }
     }
     if (isPresent(markStartEvent) && isBlank(markEndEvent) &&
         event['pid'] === markStartEvent['pid']) {
         if (StringWrapper.equals(ph, 'b') && StringWrapper.equals(name, _MARK_NAME_FRAME_CAPUTRE)) {
             if (isPresent(frameCaptureStartEvent)) {
                 throw new BaseException('can capture frames only once per benchmark run');
             }
             if (!this._captureFrames) {
                 throw new BaseException('found start event for frame capture, but frame capture was not requested in benchpress');
             }
             frameCaptureStartEvent = event;
         }
         else if (StringWrapper.equals(ph, 'e') &&
             StringWrapper.equals(name, _MARK_NAME_FRAME_CAPUTRE)) {
             if (isBlank(frameCaptureStartEvent)) {
                 throw new BaseException('missing start event for frame capture');
             }
             frameCaptureEndEvent = event;
         }
         if (isInstant) {
             if (isPresent(frameCaptureStartEvent) && isBlank(frameCaptureEndEvent) &&
                 StringWrapper.equals(name, 'frame')) {
                 frameTimestamps.push(event['ts']);
                 if (frameTimestamps.length >= 2) {
                     frameTimes.push(frameTimestamps[frameTimestamps.length - 1] -
                         frameTimestamps[frameTimestamps.length - 2]);
                 }
             }
         }
         if (StringWrapper.equals(ph, 'B') || StringWrapper.equals(ph, 'b')) {
             if (isBlank(intervalStarts[name])) {
                 intervalStartCount[name] = 1;
                 intervalStarts[name] = event;
             }
             else {
                 intervalStartCount[name]++;
             }
         }
         else if ((StringWrapper.equals(ph, 'E') || StringWrapper.equals(ph, 'e')) &&
             isPresent(intervalStarts[name])) {
             intervalStartCount[name]--;
             if (intervalStartCount[name] === 0) {
                 var startEvent = intervalStarts[name];
                 var duration = (event['ts'] - startEvent['ts']);
                 intervalStarts[name] = null;
                 if (StringWrapper.equals(name, 'gc')) {
                     result['gcTime'] += duration;
                     var amount = (startEvent['args']['usedHeapSize'] - event['args']['usedHeapSize']) / 1000;
                     result['gcAmount'] += amount;
                     var majorGc = event['args']['majorGc'];
                     if (isPresent(majorGc) && majorGc) {
                         result['majorGcTime'] += duration;
                     }
                     if (isPresent(intervalStarts['script'])) {
                         gcTimeInScript += duration;
                     }
                 }
                 else if (StringWrapper.equals(name, 'render')) {
                     result['renderTime'] += duration;
                     if (isPresent(intervalStarts['script'])) {
                         renderTimeInScript += duration;
                     }
                 }
                 else if (StringWrapper.equals(name, 'script')) {
                     result['scriptTime'] += duration;
                 }
                 else if (isPresent(this._microMetrics[name])) {
                     result[name] += duration / microIterations;
                 }
             }
         }
     }
 });
this.onChange = function (value) { fn(lang_1.NumberWrapper.parseFloat(value)); };
this.onChange = (value) => { fn(value == '' ? null : NumberWrapper.parseFloat(value)); };
Example #18
0
 set: function (value) {
     this._mdShrinkSpeed = lang_1.isString(value) ? lang_1.NumberWrapper.parseFloat(value) : value;
 },
Example #19
0
 /** @internal */
 _stripValue(value) { return NumberWrapper.parseInt(value.substring(1), 10); }
Example #20
0
 constructor(maxLength) {
     this._validator = Validators.maxLength(NumberWrapper.parseInt(maxLength, 10));
 }
Example #21
0
 NgPlural.prototype._stripValue = function (value) { return lang_1.NumberWrapper.parseInt(value.substring(1), 10); };
function getIntParameter(name) {
    return lang_1.NumberWrapper.parseInt(getStringParameter(name), 10);
}
 return elId.split(NG_ID_SEPARATOR).map(partStr => NumberWrapper.parseInt(partStr, 10));
 return RegExpWrapper.replaceAll(_PLACEHOLDER_EXPANDED_REGEXP, message, (match) => {
     let nameWithQuotes = match[2];
     let name = nameWithQuotes.substring(1, nameWithQuotes.length - 1);
     let index = NumberWrapper.parseInt(name, 10);
     return this._convertIntoExpression(index, exps, sourceSpan);
 });
Example #25
0
 MdPeekaboo.MakeNumber = function (value) {
     return lang_1.isString(value) ? lang_1.NumberWrapper.parseInt(value, 10) : value;
 };
 return lang_1.RegExpWrapper.replaceAll(_PLACEHOLDER_EXPANDED_REGEXP, message, function (match) {
     var nameWithQuotes = match[2];
     var name = nameWithQuotes.substring(1, nameWithQuotes.length - 1);
     var index = lang_1.NumberWrapper.parseInt(name, 10);
     return _this._convertIntoExpression(index, exps, sourceSpan);
 });
this.onChange = (value) => { fn(NumberWrapper.parseFloat(value)); };
 return collection_1.ListWrapper.map(lang_1.StringWrapper.split(elId, NG_ID_SEPARATOR_RE), function (partStr) { return lang_1.NumberWrapper.parseInt(partStr, 10); });
Example #29
0
 function MaxLengthValidator(maxLength) {
     this._validator = validators_1.Validators.maxLength(lang_2.NumberWrapper.parseInt(maxLength, 10));
 }
Example #30
0
 static _formatNum(n) {
   return NumberWrapper.toFixed(n, 2);
 }