Download js/app/src/api_docs/utils.ts from mindmime/gradio: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/mindmime/gradio/resolve/main/js/app/src/api_docs/utils.ts
- Command line
-
hf download hf://spaces/mindmime/gradio/js/app/src/api_docs/utils.ts
-
curl -L -o utils.ts https://huggingface.co/spaces/mindmime/gradio/resolve/main/js/app/src/api_docs/utils.ts
1.15 kB
| // eslint-disable-next-line complexity | |
| export function represent_value( | |
| value: string, | |
| type: string | undefined, | |
| lang: "js" | "py" | null = null | |
| ): string | null | number | boolean | Record<string, unknown> { | |
| if (type === undefined) { | |
| return lang === "py" ? "None" : null; | |
| } | |
| if (type === "string" || type === "str" || type == "filepath") { | |
| return lang === null ? value : '"' + value + '"'; | |
| } else if (type === "number") { | |
| return lang === null ? parseFloat(value) : value; | |
| } else if (type === "boolean" || type == "bool") { | |
| if (lang === "py") { | |
| value = String(value); | |
| return value === "true" ? "True" : "False"; | |
| } else if (lang === "js") { | |
| return value; | |
| } | |
| return value === "true"; | |
| } else if (type === "List[str]") { | |
| value = JSON.stringify(value); | |
| return value; | |
| } else if (type.startsWith("Literal['")) { | |
| // a literal of strings | |
| return '"' + value + '"'; | |
| } | |
| // assume object type | |
| if (lang === null) { | |
| return value === "" ? null : JSON.parse(value); | |
| } else if (typeof value === "string") { | |
| if (value === "") { | |
| return lang === "py" ? "None" : "null"; | |
| } | |
| return value; | |
| } | |
| return JSON.stringify(value); | |
| } | |