-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrom.ts
36 lines (30 loc) · 1.26 KB
/
from.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
30
31
32
33
34
35
36
import { readLines } from "./deps.ts";
import { parseDsv, parseJson } from "./transform.ts";
import { pipe, PipeFunction } from "./pipe.ts";
export const fromFile = async (path: string, funcs: PipeFunction[] = []) => {
const file = await Deno.open(path, { read: true, write: false });
return pipe(funcs, file.rid)(readLines(file));
};
export const fromStdin = (funcs: PipeFunction[] = []) =>
pipe(funcs)(readLines(Deno.stdin));
export const fromNdjsonFile = async (
path: string,
funcs: PipeFunction[] = [],
) => {
const file = await Deno.open(path, { read: true, write: false });
return pipe([parseJson, ...funcs], file.rid)(readLines(file));
};
export const fromNdjsonStdin = (funcs: PipeFunction[] = []) =>
pipe([parseJson, ...funcs])(readLines(Deno.stdin));
export const fromDsvFile = async (
path: string,
config: { delimiter?: string; numeric?: string[]; bool?: string[] } = {},
funcs: PipeFunction[] = [],
) => {
const file = await Deno.open(path, { read: true, write: false });
return pipe([parseDsv(config), ...funcs], file.rid)(readLines(file));
};
export const fromDsvStdin = (
config: { delimiter?: string; numeric?: string[]; bool?: string[] } = {},
funcs: PipeFunction[] = [],
) => pipe([parseDsv(config), ...funcs])(readLines(Deno.stdin));