Spaces:
Sleeping
Sleeping
Download apps/api/src/lib/format-utils.ts from s-eto-hub/firecrawl-api: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/s-eto-hub/firecrawl-api/resolve/main/apps/api/src/lib/format-utils.ts
- Command line
-
hf download hf://spaces/s-eto-hub/firecrawl-api/apps/api/src/lib/format-utils.ts
-
curl -L -o format-utils.ts https://huggingface.co/spaces/s-eto-hub/firecrawl-api/resolve/main/apps/api/src/lib/format-utils.ts
1.62 kB
| import { FormatObject } from "../controllers/v2/types"; | |
| /** | |
| * Checks if a format of a specific type exists in the formats array. | |
| * Returns the format object if found, undefined otherwise. | |
| * | |
| * This function handles both simple formats (e.g., { type: "markdown" }) | |
| * and complex formats with additional properties (e.g., { type: "screenshot", fullPage: true }). | |
| * | |
| * @param formats - Array of format objects | |
| * @param type - The format type to search for | |
| * @returns The format object if found, undefined otherwise | |
| */ | |
| export function hasFormatOfType<T extends FormatObject["type"]>( | |
| formats: FormatObject[] | undefined, | |
| type: T, | |
| ): Extract<FormatObject, { type: T }> | undefined { | |
| if (!formats) { | |
| return undefined; | |
| } | |
| const found = formats.find(f => f.type === type); | |
| return found as Extract<FormatObject, { type: T }> | undefined; | |
| } | |
| /** | |
| * Checks if a format of a specific type exists in a formats array. | |
| * Works with both v1-style string arrays and v2-style object arrays. | |
| * | |
| * @param formats - Array of format strings or objects | |
| * @param type - The format type to check for | |
| * @returns true if the format exists, false otherwise | |
| * | |
| * @example | |
| * // v2 style (object array) | |
| * includesFormat([{ type: "markdown" }, { type: "html" }], "markdown") // true | |
| * | |
| * // v1 style (string array) | |
| * includesFormat(["markdown", "html"], "markdown") // true | |
| */ | |
| export function includesFormat( | |
| formats: (string | FormatObject)[] | undefined, | |
| type: string, | |
| ): boolean { | |
| if (!formats) { | |
| return false; | |
| } | |
| return formats.some(f => | |
| typeof f === "string" ? f === type : f.type === type, | |
| ); | |
| } | |