| Index: third_party/WebKit/Source/devtools/front_end/audits2/lighthouse/renderer/util.js
|
| diff --git a/third_party/WebKit/Source/devtools/front_end/audits2/lighthouse/renderer/util.js b/third_party/WebKit/Source/devtools/front_end/audits2/lighthouse/renderer/util.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d92c65c83161c54efd429a091e56a1804a045dd4
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/devtools/front_end/audits2/lighthouse/renderer/util.js
|
| @@ -0,0 +1,78 @@
|
| +/**
|
| + * Copyright 2017 Google Inc. All rights reserved.
|
| + *
|
| + * Licensed under the Apache License, Version 2.0 (the "License");
|
| + * you may not use this file except in compliance with the License.
|
| + * You may obtain a copy of the License at
|
| + *
|
| + * http://www.apache.org/licenses/LICENSE-2.0
|
| + *
|
| + * Unless required by applicable law or agreed to in writing, software
|
| + * distributed under the License is distributed on an "AS IS" BASIS,
|
| + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| + * See the License for the specific language governing permissions and
|
| + * limitations under the License.
|
| + */
|
| +'use strict';
|
| +
|
| +/* globals self */
|
| +
|
| +const RATINGS = {
|
| + PASS: {label: 'pass', minScore: 75},
|
| + AVERAGE: {label: 'average', minScore: 45},
|
| + FAIL: {label: 'fail'}
|
| +};
|
| +
|
| +class Util {
|
| + /**
|
| + * Convert a score to a rating label.
|
| + * @param {number} score
|
| + * @return {string}
|
| + */
|
| + static calculateRating(score) {
|
| + let rating = RATINGS.FAIL.label;
|
| + if (score >= RATINGS.PASS.minScore) {
|
| + rating = RATINGS.PASS.label;
|
| + } else if (score >= RATINGS.AVERAGE.minScore) {
|
| + rating = RATINGS.AVERAGE.label;
|
| + }
|
| + return rating;
|
| + }
|
| +
|
| + /**
|
| + * Format number.
|
| + * @param {number} number
|
| + * @return {string}
|
| + */
|
| + static formatNumber(number) {
|
| + return number.toLocaleString(undefined, {maximumFractionDigits: 1});
|
| + }
|
| +
|
| + /**
|
| + * Format time.
|
| + * @param {string} date
|
| + * @return {string}
|
| + */
|
| + static formatDateTime(date) {
|
| + const options = {
|
| + month: 'short', day: 'numeric', year: 'numeric',
|
| + hour: 'numeric', minute: 'numeric', timeZoneName: 'short'
|
| + };
|
| + let formatter = new Intl.DateTimeFormat('en-US', options);
|
| +
|
| + // Force UTC if runtime timezone could not be detected.
|
| + // See https://github.com/GoogleChrome/lighthouse/issues/1056
|
| + const tz = formatter.resolvedOptions().timeZone;
|
| + if (!tz || tz.toLowerCase() === 'etc/unknown') {
|
| + options.timeZone = 'UTC';
|
| + formatter = new Intl.DateTimeFormat('en-US', options);
|
| + }
|
| + return formatter.format(new Date(date));
|
| + }
|
| +}
|
| +
|
| +if (typeof module !== 'undefined' && module.exports) {
|
| + module.exports = Util;
|
| +} else {
|
| + self.Util = Util;
|
| +}
|
|
|