New Captcha Package added

This commit is contained in:
2026-07-25 13:38:18 +05:30
parent d0aded0392
commit 8b728a3e5d
157 changed files with 12092 additions and 1913 deletions
+25
View File
@@ -0,0 +1,25 @@
import type { CaptchaChallengeRecord, VerifyCaptchaInput } from "./types.ts";
export function normalizeTextAnswer(value: unknown, caseSensitive: boolean): string {
const normalized = String(value ?? "")
.normalize("NFKC")
.trim()
.replace(/\s+/g, " ");
return caseSensitive ? normalized : normalized.toUpperCase();
}
export function normalizeSelections(values: unknown): string {
if (!Array.isArray(values)) return "";
return [...new Set(values.map((value) => String(value).trim()).filter(Boolean))].sort().join(",");
}
export function normalizedSubmittedAnswer(record: CaptchaChallengeRecord, input: VerifyCaptchaInput): string {
if (record.answerKind === "selections") return normalizeSelections(input.selections);
if (record.answerKind === "invisible") {
return JSON.stringify({
honeypot: String(input.honeypot ?? ""),
timingToken: String(input.timingToken ?? ""),
});
}
return normalizeTextAnswer(input.answer, record.caseSensitive);
}