Files
Genarrative/src/services/publicWorkCode.ts
五香丸子 df24467e1d
Some checks failed
CI / verify (push) Has been cancelled
Integrate Match3D Q1 flow
2026-05-01 14:33:18 +08:00

64 lines
1.8 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 buildMatch3DPublicWorkCode(profileId: string) {
const normalized = normalizePublicCodeText(profileId);
const fallback = normalized || '00000000';
const suffix = fallback.slice(-8).padStart(8, '0');
return `M3-${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)
);
}