star-chart-search-enhancer/src/shared/normalize-rate-label.ts

29 lines
644 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { AfterSearchRateField } from "./result-types";
function normalizeText(value: string): string {
return value
.trim()
.replace(/\s+/g, "")
.replace(/[:,。.()\-]/g, "")
.toLowerCase();
}
export function normalizeRateLabel(
label: string
): AfterSearchRateField | null {
const normalized = normalizeText(label);
if (normalized.includes("个人视频看后搜率")) {
return "personalVideoAfterSearchRate";
}
if (
normalized.includes("单条视频看后搜率") ||
normalized.includes("单视频看后搜率")
) {
return "singleVideoAfterSearchRate";
}
return null;
}