json-bible 1.1.1 → 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/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
- for (let book of bible.books) {
75
- let abbr = getDefaultBooks().ids[book.number - 1] || ""
76
- if (abbr.toLowerCase() === name) return [book]
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)
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.1",
4
+ "version": "1.1.2",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {