46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
export function normalizePublicCodeText(value: string) {
|
|
return value
|
|
.trim()
|
|
.replace(/[^a-zA-Z0-9]/gu, '')
|
|
.toUpperCase();
|
|
}
|
|
|
|
export function buildPuzzlePublicWorkCode(profileId: string) {
|
|
const normalized = normalizePublicCodeText(profileId);
|
|
const fallback = normalized || '00000000';
|
|
const suffix = fallback.slice(-8).padStart(8, '0');
|
|
|
|
return `PZ-${suffix}`;
|
|
}
|
|
|
|
export function buildBigFishPublicWorkCode(sessionId: string) {
|
|
const normalized = normalizePublicCodeText(sessionId);
|
|
const fallback = normalized || '00000000';
|
|
const suffix = fallback.slice(-8).padStart(8, '0');
|
|
|
|
return `BF-${suffix}`;
|
|
}
|
|
|
|
export function isSamePuzzlePublicWorkCode(keyword: string, profileId: string) {
|
|
const normalizedKeyword = normalizePublicCodeText(keyword);
|
|
|
|
return (
|
|
normalizedKeyword ===
|
|
normalizePublicCodeText(buildPuzzlePublicWorkCode(profileId)) ||
|
|
normalizedKeyword === normalizePublicCodeText(profileId)
|
|
);
|
|
}
|
|
|
|
export function isSameBigFishPublicWorkCode(
|
|
keyword: string,
|
|
sessionId: string,
|
|
) {
|
|
const normalizedKeyword = normalizePublicCodeText(keyword);
|
|
|
|
return (
|
|
normalizedKeyword ===
|
|
normalizePublicCodeText(buildBigFishPublicWorkCode(sessionId)) ||
|
|
normalizedKeyword === normalizePublicCodeText(sessionId)
|
|
);
|
|
}
|