Skip to content

Commit

Permalink
feat: ✨ add addresses and links
Browse files Browse the repository at this point in the history
  • Loading branch information
gouz committed Apr 18, 2024
1 parent 89c5ec6 commit 4f35a8d
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ Options:
-c, --with-categories view categories (default: false)
-f, --with-formats view formats (default: false)
-e, --with-companies view speakers company (default: false)
-a, --with-addresses view speakers address (default: false)
-l, --with-languages view talks language (default: false)
-t, --titlelength <int> the title length (default: 100)
-w, --links <eventId> view links
-x, --export <file> export into tsv file
-h, --help display help for command
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "choc",
"version": "0.1.3",
"version": "0.1.4",
"module": "src/index.ts",
"type": "module",
"devDependencies": {
Expand Down
41 changes: 40 additions & 1 deletion src/DTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ export const DTO = (
): TalkRow[] =>
talks.flatMap(
(
{ title, speakers, formats, categories, rating, loves, hates, language },
{
id,
title,
speakers,
formats,
categories,
rating,
loves,
hates,
language,
},
position: number
) => {
const lines: TalkRow[] = [];
Expand All @@ -24,6 +34,11 @@ export const DTO = (
addCompanies = {
company: speakerHash.get(uid)?.company,
};
let addAddresses = {};
if (options.withAddresses)
addAddresses = {
addresses: speakerHash.get(uid)?.address,
};
if (i === 0) {
const line = {
position: position + 1,
Expand All @@ -44,22 +59,31 @@ export const DTO = (
addLanguages = {
language: language,
};
let addLink = {};
if (options.links) {
addLink = {
link: `https://conference-hall.io/organizer/event/${options.links}/proposals/${id}`,
};
}
lines.push({
...line,
...addFormats,
...addCategories,
speakers: speakerHash.get(uid)?.name,
...addCompanies,
...addAddresses,
...addLanguages,
rating: Number(Number(rating ?? "0").toFixed(2)),
loves,
hates,
...addLink,
});
} else
lines.push({
title: titleSplit.shift() ?? "",
speakers: speakerHash.get(uid)?.name,
...addCompanies,
...addAddresses,
});
});
titleSplit.forEach((title) => lines.push({ title }));
Expand Down Expand Up @@ -106,6 +130,19 @@ export const DTOExport = (
.map((uid: string) => speakerHash.get(uid)?.company)
.join(", "),
};
let addAddresses = {};
if (options.withAddresses)
addAddresses = {
address: speakers
.map((uid: string) => speakerHash.get(uid)?.address)
.join(", "),
};
let addLink = {};
if (options.links) {
addLink = {
link: `https://conference-hall.io/organizer/event/${options.links}/proposals/${id}`,
};
}
return {
...line,
...addFormats,
Expand All @@ -114,10 +151,12 @@ export const DTOExport = (
.map((uid: string) => speakerHash.get(uid)?.name)
.join(", "),
...addCompanies,
...addAddresses,
...addLanguages,
rating: Number(Number(rating ?? "0").toFixed(2)),
loves,
hates,
...addLink,
};
}
);
3 changes: 2 additions & 1 deletion src/choc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ const choc = async (file: string, options: Options) => {
formatsHash.set(id, removeEmojis(name));
});
const speakerHash = new Map<string, SpeakerData>();
(speakers as Speaker[]).forEach(({ uid, displayName, company }) => {
(speakers as Speaker[]).forEach(({ uid, displayName, company, address }) => {
speakerHash.set(uid, {
name: removeEmojis(displayName),
company: removeEmojis(company ?? ""),
address: removeEmojis(address?.formattedAddress ?? ""),
});
});
const categoriesHash = new Map<string, string>();
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ program
.option("-c, --with-categories", "view categories", false)
.option("-f, --with-formats", "view formats", false)
.option("-e, --with-companies", "view speakers company", false)
.option("-a, --with-addresses", "view speakers address", false)
.option("-l, --with-languages", "view talks language", false)
.option("-t, --titlelength <int>", "the title length", myParseInt, 100)
.option("-w, --links <eventId>", "view links")
.option("-x, --export <file>", "export into tsv file")
.action(choc);

Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ export type Speaker = {
uid: string;
displayName: string;
company: string;
address: Address;
};

export type SpeakerData = {
name: string;
company: string;
address: string;
};

export type Address {
formattedAddress: string;
}

export type Talk = {
id: string;
title: string;
speakers: string[];
formats: string;
Expand All @@ -41,6 +48,8 @@ export type Options = {
withCompanies: boolean;
withFormats: boolean;
withLanguages: boolean;
withAddresses: boolean;
titlelength: number;
links: string;
export?: string;
};

0 comments on commit 4f35a8d

Please sign in to comment.