adf0d17497
publish / version_or_publish (push) Has been cancelled
storybook-build / changes (push) Has been cancelled
storybook-build / :storybook-build (push) Has been cancelled
Sync Gradio Skills to Hugging Face / sync-skills (push) Has been cancelled
functional / changes (push) Has been cancelled
functional / build-frontend (push) Has been cancelled
functional / functional-test-SSR=false (push) Has been cancelled
functional / functional-reload (push) Has been cancelled
js / changes (push) Has been cancelled
js / js-test (push) Has been cancelled
docs-build / changes (push) Has been cancelled
docs-build / docs-build (push) Has been cancelled
docs-build / website-build (push) Has been cancelled
functional / functional-test-SSR=true (push) Has been cancelled
hygiene / hygiene-test (push) Has been cancelled
python / changes (push) Has been cancelled
python / build (push) Has been cancelled
python / test-ubuntu-latest-flaky (push) Has been cancelled
python / test-ubuntu-latest-not-flaky (push) Has been cancelled
python / test-windows-latest-flaky (push) Has been cancelled
python / test-windows-latest-not-flaky (push) Has been cancelled
59 lines
1.2 KiB
TypeScript
59 lines
1.2 KiB
TypeScript
import type { CellValue } from "../types";
|
|
|
|
export type Headers = string[];
|
|
export type Data = CellValue[][];
|
|
|
|
export type Datatype =
|
|
| "str"
|
|
| "number"
|
|
| "bool"
|
|
| "date"
|
|
| "markdown"
|
|
| "html"
|
|
| "image";
|
|
|
|
export type Metadata = {
|
|
[key: string]: string[][] | null;
|
|
} | null;
|
|
export type HeadersWithIDs = { value: string; id: string }[];
|
|
export type DataframeValue = {
|
|
data: Data;
|
|
headers: Headers;
|
|
metadata?: Metadata;
|
|
};
|
|
|
|
/**
|
|
* Coerce a value to a given type.
|
|
* @param v - The value to coerce.
|
|
* @param t - The type to coerce to.
|
|
* @returns The coerced value.
|
|
*/
|
|
export function cast_value_to_type(v: any, t: Datatype): CellValue {
|
|
if (v === null || v === undefined) {
|
|
return v;
|
|
}
|
|
if (t === "number") {
|
|
const n = Number(v);
|
|
return isNaN(n) ? v : n;
|
|
}
|
|
if (t === "bool") {
|
|
if (typeof v === "boolean") return v;
|
|
if (typeof v === "number") return v !== 0;
|
|
const s = String(v).toLowerCase();
|
|
if (s === "true" || s === "1") return true;
|
|
if (s === "false" || s === "0") return false;
|
|
return v;
|
|
}
|
|
if (t === "date") {
|
|
const d = new Date(v);
|
|
return isNaN(d.getTime()) ? v : d.toISOString();
|
|
}
|
|
return v;
|
|
}
|
|
|
|
export interface EditData {
|
|
index: number | [number, number];
|
|
value: string;
|
|
previous_value: string;
|
|
}
|