Initial commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Reverse the word order of a name. "Aiba Reika" → "Reika Aiba".
|
||||
* For single-token names returns null (no useful reverse).
|
||||
*/
|
||||
export function reverseName(name: string): string | null {
|
||||
const tokens = name.trim().split(/\s+/).filter(Boolean);
|
||||
if (tokens.length < 2) return null;
|
||||
return tokens.slice().reverse().join(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the displayed alt-name list for an actress: always lead with the
|
||||
* word-order-reversed name (auto-generated, user can't remove), then any
|
||||
* user-typed alt names from the comma-separated `altNames` field, deduped
|
||||
* and excluding the actress's own canonical name.
|
||||
*/
|
||||
export function buildAltNameChips(name: string, altNamesField: string | null): Array<{ value: string; auto: boolean }> {
|
||||
const out: Array<{ value: string; auto: boolean }> = [];
|
||||
const seen = new Set<string>([name.trim().toLowerCase()]);
|
||||
|
||||
const reversed = reverseName(name);
|
||||
if (reversed && !seen.has(reversed.toLowerCase())) {
|
||||
out.push({ value: reversed, auto: true });
|
||||
seen.add(reversed.toLowerCase());
|
||||
}
|
||||
|
||||
if (altNamesField) {
|
||||
for (const raw of altNamesField.split(/[,、,]/)) {
|
||||
const v = raw.trim();
|
||||
if (!v) continue;
|
||||
const k = v.toLowerCase();
|
||||
if (seen.has(k)) continue;
|
||||
seen.add(k);
|
||||
out.push({ value: v, auto: false });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Reference in New Issue
Block a user