mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-08-03 19:17:07 -04:00
21 lines
599 B
TypeScript
21 lines
599 B
TypeScript
import fs from 'node:fs/promises';
|
|
|
|
import Papa from 'papaparse';
|
|
import Suml from 'suml';
|
|
|
|
import { rootDir } from './paths.ts';
|
|
|
|
export const loadSuml = async <T = unknown>(path: string): Promise<T> => {
|
|
return new Suml().parse(await fs.readFile(`${rootDir}/${path}`, 'utf-8')) as T;
|
|
};
|
|
|
|
export const tsvParseConfig = {
|
|
dynamicTyping: true,
|
|
header: true,
|
|
skipEmptyLines: true,
|
|
delimiter: '\t',
|
|
};
|
|
export const loadTsv = async <T = unknown>(path: string): Promise<T[]> => {
|
|
return Papa.parse(await fs.readFile(`${rootDir}/${path}`, 'utf-8'), tsvParseConfig).data as T[];
|
|
};
|