feat(*): Add tsv parser to enable easily loading pokedex data

This commit is contained in:
Josh Creek
2024-07-12 14:14:24 +01:00
parent 7deb4632bc
commit 212f674b44
5 changed files with 28642 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
const fs = require('fs');
const csv = require('csv-parser');
const inputFilePath = 'seed-data.tsv'; // Replace with the path to your TSV file
const outputFilePath = 'pokedex.json';
const results = [];
fs.createReadStream(inputFilePath)
.pipe(csv({ separator: '\t' }))
.on('data', (data) => {
const entry = {
pokedexNumber: parseInt(data['Dex #']),
boxPlacement: {
box: parseInt(data['Home Box']),
row: parseInt(data['Home Row']),
column: parseInt(data['Home Column'])
},
pokemon: data['Pokemon'],
form: data['Form'],
canGigantamax: data['Can Gigantamax'].toLowerCase(),
regionToCatchIn: data['Region'],
gamesToCatchIn: data['Catch In These Games'].split(',').map((game) => game.trim()),
regionToEvolveIn: data['Evolve In Region'],
notes: data['Notes to obtain']
};
results.push(entry);
})
.on('end', () => {
fs.writeFile(outputFilePath, JSON.stringify(results, null, 2), (err) => {
if (err) {
console.error('Error writing to JSON file', err);
} else {
console.log('JSON file has been successfully created');
}
});
});