Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Unified Diff: third_party/WebKit/Source/devtools/front_end/audits2/lighthouse/renderer/util.js

Issue 2856653002: Roll Lighthouse & add error reporting (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+}

Powered by Google App Engine
This is Rietveld 408576698