From d1a87cacdbc07315ce2da6b7975961622fbe00eb Mon Sep 17 00:00:00 2001 From: Sylvain Gougouzian Date: Wed, 17 Apr 2024 18:43:48 +0200 Subject: [PATCH] feat: :sparkles: add categories --- index.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index e044604..c446e56 100644 --- a/index.ts +++ b/index.ts @@ -2,6 +2,7 @@ type TalkRow = { position?: number; title?: string; format?: string; + categories?: string; speakers?: string; rating?: number; loves?: number; @@ -22,6 +23,7 @@ type Talk = { title: string; speakers: string[]; formats: string; + categories: string; rating: number; loves: number; hates: number; @@ -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) { @@ -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(); (formats as Format[]).forEach(({ id, name }) => { - formatsHash.set(id, name); + formatsHash.set(id, removeEmojis(name)); }); const speakerHash = new Map(); (speakers as Speaker[]).forEach(({ uid, displayName }) => { speakerHash.set(uid, displayName); }); + const categoriesHash = new Map(); + (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) => { @@ -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,