json-bible 1.1.1 → 1.1.3
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 +3 -0
- package/lib/api/index.ts +1 -0
- package/lib/load.ts +5 -2
- package/lib/search.ts +7 -3
- package/package.json +1 -1
package/lib/api/get.ts
CHANGED
|
@@ -45,6 +45,8 @@ export default function ApiBibleHelper(key: string, customApiUrl?: string) {
|
|
|
45
45
|
|
|
46
46
|
// GEN
|
|
47
47
|
async function getChapters(bookId: string) {
|
|
48
|
+
if (!bookId) return { json: [], chaptersData: [] }
|
|
49
|
+
|
|
48
50
|
const chaptersData = await getApiChapters(bookId)
|
|
49
51
|
|
|
50
52
|
const json = chaptersData.map((chapter) => {
|
|
@@ -87,6 +89,7 @@ export default function ApiBibleHelper(key: string, customApiUrl?: string) {
|
|
|
87
89
|
|
|
88
90
|
// no api key needed, just the bible id
|
|
89
91
|
async function contentSearch(query: string, { limit } = { limit: 20 }) {
|
|
92
|
+
query = encodeURIComponent(query.trim())
|
|
90
93
|
const url = `${bibleUrl}/search?query=${query}&limit=${limit}`
|
|
91
94
|
return ((await fetchWrapper(url, headers, 14)) as BibleContentSearchResult).verses
|
|
92
95
|
}
|
package/lib/api/index.ts
CHANGED
|
@@ -273,6 +273,7 @@ export async function ApiBible(apiKey: string, bibleKey: string, apiUrl?: string
|
|
|
273
273
|
*/
|
|
274
274
|
async function textSearch(value: string, limit: number = 50) {
|
|
275
275
|
const result = await bibleData.contentSearch(value, { limit })
|
|
276
|
+
if (!result) return []
|
|
276
277
|
|
|
277
278
|
// convert result to VerseReference[]
|
|
278
279
|
return result.map((r) => {
|
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
|
+
// set book names/id/number if missing
|
|
59
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, bible, i)
|
|
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)
|