This commit is contained in:
dahyeon committed 2026-04-25 11:49:21 -07:00
1 parent 5af2c80cd1
commit f7ee34da4f
78 files changed
+9016 -150

No files matched your search

@@ -0,0 +1,87 @@
import { Position } from '../../global/database/schema';
const POSITION_ALIASES: Record<string, Position> = {
// TOP
top: 'TOP',
탑: 'TOP',
top레인: 'TOP',
// JUNGLE
jgl: 'JGL',
jungle: 'JGL',
jng: 'JGL',
jg: 'JGL',
정글: 'JGL',
정글러: 'JGL',
// MID
mid: 'MID',
middle: 'MID',
미드: 'MID',
// ADC (BOTTOM)
adc: 'ADC',
ad: 'ADC',
bot: 'ADC',
bottom: 'ADC',
원딜: 'ADC',
바텀: 'ADC',
// SUP
sup: 'SUP',
supp: 'SUP',
support: 'SUP',
서폿: 'SUP',
서포터: 'SUP',
};
export interface ParsedPositions {
positions: Position[];
}
export class PositionParseError extends Error {
constructor(
public readonly reason:
| 'too_few'
| 'too_many'
| 'duplicate'
| 'unknown'
| 'empty',
public readonly token?: string,
) {
super(`Position parse error: ${reason}${token ? ` (${token})` : ''}`);
}
}
export function parsePositionList(input: string): ParsedPositions {
const trimmed = input.trim();
if (trimmed.length === 0) {
throw new PositionParseError('empty');
}
const tokens = trimmed
.split(',')
.map((t) => t.trim())
.filter((t) => t.length > 0);
if (tokens.length < 2) {
throw new PositionParseError('too_few');
}
if (tokens.length > 5) {
throw new PositionParseError('too_many');
}
const positions: Position[] = [];
const seen = new Set<Position>();
for (const token of tokens) {
const key = token.toLowerCase().replace(/\s+/g, '');
const mapped = POSITION_ALIASES[key];
if (!mapped) {
throw new PositionParseError('unknown', token);
}
if (seen.has(mapped)) {
throw new PositionParseError('duplicate', token);
}
seen.add(mapped);
positions.push(mapped);
}
return { positions };
}