type RuntimeFormDataCtor = NonNullable<UndiciRuntimeDeps["FormData"]>;
type FormDataEntryValueWithOptionalName = FormDataEntryValue & { name?: string };
function isFormDataLike(value: unknown): value is FormData { return ( typeof value === "object" &&
value !== null && typeof (value as FormData).entries === "function" &&
(value as { [Symbol.toStringTag]?: unknown })[Symbol.toStringTag] === "FormData"
);
}
function normalizeRuntimeFormData(
body: unknown,
RuntimeFormData: RuntimeFormDataCtor | undefined,
): BodyInit | null | undefined { if (!isFormDataLike(body) || typeof RuntimeFormData !== "function") { return body as BodyInit | null | undefined;
} if (body instanceof RuntimeFormData) { return body;
}
const next = new RuntimeFormData(); for (const [key, value] of body.entries()) { const namedValue = value as FormDataEntryValueWithOptionalName; // File.name is the standard filename property; skip empty/whitespace-only values const fileName = typeof namedValue.name === "string" && namedValue.name.trim() ? namedValue.name : undefined; if (fileName) {
next.append(key, value, fileName);
} else {
next.append(key, value);
}
} // undici.FormData is structurally compatible with BodyInit but lives in a separate // type namespace; the cast avoids a cross-implementation assignability error. return next as unknown as BodyInit;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.