Created
September 26, 2021 02:18
-
-
Save Patrick-web/22a808be5f8c65588fb7ff7110cf190c to your computer and use it in GitHub Desktop.
JSON Bible Parser
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
const path = require("path"); | |
const fs = require("fs"); | |
function parseBible(biblePath) { | |
console.time("parsing time"); | |
const files = fs.readdirSync(biblePath); | |
files.filter((file) => file == "books.json"); | |
const bookNames = JSON.parse( | |
fs.readFileSync(path.join(biblePath, "books.json")) | |
).bookNames; | |
let books = []; | |
for (let index = 0; index < 65; index++) { | |
const book = { | |
name: bookNames[index], | |
chapters: [], | |
}; | |
files.forEach((file) => { | |
if (file.startsWith(`${index}-`)) { | |
book.chapters.push(file); | |
} | |
}); | |
book.chapters = book.chapters.map((value, chapIndex) => { | |
const chap = `${index}-${chapIndex}.json`; | |
const verses = JSON.parse( | |
fs.readFileSync(path.join(biblePath, chap)) | |
).verses; | |
const newChapter = new Map(); | |
newChapter.set(chap, verses); | |
return newChapter; | |
}); | |
books.push(book); | |
} | |
console.log(books); | |
console.timeEnd("parsing time"); | |
} | |
parseBible("./KJV"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment