-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.ts
29 lines (27 loc) 路 974 Bytes
/
io.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { paramCase } from "@wok/case";
import { format } from "@std/path";
import { convertFromTOML, convertToOPML } from "./convert.ts";
import type { List, Lists } from "@5ouma/opml-generator/types";
export async function readTOML(file: string): Promise<Lists> {
try {
const data: string = await Deno.readTextFile(file);
return convertFromTOML(data);
} catch (error) {
if (error instanceof Deno.errors.NotFound) {
throw new Error(`file not found: "${file}"`);
} else if (error instanceof Deno.errors.PermissionDenied) {
throw new Error(`permission denied: "${file}"`);
} else throw error;
}
}
export async function writeXML(feeds: Lists, dir: string): Promise<void> {
await Deno.mkdir(dir, { recursive: true });
feeds.lists.map(async (list: List) => {
const file: string = format({
dir: dir,
name: paramCase(list.name),
ext: ".xml",
});
await Deno.writeTextFile(file, convertToOPML(list));
});
}