refactor: centralize isPlainObject, isRecord, isErrno, isLoopbackHost utilities (#12926)

This commit is contained in:
max
2026-02-09 17:02:55 -08:00
committed by GitHub
parent 70f9edeec7
commit 8d75a496bf
37 changed files with 97 additions and 226 deletions

View File

@@ -1,3 +1,5 @@
import { isLoopbackHost } from "../gateway/net.js";
type HostSource = string | null | undefined;
type CanvasHostUrlParams = {
@@ -9,23 +11,6 @@ type CanvasHostUrlParams = {
scheme?: "http" | "https";
};
const isLoopbackHost = (value: string) => {
const normalized = value.trim().toLowerCase();
if (!normalized) {
return false;
}
if (normalized === "localhost") {
return true;
}
if (normalized === "::1") {
return true;
}
if (normalized === "0.0.0.0" || normalized === "::") {
return true;
}
return normalized.startsWith("127.");
};
const normalizeHost = (value: HostSource, rejectLoopback: boolean) => {
if (!value) {
return "";