json-bible 1.1.3 → 1.1.5
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/api/get.ts +2 -1
- package/lib/get.ts +1 -0
- package/lib/reference.ts +1 -1
- package/lib/search.ts +12 -2
- package/package.json +1 -1
package/lib/api/get.ts
CHANGED
|
@@ -103,7 +103,8 @@ export default function ApiBibleHelper(key: string, customApiUrl?: string) {
|
|
|
103
103
|
// HTTP
|
|
104
104
|
|
|
105
105
|
export function fetchWrapper(url: string, headers: any, cacheTimeDays: number) {
|
|
106
|
-
|
|
106
|
+
const cached = getCachedContent(url, cacheTimeDays)
|
|
107
|
+
if (cached) return Promise.resolve(cached)
|
|
107
108
|
|
|
108
109
|
// console.info("Fetching:", url)
|
|
109
110
|
return fetch(url, { headers })
|
package/lib/get.ts
CHANGED
|
@@ -145,6 +145,7 @@ export function formatText(value: string, html: boolean = false) {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
function getVerseNumber(verse: Verse) {
|
|
148
|
+
if (verse.number === undefined) return ""
|
|
148
149
|
let number = verse.number.toString()
|
|
149
150
|
if (verse.endNumber) number += `-${verse.endNumber}`
|
|
150
151
|
return number
|
package/lib/reference.ts
CHANGED
|
@@ -127,7 +127,7 @@ function referenceStringToId(ref: string) {
|
|
|
127
127
|
// "Genesis 1:1-3" = { book: "Genesis ", chapter: 1, verses: [1, 2, 3] }
|
|
128
128
|
function splitReferenceString(ref: string) {
|
|
129
129
|
// (:,.) allowed between chapter/verse - (-+) allowed between verses
|
|
130
|
-
const regex = /(?<book>(?:\d+\.?\s?)?[\p{L}](?:[\p{L}\s']*[\p{L}])?)(?:\s(?<chapter>\d+))?(?:[:,.](?<verses>[0-9,.\-+]+))?/u
|
|
130
|
+
const regex = /(?<book>(?:\d+\.?\s?)?[\p{L}\p{M}](?:[\p{L}\p{M}\s']*[\p{L}\p{M}])?)(?:\s(?<chapter>\d+))?(?:[:,.](?<verses>[0-9,.\-+]+))?/u
|
|
131
131
|
const match = ref.match(regex)
|
|
132
132
|
|
|
133
133
|
if (!match) return { book: "", chapter: "", verses: "" }
|
package/lib/search.ts
CHANGED
|
@@ -70,13 +70,23 @@ export function _bookSearch(bible: Bible, searchValue: string) {
|
|
|
70
70
|
if (bookName.includes(name)) matches.push(book)
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
// remove any books that starts with the full name of another book (e.g. Johannes vs Johannes' Åpenbaring)
|
|
74
|
+
if (matches.length > 1) {
|
|
75
|
+
const shortestMatchName = matches.reduce((shortest, book) => (book.name.length < shortest.length ? book.name : shortest), matches[0].name)
|
|
76
|
+
matches = matches.filter((a) => a.name === shortestMatchName || !a.name.startsWith(shortestMatchName))
|
|
77
|
+
}
|
|
78
|
+
|
|
73
79
|
const booksStartingWithSearch = bible.books.filter((a) => removeSpaces(formatText(a.name)).startsWith(name))
|
|
74
80
|
|
|
75
81
|
// find any abbreviation matches
|
|
76
82
|
if (booksStartingWithSearch.length < 2) {
|
|
77
83
|
for (let book of bible.books) {
|
|
78
|
-
|
|
79
|
-
if
|
|
84
|
+
if (book.abbreviation?.toLowerCase() === name) return [book]
|
|
85
|
+
// only match by index if books count are 66
|
|
86
|
+
if (bible.books.length === 66) {
|
|
87
|
+
let abbr = getDefaultBooks().ids[book.number - 1] || ""
|
|
88
|
+
if (abbr.toLowerCase() === name) return [book]
|
|
89
|
+
}
|
|
80
90
|
}
|
|
81
91
|
}
|
|
82
92
|
|