Created
December 12, 2020 12:24
-
-
Save yakimelon/123cba8c227562ce141792908a4d9ecd to your computer and use it in GitHub Desktop.
FirebaseRealtimeDBでエクスポートしたJSONをスプシで良い感じに読み込めるCSVに変換する雑なコード。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function replace(text) { | |
return text | |
// 余計な文字の削除 | |
.replace(/(".*" : \{|\{|\}|".*" : |^ )/g, '') | |
// 1つのデータの塊を1列に変換 | |
.replace(/",\r?\n/g, '", ') | |
// 半角スペースをすべて削除 | |
.replace(/ /g, '') | |
// 行間のカンマとその行を削除 | |
.replace(/"\r?\n,/g, '"') | |
// 行と行の間にある3つの改行を1つに変換する | |
.replace(/\r?\n\r?\n/g, '\n') | |
} | |
const fs = require('fs'); | |
const text = fs.readFileSync("login.json", 'utf-8'); | |
console.log(replace(text)); | |
try { | |
fs.writeFileSync("login.csv", replace(text)); | |
console.log("Success!"); | |
} catch(e) { | |
console.log("Failed...") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment