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 buildMatch3DPublicWorkCode(profileId: string) { const normalized = normalizePublicCodeText(profileId); const fallback = normalized || '00000000'; const suffix = fallback.slice(-8).padStart(8, '0'); return `M3-${suffix}`; } export function buildSquareHolePublicWorkCode(profileId: string) { const normalized = normalizePublicCodeText(profileId); const fallback = normalized || '00000000'; const suffix = fallback.slice(-8).padStart(8, '0'); return `SH-${suffix}`; } export function buildVisualNovelPublicWorkCode(profileId: string) { const normalized = normalizePublicCodeText(profileId); const fallback = normalized || '00000000'; const suffix = fallback.slice(-8).padStart(8, '0'); return `VN-${suffix}`; } export function buildBabyObjectMatchPublicWorkCode(profileId: string) { const normalized = normalizePublicCodeText(profileId); const fallback = normalized || '00000000'; const suffix = fallback.slice(-8).padStart(8, '0'); return `BO-${suffix}`; } function normalizeCustomWorldPublicWorkCodeSuffix(profileId: string) { const digits = profileId .split('') .filter((character) => character >= '0' && character <= '9') .join(''); if (digits.length === 0) { const bytes = new TextEncoder().encode(profileId); const checksum = bytes.reduce((accumulator, value) => { return (accumulator * 131 + value) >>> 0; }, 0); return String(checksum % 100_000_000).padStart(8, '0'); } return digits.slice(-8).padStart(8, '0'); } export function buildCustomWorldPublicWorkCode(profileId: string) { return `CW-${normalizeCustomWorldPublicWorkCodeSuffix(profileId)}`; } function normalizeBarkBattlePublicWorkCodeSuffix(workId: string) { const normalized = normalizePublicCodeText(workId); const withoutPrefix = normalized.startsWith('BB') ? normalized.slice(2) : normalized; const fallback = withoutPrefix || normalized || '00000000'; return fallback.slice(-8).padStart(8, '0'); } export function buildBarkBattlePublicWorkCode(workId: string) { return `BB-${normalizeBarkBattlePublicWorkCodeSuffix(workId)}`; } export function buildJumpHopPublicWorkCode(profileId: string) { const normalized = normalizePublicCodeText(profileId); const fallback = normalized || '00000000'; const suffix = fallback.slice(-8).padStart(8, '0'); return `JH-${suffix}`; } export function buildWoodenFishPublicWorkCode(profileId: string) { const normalized = normalizePublicCodeText(profileId); const fallback = normalized || '00000000'; const suffix = fallback.slice(-8).padStart(8, '0'); return `WF-${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) ); } export function isSameMatch3DPublicWorkCode(keyword: string, profileId: string) { const normalizedKeyword = normalizePublicCodeText(keyword); return ( normalizedKeyword === normalizePublicCodeText(buildMatch3DPublicWorkCode(profileId)) || normalizedKeyword === normalizePublicCodeText(profileId) ); } export function isSameSquareHolePublicWorkCode( keyword: string, profileId: string, ) { const normalizedKeyword = normalizePublicCodeText(keyword); return ( normalizedKeyword === normalizePublicCodeText(buildSquareHolePublicWorkCode(profileId)) || normalizedKeyword === normalizePublicCodeText(profileId) ); } export function isSameVisualNovelPublicWorkCode( keyword: string, profileId: string, ) { const normalizedKeyword = normalizePublicCodeText(keyword); return ( normalizedKeyword === normalizePublicCodeText(buildVisualNovelPublicWorkCode(profileId)) || normalizedKeyword === normalizePublicCodeText(profileId) ); } export function isSameBabyObjectMatchPublicWorkCode( keyword: string, profileId: string, ) { const normalizedKeyword = normalizePublicCodeText(keyword); return ( normalizedKeyword === normalizePublicCodeText(buildBabyObjectMatchPublicWorkCode(profileId)) || normalizedKeyword === normalizePublicCodeText(profileId) ); } export function isSameCustomWorldPublicWorkCode( keyword: string, profileId: string, ) { const normalizedKeyword = normalizePublicCodeText(keyword); return ( normalizedKeyword === normalizePublicCodeText(buildCustomWorldPublicWorkCode(profileId)) || normalizedKeyword === normalizePublicCodeText(profileId) ); } export function isSameBarkBattlePublicWorkCode(keyword: string, workId: string) { const normalizedKeyword = normalizePublicCodeText(keyword); return ( normalizedKeyword === normalizePublicCodeText(buildBarkBattlePublicWorkCode(workId)) || normalizedKeyword === normalizePublicCodeText(workId) || normalizedKeyword === normalizeBarkBattlePublicWorkCodeSuffix(workId) ); } export function isSameJumpHopPublicWorkCode(keyword: string, profileId: string) { const normalizedKeyword = normalizePublicCodeText(keyword); return ( normalizedKeyword === normalizePublicCodeText(buildJumpHopPublicWorkCode(profileId)) || normalizedKeyword === normalizePublicCodeText(profileId) ); } export function isSameWoodenFishPublicWorkCode( keyword: string, profileId: string, ) { const normalizedKeyword = normalizePublicCodeText(keyword); return ( normalizedKeyword === normalizePublicCodeText(buildWoodenFishPublicWorkCode(profileId)) || normalizedKeyword === normalizePublicCodeText(profileId) ); }