json-bible 1.1.2 → 1.1.4
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 +5 -1
- package/lib/api/index.ts +1 -0
- package/lib/reference.ts +1 -1
- 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
|
}
|
|
@@ -100,7 +103,8 @@ export default function ApiBibleHelper(key: string, customApiUrl?: string) {
|
|
|
100
103
|
// HTTP
|
|
101
104
|
|
|
102
105
|
export function fetchWrapper(url: string, headers: any, cacheTimeDays: number) {
|
|
103
|
-
|
|
106
|
+
const cached = getCachedContent(url, cacheTimeDays)
|
|
107
|
+
if (cached) return Promise.resolve(cached)
|
|
104
108
|
|
|
105
109
|
// console.info("Fetching:", url)
|
|
106
110
|
return fetch(url, { headers })
|
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/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: "" }
|