Skip to content

Commit

Permalink
update 11 files and delete 3 files
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Best-Codes committed Jul 23, 2024
1 parent 2120b1c commit 73e8b6a
Show file tree
Hide file tree
Showing 9 changed files with 34,021 additions and 34,032 deletions.
67,224 changes: 33,612 additions & 33,612 deletions dist/data/bible.json

Large diffs are not rendered by default.

129 changes: 78 additions & 51 deletions dist/index.cjs.js → dist/index.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import bibleData from "./data/bible.json"
import abbreviations from "./utils/abbreviations"
import { isValidBook, isValidChapter, isValidVerse } from "./utils/validation"
const bibleData = require("./data/bible.json");

let abbreviations, isValidBook, isValidChapter, isValidVerse;
let initializationPromise = null;

function initialize() {
if (!initializationPromise) {
initializationPromise = Promise.all([
import("./utils/abbreviations.js"),
import("./utils/validation.js")
]).then(([abbrModule, validationModule]) => {
abbreviations = abbrModule.abbreviations;
isValidBook = validationModule.isValidBook;
isValidChapter = validationModule.isValidChapter;
isValidVerse = validationModule.isValidVerse;
});
}
return initializationPromise;
}


/**
* Retrieves a specific verse from the Bible data based on the provided book name, chapter number, and verse number.
Expand All @@ -11,16 +28,17 @@ import { isValidBook, isValidChapter, isValidVerse } from "./utils/validation"
* @param {string} [outputType="default"] - The type of output format desired (indexed or string).
* @return {Array|string} The content of the requested verse based on the output type.
*/
function getVerse(
async function getVerse(
bookName,
chapterNumber,
verseNumber,
outputType = "default"
) {
await initialize();
if (!isValidVerse(bookName, chapterNumber, verseNumber)) {
throw new Error("Invalid verse reference")
throw new Error("Invalid verse reference");
}
const content = bibleData[bookName][chapterNumber][verseNumber - 1]
const content = bibleData[bookName][chapterNumber][verseNumber - 1];
if (outputType === "indexed") {
return [
{
Expand All @@ -30,11 +48,11 @@ function getVerse(
verse: verseNumber.toString(),
content: content
}
]
];
} else if (outputType === "string") {
return `${bookName} ${chapterNumber}:${verseNumber} - ${content}`
return `${bookName} ${chapterNumber}:${verseNumber} - ${content}`;
} else {
return [content]
return [content];
}
}

Expand All @@ -46,28 +64,29 @@ function getVerse(
* @param {string} [outputType="default"] - The type of output format desired (indexed or string).
* @return {Array|String} The information about the chapter based on the output type.
*/
function getChapter(bookName, chapterNumber, outputType = "default") {
async function getChapter(bookName, chapterNumber, outputType = "default") {
await initialize();
if (!isValidChapter(bookName, chapterNumber)) {
throw new Error("Invalid chapter reference")
throw new Error("Invalid chapter reference");
}
const verses = bibleData[bookName][chapterNumber]
const verses = bibleData[bookName][chapterNumber];
if (outputType === "indexed") {
return verses.map((content, index) => ({
key: `${bookName} ${chapterNumber}:${index + 1}`,
book: bookName,
chapter: chapterNumber.toString(),
verse: (index + 1).toString(),
content: content
}))
}));
} else if (outputType === "string") {
return verses
.map(
(content, index) =>
`${bookName} ${chapterNumber}:${index + 1} - ${content}`
)
.join("\n")
.join("\n");
} else {
return verses
return verses;
}
}

Expand All @@ -78,11 +97,12 @@ function getChapter(bookName, chapterNumber, outputType = "default") {
* @param {string} [outputType="default"] - The type of output format desired (indexed or string).
* @return {Array|String|Object} The information about the book based on the output type.
*/
function getBook(bookName, outputType = "default") {
async function getBook(bookName, outputType = "default") {
await initialize();
if (!isValidBook(bookName)) {
throw new Error("Invalid book name")
throw new Error("Invalid book name");
}
const chapters = bibleData[bookName]
const chapters = bibleData[bookName];
if (outputType === "indexed") {
return Object.entries(chapters).flatMap(([chapterNumber, verses]) =>
verses.map((content, index) => ({
Expand All @@ -92,7 +112,7 @@ function getBook(bookName, outputType = "default") {
verse: (index + 1).toString(),
content: content
}))
)
);
} else if (outputType === "string") {
return Object.entries(chapters)
.map(([chapterNumber, verses]) =>
Expand All @@ -103,9 +123,9 @@ function getBook(bookName, outputType = "default") {
)
.join("\n")
)
.join("\n\n")
.join("\n\n");
} else {
return chapters
return chapters;
}
}

Expand All @@ -116,11 +136,12 @@ function getBook(bookName, outputType = "default") {
* @throws {Error} Throws an error if the book name is invalid.
* @return {number} The number of chapters in the specified book.
*/
function getChapterCount(bookName) {
async function getChapterCount(bookName) {
await initialize();
if (!isValidBook(bookName)) {
throw new Error("Invalid book name")
throw new Error("Invalid book name");
}
return Object.keys(bibleData[bookName]).length
return Object.keys(bibleData[bookName]).length;
}

/**
Expand All @@ -131,20 +152,22 @@ function getChapterCount(bookName) {
* @throws {Error} Throws an error if the chapter reference is invalid.
* @return {number} The number of verses in the specified chapter.
*/
function getVerseCount(bookName, chapterNumber) {
async function getVerseCount(bookName, chapterNumber) {
await initialize();
if (!isValidChapter(bookName, chapterNumber)) {
throw new Error("Invalid chapter reference")
throw new Error("Invalid chapter reference");
}
return bibleData[bookName][chapterNumber].length
return bibleData[bookName][chapterNumber].length;
}

/**
* Retrieves the list of Bible books.
*
* @return {Array} An array containing the names of all the Bible books.
*/
function getBibleBooks() {
return Object.keys(bibleData)
async function getBibleBooks() {
await initialize();
return Object.keys(bibleData);
}

/**
Expand All @@ -160,7 +183,7 @@ function getBibleBooks() {
* @throws {Error} Throws an error if the verse reference is invalid.
* @return {Array|string} Returns an array of verses or a string of verses depending on the outputType.
*/
function getRange(
async function getRange(
startBookName,
startChapterNumber,
startVerseNumber,
Expand All @@ -169,25 +192,26 @@ function getRange(
endVerseNumber,
outputType = "default"
) {
await initialize();
if (
!isValidVerse(startBookName, startChapterNumber, startVerseNumber) ||
!isValidVerse(endBookName, endChapterNumber, endVerseNumber)
) {
throw new Error("Invalid verse reference")
throw new Error("Invalid verse reference");
}

var verses = []
var verses = [];

// Get the index of the start and end books
var startBookIndex = getBibleBooks().indexOf(startBookName)
var endBookIndex = getBibleBooks().indexOf(endBookName)
var startBookIndex = getBibleBooks().indexOf(startBookName);
var endBookIndex = getBibleBooks().indexOf(endBookName);

// Iterate through the books
for (var bookIndex = startBookIndex; bookIndex <= endBookIndex; bookIndex++) {
var bookName = getBibleBooks()[bookIndex]
var startChapter = bookIndex === startBookIndex ? startChapterNumber : 1
var bookName = getBibleBooks()[bookIndex];
var startChapter = bookIndex === startBookIndex ? startChapterNumber : 1;
var endChapter =
bookIndex === endBookIndex ? endChapterNumber : getChapterCount(bookName)
bookIndex === endBookIndex ? endChapterNumber : getChapterCount(bookName);

// Iterate through the chapters
for (
Expand All @@ -198,42 +222,42 @@ function getRange(
var startVerse =
bookIndex === startBookIndex && chapterNumber === startChapterNumber
? startVerseNumber
: 1
: 1;
var endVerse =
bookIndex === endBookIndex && chapterNumber === endChapterNumber
? endVerseNumber
: getVerseCount(bookName, chapterNumber)
: getVerseCount(bookName, chapterNumber);

// Iterate through the verses
for (
var verseNumber = startVerse;
verseNumber <= endVerse;
verseNumber++
) {
const content = getVerse(bookName, chapterNumber, verseNumber)[0]
const content = getVerse(bookName, chapterNumber, verseNumber)[0];
if (outputType === "indexed") {
verses.push({
key: `${bookName} ${chapterNumber}:${verseNumber}`,
book: bookName,
chapter: chapterNumber.toString(),
verse: verseNumber.toString(),
content: content
})
});
} else if (outputType === "string") {
verses.push(
`${bookName} ${chapterNumber}:${verseNumber} - ${content}`
)
);
} else {
verses.push(content)
verses.push(content);
}
}
}
}

if (outputType === "string") {
return verses.join("\n")
return verses.join("\n");
} else {
return verses
return verses;
}
}

Expand All @@ -243,11 +267,13 @@ function getRange(
* @param {string} abbreviation - The abbreviation to resolve.
* @return {string} The full name corresponding to the abbreviation.
*/
function resolveAbbreviation(abbreviation) {
return abbreviations[abbreviation] || abbreviation
async function resolveAbbreviation(abbreviation) {
await initialize();
return abbreviations[abbreviation] || abbreviation;
}

function bibleStats() {
async function bibleStats() {
await initialize();
return {
books: Object.keys(bibleData).length,
chapters: Object.values(bibleData).reduce(
Expand All @@ -260,10 +286,11 @@ function bibleStats() {
Object.values(book).reduce((sum, chapter) => sum + chapter.length, 0),
0
)
}
};
}

export {

module.exports = {
getVerse,
getChapter,
getBook,
Expand All @@ -273,4 +300,4 @@ export {
getBibleBooks,
resolveAbbreviation,
bibleStats
}
}
35 changes: 0 additions & 35 deletions dist/index.esm.js

This file was deleted.

Loading

0 comments on commit 73e8b6a

Please sign in to comment.