Last active
April 1, 2020 22:32
-
-
Save Adrian-Samuel/5accdab48fb715215f5189161b7c3fa0 to your computer and use it in GitHub Desktop.
Script to find bible all names in passages of text
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 getMatchingBibleBooks = async (passage) => { | |
const bibleSite = "https://www.biblegateway.com/passage/bbl/?version=NKJV&locale=en" | |
if (window.location.href != bibleSite) window.location.href = bibleSite | |
const getPage = await fetch(bibleSite) | |
const getJSONPage = await getPage.json() | |
const bibleBooks = getJSONPage.testaments.reduce((bookNames, currentTestament) => { | |
const bookList = currentTestament.columns.reduce((testamentNames, currentList) => { | |
const currentBookList = currentList.map(({ | |
name | |
}) => name) | |
return [...testamentNames, ...currentBookList] | |
}, []) | |
return [...bookNames, ...bookList]; | |
}, []) | |
const cleanedIndexBookNames = bibleBooks.map(book => book.replace(/\d+/g, "").trim()) | |
const trimmedPassage = passage.replace(/[^A-Z]/gi, "") | |
const matchedBooks = cleanedIndexBookNames.reduce((matchList, currentBook) => { | |
if (trimmedPassage.match(new RegExp(currentBook, "ig")) != null) { | |
matchList.push(currentBook) | |
return matchList | |
} | |
return matchList | |
}, []) | |
const finalBookList = [...new Set(matchedBooks)] | |
console.table(finalBookList, "Bible Book Matched") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment