diff --git a/README.md b/README.md index 429e0e9b..164a1a19 100644 --- a/README.md +++ b/README.md @@ -761,6 +761,20 @@ Metric-specific subclasses: - [`LCPMetricWithAttribution`](/src/types/lcp.ts#:~:text=interface%20LCPMetricWithAttribution) - [`TTFBMetricWithAttribution`](/src/types/ttfb.ts#:~:text=interface%20TTFBMetricWithAttribution) +#### `MetricThresholds` + +```ts +/** + * The ranges defining a metric's "good", "needs improvement", and "poor" + * thresholds: + * + * - Metric values ≦ [0] are "good" + * - Metric values > [0] and ≦ [1] are "needs improvement" + * - Metric values > [1] are "poor". + */ +type MetricThresholds = [number, number]; +``` + #### `ReportCallback` ```ts diff --git a/src/lib/bindReporter.ts b/src/lib/bindReporter.ts index 0c2e2148..f3c42903 100644 --- a/src/lib/bindReporter.ts +++ b/src/lib/bindReporter.ts @@ -14,17 +14,12 @@ * limitations under the License. */ -import { - Metric, - MetricRating, - MetricThresholds, - ReportCallback, -} from '../types.js'; +import {Metric, MetricThresholds, ReportCallback} from '../types.js'; const getRating = ( value: number, thresholds: MetricThresholds -): MetricRating => { +): Metric['rating'] => { if (value > thresholds[1]) { return 'poor'; } diff --git a/src/types/base.ts b/src/types/base.ts index 4c0a97b6..6550c133 100644 --- a/src/types/base.ts +++ b/src/types/base.ts @@ -19,12 +19,6 @@ import { NavigationTimingPolyfillEntry, } from './polyfills.js'; -/** - * A rating indicating if a metric's value is within its "good", "needs - * improvement", or "poor" thresholds. - */ -export type MetricRating = 'good' | 'needs-improvement' | 'poor'; - /** * The ranges defining a metric's "good", "needs improvement", and "poor" * thresholds: @@ -50,7 +44,7 @@ export interface Metric { * The rating as to whether the metric value is within the "good", * "needs improvement", or "poor" thresholds of the metric. */ - rating: MetricRating; + rating: 'good' | 'needs-improvement' | 'poor'; /** * The delta between the current value and the last-reported value.