Skip to content

Commit

Permalink
Refine rendering of CSV values
Browse files Browse the repository at this point in the history
Undefined values, empty strings or numbers will not be quoted any more.
  • Loading branch information
cmil committed Sep 27, 2024
1 parent d4fdcc7 commit 89d1101
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions yml2csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const lines = data.map((p: Play) => {
const num = countCharactersByGender(p);
const locationId = p.settings?.find((s) => s.location?.wikidataId)?.location
.wikidataId;
const yearPremiered = premiered ? parseInt(`${premiered}`) : undefined;
const play: {[index: string]: string | number | undefined} = {
id,
link: `https://einakter.dracor.org/${slug}`,
Expand All @@ -80,13 +81,13 @@ const lines = data.map((p: Play) => {
authorPseudonym,
authorWikidataID,
basedOn: basedOn ? 'true' : 'false',
earliestYear: getEarliestYear(p)?.toString(),
earliestYear: getEarliestYear(p),
yearNormalized: normalizeYear(p),
yearWritten,
yearPrinted,
yearPremiered: premiered ? `${premiered}`.split('-')[0] : '',
formalia: formalia?.join('\n') || '',
keywords: keywords?.join('\n') || '',
yearPremiered,
formalia: formalia?.join('\n'),
keywords: keywords?.join('\n'),
wikidataID: ids?.wikidata
? `http://wikidata.org/entity/${ids.wikidata}`
: '',
Expand All @@ -101,7 +102,13 @@ const lines = data.map((p: Play) => {
};
const line = cols
.map((col) => {
return `"${`${play[col]}`.replace(/"/g, '""')}"`;
const value = play[col];
if (value === undefined || value === '') {
return '';
} else if (typeof value === 'number') {
return value;
}
return `"${`${value}`.replace(/"/g, '""')}"`;
})
.join(',');
return line;
Expand Down

0 comments on commit 89d1101

Please sign in to comment.