Download src/converters/dasel.ts from linuxrun/convert: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/linuxrun/convert/resolve/main/src/converters/dasel.ts
- Command line
-
hf download hf://spaces/linuxrun/convert/src/converters/dasel.ts
-
curl -L -o dasel.ts https://huggingface.co/spaces/linuxrun/convert/resolve/main/src/converters/dasel.ts
1.13 kB
| import fs from "fs"; | |
| import { execFile as execFileOriginal } from "node:child_process"; | |
| import { ExecFileFn } from "./types"; | |
| export const properties = { | |
| from: { | |
| document: ["yaml", "toml", "json", "xml", "csv"], | |
| }, | |
| to: { | |
| document: ["yaml", "toml", "json", "csv"], | |
| }, | |
| }; | |
| export async function convert( | |
| filePath: string, | |
| fileType: string, | |
| convertTo: string, | |
| targetPath: string, | |
| options?: unknown, | |
| execFile: ExecFileFn = execFileOriginal, // to make it mockable | |
| ): Promise<string> { | |
| const args: string[] = []; | |
| args.push("--file", filePath); | |
| args.push("--read", fileType); | |
| args.push("--write", convertTo); | |
| return new Promise((resolve, reject) => { | |
| execFile("dasel", args, (error, stdout, stderr) => { | |
| if (error) { | |
| reject(`error: ${error}`); | |
| return; | |
| } | |
| if (stderr) { | |
| console.error(`stderr: ${stderr}`); | |
| } | |
| fs.writeFile(targetPath, stdout, (err: NodeJS.ErrnoException | null) => { | |
| if (err) { | |
| reject(`Failed to write output: ${err}`); | |
| } else { | |
| resolve("Done"); | |
| } | |
| }); | |
| }); | |
| }); | |
| } | |