This commit is contained in:
24
src/services/publicWorkCode.ts
Normal file
24
src/services/publicWorkCode.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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 isSamePuzzlePublicWorkCode(keyword: string, profileId: string) {
|
||||
const normalizedKeyword = normalizePublicCodeText(keyword);
|
||||
|
||||
return (
|
||||
normalizedKeyword ===
|
||||
normalizePublicCodeText(buildPuzzlePublicWorkCode(profileId)) ||
|
||||
normalizedKeyword === normalizePublicCodeText(profileId)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user