11 lines
450 B
TypeScript
11 lines
450 B
TypeScript
/**
|
|
* Парсит id сервера из БД (положительное целое).
|
|
* Не извлекает цифры из строк вроде «srv1» — только целая строка из цифр.
|
|
*/
|
|
export function parseDbServerId(raw: unknown): number | null {
|
|
const s = String(raw ?? "").trim()
|
|
if (!/^\d+$/.test(s)) return null
|
|
const n = Number.parseInt(s, 10)
|
|
return Number.isSafeInteger(n) && n >= 1 ? n : null
|
|
}
|