Skip to content

Commit

Permalink
delete 7 files and update 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 16c356f commit 6edfc8b
Show file tree
Hide file tree
Showing 20 changed files with 34,149 additions and 67,881 deletions.
File renamed without changes.
83 changes: 35 additions & 48 deletions dist/index.d.ts → dist/cjs/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
const bibleData = require(`./data/bible.json`);
const abbreviations = require(`./utils/abbreviations`);
const { isValidBook, isValidChapter, isValidVerse } = require(`./utils/validation`);

/**
* Retrieves a specific verse from the Bible data based on the provided book name, chapter number, and verse number.
*
Expand All @@ -18,19 +18,20 @@ function getVerse(bookName, chapterNumber, verseNumber, outputType = "default")
const content = bibleData[bookName][chapterNumber][verseNumber - 1];
if (outputType === "indexed") {
return [{
key: `${bookName} ${chapterNumber}:${verseNumber}`,
book: bookName,
chapter: chapterNumber.toString(),
verse: verseNumber.toString(),
content: content
}];
} else if (outputType === "string") {
key: `${bookName} ${chapterNumber}:${verseNumber}`,
book: bookName,
chapter: chapterNumber.toString(),
verse: verseNumber.toString(),
content: content
}];
}
else if (outputType === "string") {
return `${bookName} ${chapterNumber}:${verseNumber} - ${content}`;
} else {
}
else {
return [content];
}
}

/**
* Retrieves information about a chapter from the Bible data.
*
Expand All @@ -52,13 +53,14 @@ function getChapter(bookName, chapterNumber, outputType = "default") {
verse: (index + 1).toString(),
content: content
}));
} else if (outputType === "string") {
}
else if (outputType === "string") {
return verses.map((content, index) => `${bookName} ${chapterNumber}:${index + 1} - ${content}`).join("\n");
} else {
}
else {
return verses;
}
}

/**
* Retrieves information about a book from the Bible data.
*
Expand All @@ -72,24 +74,21 @@ function getBook(bookName, outputType = "default") {
}
const chapters = bibleData[bookName];
if (outputType === "indexed") {
return Object.entries(chapters).flatMap(([chapterNumber, verses]) =>
verses.map((content, index) => ({
key: `${bookName} ${chapterNumber}:${index + 1}`,
book: bookName,
chapter: chapterNumber,
verse: (index + 1).toString(),
content: content
}))
);
} else if (outputType === "string") {
return Object.entries(chapters).map(([chapterNumber, verses]) =>
verses.map((content, index) => `${bookName} ${chapterNumber}:${index + 1} - ${content}`).join("\n")
).join("\n\n");
} else {
return Object.entries(chapters).flatMap(([chapterNumber, verses]) => verses.map((content, index) => ({
key: `${bookName} ${chapterNumber}:${index + 1}`,
book: bookName,
chapter: chapterNumber,
verse: (index + 1).toString(),
content: content
})));
}
else if (outputType === "string") {
return Object.entries(chapters).map(([chapterNumber, verses]) => verses.map((content, index) => `${bookName} ${chapterNumber}:${index + 1} - ${content}`).join("\n")).join("\n\n");
}
else {
return chapters;
}
}

/**
* Retrieves the number of chapters in a specific book of the Bible.
*
Expand All @@ -103,7 +102,6 @@ function getChapterCount(bookName) {
}
return Object.keys(bibleData[bookName]).length;
}

/**
* Retrieves the number of verses in a specific chapter of a book in the Bible.
*
Expand All @@ -118,7 +116,6 @@ function getVerseCount(bookName, chapterNumber) {
}
return bibleData[bookName][chapterNumber].length;
}

/**
* Retrieves the list of Bible books.
*
Expand All @@ -127,7 +124,6 @@ function getVerseCount(bookName, chapterNumber) {
function getBibleBooks() {
return Object.keys(bibleData);
}

/**
* Retrieves a range of verses from the Bible based on the provided start and end references.
*
Expand All @@ -145,24 +141,19 @@ function getRange(startBookName, startChapterNumber, startVerseNumber, endBookNa
if (!isValidVerse(startBookName, startChapterNumber, startVerseNumber) || !isValidVerse(endBookName, endChapterNumber, endVerseNumber)) {
throw new Error('Invalid verse reference');
}

var verses = [];

// Get the index of the start and end books
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 endChapter = (bookIndex === endBookIndex) ? endChapterNumber : getChapterCount(bookName);

// Iterate through the chapters
for (var chapterNumber = startChapter; chapterNumber <= endChapter; chapterNumber++) {
var startVerse = (bookIndex === startBookIndex && chapterNumber === startChapterNumber) ? startVerseNumber : 1;
var endVerse = (bookIndex === endBookIndex && chapterNumber === endChapterNumber) ? endVerseNumber : getVerseCount(bookName, chapterNumber);

// Iterate through the verses
for (var verseNumber = startVerse; verseNumber <= endVerse; verseNumber++) {
const content = getVerse(bookName, chapterNumber, verseNumber)[0];
Expand All @@ -174,22 +165,23 @@ function getRange(startBookName, startChapterNumber, startVerseNumber, endBookNa
verse: verseNumber.toString(),
content: content
});
} else if (outputType === "string") {
}
else if (outputType === "string") {
verses.push(`${bookName} ${chapterNumber}:${verseNumber} - ${content}`);
} else {
}
else {
verses.push(content);
}
}
}
}

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

/**
* Resolves an abbreviation to its full name.
*
Expand All @@ -199,15 +191,13 @@ function getRange(startBookName, startChapterNumber, startVerseNumber, endBookNa
function resolveAbbreviation(abbreviation) {
return abbreviations[abbreviation] || abbreviation;
}

function bibleStats() {
return {
books: Object.keys(bibleData).length,
chapters: Object.values(bibleData).reduce((sum, book) => sum + Object.keys(book).length, 0),
verses: Object.values(bibleData).reduce((sum, book) => sum + Object.values(book).reduce((sum, chapter) => sum + chapter.length, 0), 0),
};
}

/**
* Returns an object containing the three validation functions: `isValidBook`, `isValidChapter`, and `isValidVerse`.
*
Expand All @@ -218,9 +208,8 @@ function validators() {
isValidBook,
isValidChapter,
isValidVerse
}
};
}

module.exports = {
getVerse,
getChapter,
Expand All @@ -231,7 +220,5 @@ module.exports = {
getBibleBooks,
resolveAbbreviation,
bibleStats,
bibleValidation: {
...validators()
}
bibleValidation: Object.assign({}, validators())
};
70 changes: 70 additions & 0 deletions dist/cjs/utils/abbreviations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"use strict";
const abbreviations = {
'Gen': 'Genesis',
'Ex': 'Exodus',
'Lev': 'Leviticus',
'Num': 'Numbers',
'Deu': 'Deuteronomy',
'Jos': 'Joshua',
'Jdg': 'Judges',
'Rut': 'Ruth',
'1Sa': '1 Samuel',
'2Sa': '2 Samuel',
'1Ki': '1 Kings',
'2Ki': '2 Kings',
'1Ch': '1 Chronicles',
'2Ch': '2 Chronicles',
'Ezr': 'Ezra',
'Neh': 'Nehemiah',
'Est': 'Esther',
'Job': 'Job',
'Psa': 'Psalms',
'Pro': 'Proverbs',
'Ecc': 'Ecclesiastes',
'Sng': 'Song of Solomon',
'Isa': 'Isaiah',
'Jer': 'Jeremiah',
'Lam': 'Lamentations',
'Eze': 'Ezekiel',
'Dan': 'Daniel',
'Hos': 'Hosea',
'Joe': 'Joel',
'Amo': 'Amos',
'Oba': 'Obadiah',
'Jnh': 'Jonah',
'Mic': 'Micah',
'Nah': 'Nahum',
'Hab': 'Habakkuk',
'Zeph': 'Zephaniah',
'Hag': 'Haggai',
'Zech': 'Zechariah',
'Mal': 'Malachi',
'Matt': 'Matthew',
'Mark': 'Mark',
'Luk': 'Luke',
'Jhn': 'John',
'Act': 'Acts',
'Rom': 'Romans',
'1Co': '1 Corinthians',
'2Co': '2 Corinthians',
'Gal': 'Galatians',
'Eph': 'Ephesians',
'Phil': 'Philippians',
'Col': 'Colossians',
'1Th': '1 Thessalonians',
'2Th': '2 Thessalonians',
'1Ti': '1 Timothy',
'2Ti': '2 Timothy',
'Tit': 'Titus',
'Phm': 'Philemon',
'Heb': 'Hebrews',
'Jam': 'James',
'1Pe': '1 Peter',
'2Pe': '2 Peter',
'1Jn': '1 John',
'2Jn': '2 John',
'3Jn': '3 John',
'Jude': 'Jude',
'Rev': 'Revelation'
};
module.exports = abbreviations;
45 changes: 45 additions & 0 deletions dist/cjs/utils/validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use strict";
const bibleData = require('../data/bible.json');
/**
* Checks if the provided book name is a valid entry in the bibleData.
*
* @param {string} bookName - The name of the book to check.
* @return {boolean} Indicates whether the book name is valid.
*/
function isValidBook(bookName) {
return bibleData.hasOwnProperty(bookName);
}
/**
* Checks if the given chapter number is valid for the specified book.
*
* @param {string} bookName - The name of the book.
* @param {number} chapterNumber - The number of the chapter.
* @return {boolean} Returns true if the chapter number is valid, false otherwise.
*/
function isValidChapter(bookName, chapterNumber) {
if (!isValidBook(bookName)) {
return false;
}
const book = bibleData[bookName];
return book.hasOwnProperty(chapterNumber);
}
/**
* Checks if the given verse number is valid for the specified book and chapter.
*
* @param {string} bookName - The name of the book.
* @param {number} chapterNumber - The number of the chapter.
* @param {number} verseNumber - The number of the verse.
* @return {boolean} Returns true if the verse number is valid, false otherwise.
*/
function isValidVerse(bookName, chapterNumber, verseNumber) {
if (!isValidChapter(bookName, chapterNumber)) {
return false;
}
const chapter = bibleData[bookName][chapterNumber];
return verseNumber >= 1 && verseNumber <= chapter.length;
}
module.exports = {
isValidBook,
isValidChapter,
isValidVerse,
};
Loading

0 comments on commit 6edfc8b

Please sign in to comment.