| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Copyright 2017 Google Inc. All rights reserved. | 2 * Copyright 2017 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Licensed under the Apache License, Version 2.0 (the "License"); | 4 * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 * you may not use this file except in compliance with the License. | 5 * you may not use this file except in compliance with the License. |
| 6 * You may obtain a copy of the License at | 6 * You may obtain a copy of the License at |
| 7 * | 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 | 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * | 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software | 10 * Unless required by applicable law or agreed to in writing, software |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, | 11 * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 * See the License for the specific language governing permissions and | 13 * See the License for the specific language governing permissions and |
| 14 * limitations under the License. | 14 * limitations under the License. |
| 15 */ | 15 */ |
| 16 'use strict'; | 16 'use strict'; |
| 17 | 17 |
| 18 /* globals self URL */ | 18 /* globals self URL */ |
| 19 | 19 |
| 20 const ELLIPSIS = '\u2026'; | 20 const ELLIPSIS = '\u2026'; |
| 21 const NBSP = '\xa0'; |
| 21 | 22 |
| 22 const RATINGS = { | 23 const RATINGS = { |
| 23 PASS: {label: 'pass', minScore: 75}, | 24 PASS: {label: 'pass', minScore: 75}, |
| 24 AVERAGE: {label: 'average', minScore: 45}, | 25 AVERAGE: {label: 'average', minScore: 45}, |
| 25 FAIL: {label: 'fail'} | 26 FAIL: {label: 'fail'} |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 class Util { | 29 class Util { |
| 29 /** | 30 /** |
| 30 * Convert a score to a rating label. | 31 * Convert a score to a rating label. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 53 /** | 54 /** |
| 54 * @param {number} size | 55 * @param {number} size |
| 55 * @param {number=} decimalPlaces Number of decimal places to include. Default
s to 2. | 56 * @param {number=} decimalPlaces Number of decimal places to include. Default
s to 2. |
| 56 * @return {string} | 57 * @return {string} |
| 57 */ | 58 */ |
| 58 static formateBytesToKB(size, decimalPlaces = 2) { | 59 static formateBytesToKB(size, decimalPlaces = 2) { |
| 59 return (size / 1024).toLocaleString(undefined, {maximumFractionDigits: decim
alPlaces}); | 60 return (size / 1024).toLocaleString(undefined, {maximumFractionDigits: decim
alPlaces}); |
| 60 } | 61 } |
| 61 | 62 |
| 62 /** | 63 /** |
| 64 * @param {number} ms |
| 65 * @param {number=} granularity Controls how coarse the displayed value is, de
faults to 10 |
| 66 * @return {string} |
| 67 */ |
| 68 static formatMilliseconds(ms, granularity = 10) { |
| 69 const coarseTime = Math.round(ms / granularity) * granularity; |
| 70 return `${coarseTime.toLocaleString()}${NBSP}ms`; |
| 71 } |
| 72 |
| 73 /** |
| 63 * Format time. | 74 * Format time. |
| 64 * @param {string} date | 75 * @param {string} date |
| 65 * @return {string} | 76 * @return {string} |
| 66 */ | 77 */ |
| 67 static formatDateTime(date) { | 78 static formatDateTime(date) { |
| 68 const options = { | 79 const options = { |
| 69 month: 'short', day: 'numeric', year: 'numeric', | 80 month: 'short', day: 'numeric', year: 'numeric', |
| 70 hour: 'numeric', minute: 'numeric', timeZoneName: 'short' | 81 hour: 'numeric', minute: 'numeric', timeZoneName: 'short' |
| 71 }; | 82 }; |
| 72 let formatter = new Intl.DateTimeFormat('en-US', options); | 83 let formatter = new Intl.DateTimeFormat('en-US', options); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 static chainDuration(startTime, endTime) { | 170 static chainDuration(startTime, endTime) { |
| 160 return Util.formatNumber((endTime - startTime) * 1000); | 171 return Util.formatNumber((endTime - startTime) * 1000); |
| 161 } | 172 } |
| 162 } | 173 } |
| 163 | 174 |
| 164 if (typeof module !== 'undefined' && module.exports) { | 175 if (typeof module !== 'undefined' && module.exports) { |
| 165 module.exports = Util; | 176 module.exports = Util; |
| 166 } else { | 177 } else { |
| 167 self.Util = Util; | 178 self.Util = Util; |
| 168 } | 179 } |
| OLD | NEW |