MCPcopy
hub / github.com/NUKnightLab/TimelineJS3 / extractEventFromCSVObject

Function extractEventFromCSVObject

src/js/core/ConfigFactory.js:62–141  ·  view source on GitHub ↗
(orig_row)

Source from the content-addressed store, hash-verified

60}
61
62function extractEventFromCSVObject(orig_row) {
63
64 let row = {}
65 Object.keys(orig_row).forEach(k => {
66 row[k] = trim(orig_row[k]) // get rid of white-space and reduce all-blank cells to empty strings
67 })
68
69 var d = {
70 media: {
71 caption: row['Media Caption'] || '',
72 credit: row['Media Credit'] || '',
73 url: row['Media'] || '',
74 thumbnail: row['Media Thumbnail'] || '',
75 alt: row['Alt Text'] || ''
76 },
77 text: {
78 headline: row['Headline'] || '',
79 text: row['Text'] || ''
80 },
81 display_date: row['Display Date'] || '', // only in v3 but no problem
82 group: row['Group'] || row['Tag'] || '', // small diff between v1 and v3 sheets
83 background: interpretBackground(row['Background']), // only in v3 but no problem
84 type: row['Type'] || ''
85 }
86
87 if (Object.keys(row).includes('Start Date') || Object.keys(row).includes('End Date')) {
88 // V1 date handling
89 if (row['Start Date']) {
90 d.start_date = parseDate(row['Start Date'])
91 }
92 if (row['End Date']) {
93 d.end_date = parseDate(row['End Date'])
94 }
95 } else {
96 // V3 date handling
97 // every date must have at least a year to be valid.
98 if (row['Year']) {
99 d.start_date = {
100 year: clean_integer(row['Year']),
101 month: clean_integer(row['Month']) || '',
102 day: clean_integer(row['Day']) || ''
103 }
104 }
105 if (row['End Year']) {
106 d.end_date = {
107 year: clean_integer(row['End Year']) || '',
108 month: clean_integer(row['End Month']) || '',
109 day: clean_integer(row['End Day']) || ''
110 }
111 }
112
113 if (row['Time']) {
114 if (d.start_date) {
115 mergeData(d.start_date, parseTime(row['Time']));
116 } else {
117 throw new TLError("invalid_start_time_without_date")
118 }
119 }

Callers 1

processCSVRowsFunction · 0.85

Calls 7

trimFunction · 0.90
parseDateFunction · 0.90
mergeDataFunction · 0.90
parseTimeFunction · 0.90
validDateConfigFunction · 0.90
interpretBackgroundFunction · 0.85
clean_integerFunction · 0.85

Tested by

no test coverage detected