json-bible 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/get.ts +12 -5
- package/lib/load.ts +6 -3
- package/lib/search.ts +7 -3
- package/package.json +1 -1
package/lib/get.ts
CHANGED
|
@@ -60,16 +60,23 @@ export function _getVerse(chapter: Chapter, index: number) {
|
|
|
60
60
|
|
|
61
61
|
// BOOK //
|
|
62
62
|
|
|
63
|
-
export function getBookNumber(numberOrNameOrId: number | string, bible?: Bible) {
|
|
63
|
+
export function getBookNumber(numberOrNameOrId: number | string, bible?: Bible, bookIndexFallback?: number) {
|
|
64
64
|
if (isNumber(numberOrNameOrId)) return Number(numberOrNameOrId)
|
|
65
|
-
if (bible?.books) return bible.books.findIndex((a) => a.name === numberOrNameOrId || a.id === numberOrNameOrId)
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
if (bible?.books) {
|
|
67
|
+
const bookIndex = bible.books.findIndex((a) => a.name === numberOrNameOrId || a.id === numberOrNameOrId)
|
|
68
|
+
if (bookIndex > -1) return bookIndex + 1
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const abbrIndex = Object.entries(getDefaultBooks().data).findIndex(([id, name]) => name === numberOrNameOrId || id === numberOrNameOrId)
|
|
72
|
+
if (abbrIndex > -1) return abbrIndex + 1
|
|
73
|
+
|
|
74
|
+
if (bookIndexFallback) return bookIndexFallback + 1
|
|
75
|
+
return 0
|
|
69
76
|
}
|
|
70
77
|
|
|
71
78
|
export function getBookName(numberOrId: number | string, bible?: Bible) {
|
|
72
|
-
let bibleName = bible?.books.find((a) => a.number === numberOrId || a.id === numberOrId)
|
|
79
|
+
let bibleName = bible?.books.find((a) => Number(a.number) === numberOrId || a.number === numberOrId || a.id === numberOrId)
|
|
73
80
|
if (bibleName?.name) return bibleName.name
|
|
74
81
|
|
|
75
82
|
if (isNumber(numberOrId)) return getDefaultBooks().byNumber(Number(numberOrId))
|
package/lib/load.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Bible } from "./Bible"
|
|
2
2
|
import { getDefaultBooks } from "./defaults"
|
|
3
3
|
import { getBookName, getBookNumber } from "./get"
|
|
4
|
+
import { isNumber } from "./util"
|
|
4
5
|
|
|
5
6
|
export async function bibleFromFile(filePath: string) {
|
|
6
7
|
let content = ""
|
|
@@ -55,12 +56,14 @@ export function validateBible(bible: Bible) {
|
|
|
55
56
|
if (!bible.books[0]?.chapters[0]?.verses?.length) incomplete("No initial verses!")
|
|
56
57
|
if (!bible.books[0]?.chapters[0]?.verses[0]?.text?.length) incomplete("No initial text!")
|
|
57
58
|
|
|
58
|
-
// set book names/id if missing
|
|
59
|
-
bible.books = bible.books.map((book) => {
|
|
59
|
+
// set book names/id/number if missing
|
|
60
|
+
bible.books = bible.books.map((book, i) => {
|
|
60
61
|
if (!book.name) book.name = getBookName(book.id || book.number)
|
|
61
|
-
if (!book.number) book.number = getBookNumber(book.name)
|
|
62
62
|
if (!book.id) book.id = getDefaultBooks().ids[book.number - 1]
|
|
63
63
|
|
|
64
|
+
if (!book.number || !isNumber(book.number)) book.number = getBookNumber(book.name, bible, i)
|
|
65
|
+
if (typeof book.number === "string") book.number = Number(book.number)
|
|
66
|
+
|
|
64
67
|
return book
|
|
65
68
|
})
|
|
66
69
|
|
package/lib/search.ts
CHANGED
|
@@ -70,10 +70,14 @@ export function _bookSearch(bible: Bible, searchValue: string) {
|
|
|
70
70
|
if (bookName.includes(name)) matches.push(book)
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
const booksStartingWithSearch = bible.books.filter((a) => removeSpaces(formatText(a.name)).startsWith(name))
|
|
74
|
+
|
|
73
75
|
// find any abbreviation matches
|
|
74
|
-
|
|
75
|
-
let
|
|
76
|
-
|
|
76
|
+
if (booksStartingWithSearch.length < 2) {
|
|
77
|
+
for (let book of bible.books) {
|
|
78
|
+
let abbr = getDefaultBooks().ids[book.number - 1] || ""
|
|
79
|
+
if (abbr.toLowerCase() === name) return [book]
|
|
80
|
+
}
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
// remove books with numbers if no number at search start (John)
|