mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added create JSON from txt script
This commit is contained in:
parent
86acdec2f5
commit
9d3f14b4a8
1 changed files with 33 additions and 0 deletions
33
src/standaloneUtils/createJSON.js
Normal file
33
src/standaloneUtils/createJSON.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
const fs = require('fs')
|
||||
|
||||
const params = process.argv
|
||||
const file = params[2]
|
||||
|
||||
const data = fs.readFileSync(file,'utf8').split('\n')
|
||||
console.log(data)
|
||||
|
||||
let currVal = {}
|
||||
const res = data.reduce((acc, val) => {
|
||||
const formattedVal = val.replace(/\r/g, '').trim()
|
||||
|
||||
if (formattedVal.startsWith('#')) return acc
|
||||
if (formattedVal.startsWith('Q')) {
|
||||
currVal = {
|
||||
Q: formattedVal
|
||||
}
|
||||
return acc
|
||||
}
|
||||
if (formattedVal.startsWith('A')) {
|
||||
currVal.A = formattedVal
|
||||
return [
|
||||
...acc,
|
||||
currVal
|
||||
]
|
||||
}
|
||||
|
||||
return acc
|
||||
}, [])
|
||||
|
||||
console.log(res)
|
||||
fs.writeFileSync('./res.json', JSON.stringify(res, null, 2))
|
||||
console.log('DONE')
|
Loading…
Add table
Add a link
Reference in a new issue