36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
|
|
import type { ApplicationCoincidence } from "../../common";
|
||
|
|
|
||
|
|
/** D07: conserva tildes, puntuación, números y ediciones; no aplica la normalización amplia de búsqueda. */
|
||
|
|
export function normalizeApplicationIdentityText(value: string): string {
|
||
|
|
return value.normalize("NFC").trim().replace(/\s+/gu, " ").toLowerCase();
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Señal de revisión exclusivamente: ni el nombre ni el proveedor demuestran identidad de producto. */
|
||
|
|
export function compareApplicationProduct(
|
||
|
|
source: { name: string; provider: string | null },
|
||
|
|
candidate: ApplicationCoincidence["candidate"]
|
||
|
|
): ApplicationCoincidence | undefined {
|
||
|
|
const name = normalizeApplicationIdentityText(source.name);
|
||
|
|
|
||
|
|
if (!name || name !== normalizeApplicationIdentityText(candidate.name)) {
|
||
|
|
return undefined;
|
||
|
|
}
|
||
|
|
const own = normalizeApplicationIdentityText(source.provider ?? "");
|
||
|
|
const other = normalizeApplicationIdentityText(candidate.provider ?? "");
|
||
|
|
|
||
|
|
if (own && other && own !== other) {
|
||
|
|
return undefined;
|
||
|
|
}
|
||
|
|
const strong = Boolean(own && other);
|
||
|
|
|
||
|
|
return {
|
||
|
|
candidate,
|
||
|
|
classification: strong ? "name-provider" : "name-only",
|
||
|
|
reasons: [
|
||
|
|
"same-normalized-name",
|
||
|
|
strong ? "same-provider" : "provider-missing",
|
||
|
|
...(candidate.active ? [] : ["inactive-global" as const]),
|
||
|
|
],
|
||
|
|
};
|
||
|
|
}
|