-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpostprocess.ts
40 lines (32 loc) · 1.18 KB
/
postprocess.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { readCSV, writeCSV, removeFile } from 'https://deno.land/x/[email protected]/mod.ts'
// replace with latest library as needed: https://deno.land/x/[email protected]/mod.ts
// flat action runs on Deno, a Node competitor. Flat will pass in the downloaded filename as arg 0.
const filePath: string = Deno.args[0]
// Lazyquotes lets readCSV handle values containing line-endings inside quoted strings.
const tribalLeaders: Record<string, any> = await readCSV(filePath, {lazyQuotes: true})
// custom compare function
function compare( a, b ) {
if ( a["Tribe Full Name"] < b["Tribe Full Name"] ){
return -1;
}
if ( a['Tribe Full Name'] > b['Tribe Full Name'] ){
return 1;
}
return 0;
}
// process each line
tribalLeaders.forEach(object => {
// remove OBJECTID
delete object['OBJECTID'];
delete object['GlobalID'];
//strip newlines from all but the last element
for(const property in object) {
if(property === 'y') {
break;
}
object[property] = object[property].replace(/\r?\n|\r/g, '');
}
})
// sort using custom compare function
tribalLeaders.sort(compare)
await writeCSV('./tribal-leaders.csv', tribalLeaders)