Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

657 B
Raw Blame
export const documentFormats = ["json", "markdown", "mdx"] as const;
export type DocumentFormat = (typeof documentFormats)[number];

export const isDocumentFormat = (value: unknown): value is DocumentFormat =>
  typeof value === "string" &&
  documentFormats.includes(value as DocumentFormat);

export const getDocumentFormatByContentType = (
  contentType: string
): DocumentFormat | undefined => {
  const mimeType = contentType.split(";", 1)[0].trim().toLowerCase();
  if (mimeType === "application/json") {
    return "json";
  }
  if (mimeType === "text/markdown") {
    return "markdown";
  }
  if (mimeType === "text/mdx") {
    return "mdx";
  }
};