mirror of
https://github.com/jason5ng32/MyIP.git
synced 2026-11-04 08:55:47 +00:00
common/ had become the backend's library: 30 of its 41 modules were imported by nothing in the frontend, so the name no longer said what belonged there. It now holds only what the frontend or the build imports too; backend-only code moved to server/, flat except for datasets/ (the dataset engine and its readers). The *-db/ dataset directories stay in common/: self-hosting docs and Docker volumes mount those paths. frontend/utils/ keeps its app-wide modules at the root and gains ip/ (IP / ASN shaping and validation), report/ (the report pipeline) and features/ (the pure layer of a single feature). Paths only — no logic changes. The Dockerfile copies server/, and the AGENTS.md files say where a new module goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
19 lines
899 B
JavaScript
19 lines
899 B
JavaScript
// The AS-number grammar shared by the ASN guards (server/guards.js) and the
|
|
// tools that take a typed AS number (Whois, ASN Profile — via the
|
|
// frontend/utils/asn-input.js bridge): up to ten digits, AS1 … AS4294967295,
|
|
// `AS` prefix case-insensitive.
|
|
|
|
export const MAX_ASN = 4294967295;
|
|
|
|
// → the ASN as a number (leading zeros dropped), or null. Surrounding spaces
|
|
// are ignored; `requirePrefix` rejects a bare number (the Whois box, where
|
|
// digits alone are not an AS query).
|
|
export const parseAsnInput = (raw, { requirePrefix = false } = {}) => {
|
|
if (typeof raw !== 'string' && typeof raw !== 'number') return null;
|
|
const pattern = requirePrefix ? /^AS(\d+)$/i : /^(?:AS)?(\d+)$/i;
|
|
const match = pattern.exec(String(raw).trim());
|
|
if (!match || match[1].length > 10) return null;
|
|
const asn = Number(match[1]);
|
|
return asn >= 1 && asn <= MAX_ASN ? asn : null;
|
|
};
|