Skip to content

Instantly share code, notes, and snippets.

@kaosf
Last active May 26, 2023 15:26
Show Gist options
  • Save kaosf/ec243d5b177fb40fc53b840c4d995000 to your computer and use it in GitHub Desktop.
Save kaosf/ec243d5b177fb40fc53b840c4d995000 to your computer and use it in GitHub Desktop.
const [keyword, type] = ["大空あかり", "キャラ"];
// const [keyword, type] = ["穏やかじゃない", "セリフ"]
import * as fs from "fs";
import * as path from "path";
import { parse } from "csv-parse/sync";
const source = path.join(__dirname, "aikatsup20230422.csv");
const buffer = fs.readFileSync(source);
const rows = parse(buffer, { relax_column_count: true }) as string[][];
let ids: string[] = [];
switch (type) {
case "キャラ":
ids = rows
.filter((row) =>
row.slice(4, row.length).find((column) => column === keyword)
)
.map((row) => row[0]);
break;
case "セリフ":
const r = new RegExp(keyword);
ids = rows.filter((row) => r.test(row[1])).map((row) => row[0]);
break;
default:
process.exit(1);
}
console.log(ids);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment