Skip to content

Instantly share code, notes, and snippets.

@Adrian-Samuel
Last active April 1, 2020 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adrian-Samuel/5accdab48fb715215f5189161b7c3fa0 to your computer and use it in GitHub Desktop.
Save Adrian-Samuel/5accdab48fb715215f5189161b7c3fa0 to your computer and use it in GitHub Desktop.
Script to find bible all names in passages of text
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