// BENCH-HIDDEN — эталонное решение задачи 2. import { esc, html, json, page } from "./lib/http.mjs"; import { collection } from "./lib/store.mjs"; const signups = collection("signups"); export function normalizePhone(raw) { let d = String(raw ?? "").replace(/[\s()-]/g, ""); if (/^8\d{10}$/.test(d)) d = `+7${d.slice(1)}`; return /^\+7\d{10}$/.test(d) ? d : null; } export function validate(b) { const errors = {}; const name = String(b.childName ?? "").trim(); if (name.length < 2 || name.length > 50) errors.childName = "Укажите имя ребёнка: от 2 до 50 букв."; const phone = normalizePhone(b.phone); if (!phone) errors.phone = "Укажите номер в виде +7 и 10 цифр."; const age = Number(b.age); if (!Number.isInteger(age) || age < 6 || age > 14) errors.age = "Мы принимаем детей от 6 до 14 лет."; return { errors, value: { childName: name, phone, age } }; } const form = `
Спасибо! Мы позвоним вам в течение дня
`; export const routes = [ { method: "GET", path: "/healthz", handler: ({ res }) => res.writeHead(200).end("ok") }, { method: "GET", path: "/", handler: ({ res }) => html(res, page("Робостарт", '| ${esc(s.childName)} | ${esc(s.phone)} | ${s.age} |