Skip to content

Commit

Permalink
feat: ✨ add categories
Browse files Browse the repository at this point in the history
  • Loading branch information
gouz committed Apr 17, 2024
1 parent 215d20f commit d1a87ca
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ type TalkRow = {
position?: number;
title?: string;
format?: string;
categories?: string;
speakers?: string;
rating?: number;
loves?: number;
Expand All @@ -22,6 +23,7 @@ type Talk = {
title: string;
speakers: string[];
formats: string;
categories: string;
rating: number;
loves: number;
hates: number;
Expand All @@ -46,6 +48,10 @@ const splitString = (str: string, n: number): string[] => {
return result;
};

const removeEmojis = (str: string): string => {
return str?.replace(/[^\p{L}\p{N}\p{P}\p{Z}^$\n]/gu, "").trim();
};

const argv = Bun.argv;

if (argv.length > 2) {
Expand All @@ -54,26 +60,30 @@ if (argv.length > 2) {
let titleSize: number = 100;
if (argv.length > 3) titleSize = Number(argv[3]) || 100;

const { talks, speakers, formats } = await Bun.file(file).json();
const { talks, speakers, formats, categories } = await Bun.file(file).json();
const formatsHash = new Map<string, string>();
(formats as Format[]).forEach(({ id, name }) => {
formatsHash.set(id, name);
formatsHash.set(id, removeEmojis(name));
});
const speakerHash = new Map<string, string>();
(speakers as Speaker[]).forEach(({ uid, displayName }) => {
speakerHash.set(uid, displayName);
});
const categoriesHash = new Map<string, string>();
(categories as Format[]).forEach(({ id, name }) => {
categoriesHash.set(id, removeEmojis(name));
});
console.table(
(talks as Talk[])
.sort((a, b) => (a.rating <= b.rating ? 1 : -1))
.flatMap(
(
{ title, speakers, formats, rating, loves, hates },
{ title, speakers, formats, categories, rating, loves, hates },
position: number
) => {
const lines: TalkRow[] = [];
let titleSplit: string[] = splitString(
title.replace(/[^\p{L}\p{N}\p{P}\p{Z}^$\n]/gu, "").trim(),
removeEmojis(title),
titleSize
).map((text) => text.padEnd(titleSize, " "));
speakers.forEach((uid: string, i: number) => {
Expand All @@ -82,6 +92,7 @@ if (argv.length > 2) {
position: position + 1,
title: titleSplit.shift(),
format: formatsHash.get(formats),
categories: categoriesHash.get(categories),
speakers: speakerHash.get(uid),
rating: Number(rating.toFixed(2)),
loves,
Expand Down

0 comments on commit d1a87ca

Please sign in to comment.