mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-07-13 02:53:45 +00:00
feat(*): Add tsv parser to enable easily loading pokedex data
This commit is contained in:
@@ -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');
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user