json-bible 1.1.4 → 1.1.6

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 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/search.ts CHANGED
@@ -70,19 +70,32 @@ 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
- let abbr = getDefaultBooks().ids[book.number - 1] || ""
79
- if (abbr.toLowerCase() === name) return [book]
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
 
83
- // remove books with numbers if no number at search start (John)
93
+ // remove books with numbers if no number at search start (John) - when there are matches
84
94
  const hasNum = (str: string) => /\d/.test(str)
85
- if (!hasNum(name[0])) matches = matches.filter((book) => !hasNum(book.name))
95
+ if (!hasNum(name[0]) && name.length > 1) {
96
+ const noNumberMatches = matches.filter((book) => !hasNum(book.name))
97
+ if (noNumberMatches.length) matches = noNumberMatches
98
+ }
86
99
 
87
100
  return matches
88
101
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "json-bible",
3
3
  "description": "Universal JSON Bible Format",
4
- "version": "1.1.4",
4
+ "version": "1.1.6",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {