Skip to content

Commit ba898f8

Browse files
better typing, esmodules in dev
1 parent 6303187 commit ba898f8

File tree

12 files changed

+351
-258
lines changed

12 files changed

+351
-258
lines changed

dist/browser/best-bible.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/index.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/esm/index.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/types/index.d.ts

Lines changed: 107 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,164 @@
1+
declare module "utils/abbreviations" {
2+
const abbreviations: {
3+
[key: string]: string;
4+
};
5+
export default abbreviations;
6+
}
7+
declare module "utils/validation" {
8+
/**
9+
* Checks if the provided book name is a valid entry in the bibleData.
10+
*
11+
* @param bookName - The name of the book to check.
12+
* @return Indicates whether the book name is valid.
13+
*/
14+
function isValidBook(bookName: string): boolean;
15+
/**
16+
* Checks if the given chapter number is valid for the specified book.
17+
*
18+
* @param bookName - The name of the book.
19+
* @param chapterNumber - The number of the chapter.
20+
* @return Returns true if the chapter number is valid, false otherwise.
21+
*/
22+
function isValidChapter(bookName: string, chapterNumber: number): boolean;
23+
/**
24+
* Checks if the given verse number is valid for the specified book and chapter.
25+
*
26+
* @param bookName - The name of the book.
27+
* @param chapterNumber - The number of the chapter.
28+
* @param verseNumber - The number of the verse.
29+
* @return Returns true if the verse number is valid, false otherwise.
30+
*/
31+
function isValidVerse(bookName: string, chapterNumber: number, verseNumber: number): boolean;
32+
export { isValidBook, isValidChapter, isValidVerse };
33+
}
134
declare module "index" {
35+
interface Word {
36+
word: string;
37+
index: number;
38+
}
39+
interface VerseResult {
40+
key: string;
41+
book: string;
42+
chapter: string;
43+
verse: string;
44+
content: string;
45+
}
246
/**
347
* Parses a verse string and returns either an array of word objects or a cleaned string.
448
*
5-
* @param {string} verse - The verse string to parse.
6-
* @param {string} [outputType="default"] - The type of output. Can be "default", "string", or "indexed".
7-
* @return {Array|String} The parsed verse based on the output type.
49+
* @param verse - The verse string to parse.
50+
* @param outputType - The type of output. Can be "default", "string", or "indexed".
51+
* @return The parsed verse based on the output type.
852
* @deprecated The bible.json file no longer has translation markers, so this function is not needed.
953
*/
10-
export function parseVerse(verse: string, outputType?: string): string | {
11-
word: string;
12-
index: number;
13-
}[];
54+
export function parseVerse(verse: string, outputType?: "default" | "string" | "indexed"): Array<Word> | string;
1455
/**
1556
* Retrieves a specific verse from the Bible data based on the provided book name, chapter number, and verse number.
1657
*
17-
* @param {string} bookName - The name of the book containing the verse.
18-
* @param {number} chapterNumber - The number of the chapter containing the verse.
19-
* @param {number} verseNumber - The number of the verse to retrieve.
20-
* @param {string} [outputType="default"] - The type of output format desired (indexed or string).
21-
* @param {boolean} [cleanVerse=true] - Whether to clean the verse before returning it.
22-
* @return {Array|string} The content of the requested verse based on the output type.
58+
* @param bookName - The name of the book containing the verse.
59+
* @param chapterNumber - The number of the chapter containing the verse.
60+
* @param verseNumber - The number of the verse to retrieve.
61+
* @param outputType - The type of output format desired (indexed or string).
62+
* @param cleanVerse - Whether to clean the verse before returning it.
63+
* @return The content of the requested verse based on the output type.
2364
*/
24-
export function getVerse(bookName: string, chapterNumber: number, verseNumber: number, outputType?: string,
65+
export function getVerse(bookName: string, chapterNumber: number, verseNumber: number, outputType?: "default" | "indexed" | "string",
2566
/**
2667
* @deprecated Use of `cleanVerse` will be removed in a future version. Verses are now always cleaned by default.
2768
*/
28-
cleanVerse?: boolean): string | any[];
69+
cleanVerse?: boolean): Array<VerseResult> | string | string[];
2970
/**
3071
* Retrieves information about a chapter from the Bible data.
3172
*
32-
* @param {string} bookName - The name of the book containing the chapter.
33-
* @param {number} chapterNumber - The number of the chapter to retrieve.
34-
* @param {string} [outputType="default"] - The type of output format desired (indexed or string).
35-
* @param {boolean} [cleanVerse=true] - Whether to clean the verse before returning it.
36-
* @return {Array|String} The information about the chapter based on the output type.
73+
* @param bookName - The name of the book containing the chapter.
74+
* @param chapterNumber - The number of the chapter to retrieve.
75+
* @param outputType - The type of output format desired (indexed or string).
76+
* @param cleanVerse - Whether to clean the verse before returning it.
77+
* @return The information about the chapter based on the output type.
3778
*/
38-
export function getChapter(bookName: string, chapterNumber: number, outputType?: string,
79+
export function getChapter(bookName: string, chapterNumber: number, outputType?: "default" | "indexed" | "string",
3980
/**
4081
* @deprecated Use of `cleanVerse` will be removed in a future version. Verses are now always cleaned by default.
4182
*/
42-
cleanVerse?: boolean): any;
83+
cleanVerse?: boolean): Array<VerseResult> | string | string[];
4384
/**
4485
* Retrieves information about a book from the Bible data.
4586
*
46-
* @param {string} bookName - The name of the book to retrieve.
47-
* @param {string} [outputType="default"] - The type of output format desired (indexed or string).
48-
* @param {boolean} [cleanVerse=true] - Whether to clean the verse before returning it.
49-
* @return {Array|String|Object} The information about the book based on the output type.
87+
* @param bookName - The name of the book to retrieve.
88+
* @param outputType - The type of output format desired (indexed or string).
89+
* @param cleanVerse - Whether to clean the verse before returning it.
90+
* @return The information about the book based on the output type.
5091
*/
51-
export function getBook(bookName: string, outputType?: string,
92+
export function getBook(bookName: string, outputType?: "default" | "indexed" | "string",
5293
/**
5394
* @deprecated Use of `cleanVerse` will be removed in a future version. Verses are now always cleaned by default.
5495
*/
55-
cleanVerse?: boolean): any;
96+
cleanVerse?: boolean): Array<VerseResult> | string | {
97+
[key: string]: string[];
98+
};
5699
/**
57100
* Retrieves the number of chapters in a specific book of the Bible.
58101
*
59-
* @param {string} bookName - The name of the book.
60-
* @throws {Error} Throws an error if the book name is invalid.
61-
* @return {number} The number of chapters in the specified book.
102+
* @param bookName - The name of the book.
103+
* @throws Throws an error if the book name is invalid.
104+
* @return The number of chapters in the specified book.
62105
*/
63106
export function getChapterCount(bookName: string): number;
64107
/**
65108
* Retrieves the number of verses in a specific chapter of a book in the Bible.
66109
*
67-
* @param {string} bookName - The name of the book.
68-
* @param {number} chapterNumber - The number of the chapter.
69-
* @throws {Error} Throws an error if the chapter reference is invalid.
70-
* @return {number} The number of verses in the specified chapter.
110+
* @param bookName - The name of the book.
111+
* @param chapterNumber - The number of the chapter.
112+
* @throws Throws an error if the chapter reference is invalid.
113+
* @return The number of verses in the specified chapter.
71114
*/
72-
export function getVerseCount(bookName: string, chapterNumber: number): any;
115+
export function getVerseCount(bookName: string, chapterNumber: number): number;
73116
/**
74117
* Retrieves the list of Bible books.
75118
*
76-
* @return {Array} An array containing the names of all the Bible books.
119+
* @return An array containing the names of all the Bible books.
77120
*/
78121
export function getBibleBooks(): string[];
79122
/**
80123
* Retrieves a range of verses from the Bible based on the provided start and end references.
81124
*
82-
* @param {string} startBookName - The name of the starting book.
83-
* @param {number} startChapterNumber - The number of the starting chapter.
84-
* @param {number} startVerseNumber - The number of the starting verse.
85-
* @param {string} endBookName - The name of the ending book.
86-
* @param {number} endChapterNumber - The number of the ending chapter.
87-
* @param {number} endVerseNumber - The number of the ending verse.
88-
* @param {string} [outputType="default"] - The type of output. Can be "indexed", "string", or "default".
89-
* @param {boolean} [cleanVerse=true] - Whether to clean the verse before returning it.
90-
* @throws {Error} Throws an error if the verse reference is invalid.
91-
* @return {Array|string} Returns an array of verses or a string of verses depending on the outputType.
92-
*/
93-
export function getRange(startBookName: string, startChapterNumber: number, startVerseNumber: number, endBookName: string, endChapterNumber: number, endVerseNumber: number, outputType?: string,
125+
* @param startBookName - The name of the starting book.
126+
* @param startChapterNumber - The number of the starting chapter.
127+
* @param startVerseNumber - The number of the starting verse.
128+
* @param endBookName - The name of the ending book.
129+
* @param endChapterNumber - The number of the ending chapter.
130+
* @param endVerseNumber - The number of the ending verse.
131+
* @param outputType - The type of output. Can be "indexed", "string", or "default".
132+
* @param cleanVerse - Whether to clean the verse before returning it.
133+
* @throws Throws an error if the verse reference is invalid.
134+
* @return Returns an array of verses or a string of verses depending on the outputType.
135+
*/
136+
export function getRange(startBookName: string, startChapterNumber: number, startVerseNumber: number, endBookName: string, endChapterNumber: number, endVerseNumber: number, outputType?: "default" | "indexed" | "string",
94137
/**
95138
* @deprecated Use of `cleanVerse` will be removed in a future version. Verses are now always cleaned by default.
96139
*/
97-
cleanVerse?: boolean): string | any[];
140+
cleanVerse?: boolean): Array<VerseResult> | string | string[];
98141
/**
99142
* Searches for a query string in each verse of the Bible and returns the matching verses.
100143
*
101-
* @param {string} query - The query string to search for.
102-
* @param {boolean} [caseSensitive=false] - Whether the search should be case sensitive.
103-
* @param {boolean} [exactMatch=false] - Whether the search should match the exact phrase.
104-
* @param {string} [outputType="indexed"] - The type of output format desired (indexed or string).
105-
* @return {Array|string} The matching verses based on the output type.
144+
* @param query - The query string to search for.
145+
* @param caseSensitive - Whether the search should be case sensitive.
146+
* @param exactMatch - Whether the search should match the exact phrase.
147+
* @param outputType - The type of output format desired (indexed or string).
148+
* @return The matching verses based on the output type.
106149
*/
107-
export function searchVerse(query: string, caseSensitive?: boolean, exactMatch?: boolean, outputType?: string): string | {
108-
key: string;
109-
book: string;
110-
chapter: string;
111-
verse: string;
112-
content: any;
113-
}[] | undefined;
150+
export function searchVerse(query: string, caseSensitive?: boolean, exactMatch?: boolean, outputType?: "indexed" | "string"): Array<VerseResult> | string;
114151
/**
115152
* Resolves an abbreviation to its full name.
116153
*
117-
* @param {string} abbreviation - The abbreviation to resolve.
118-
* @return {string} The full name corresponding to the abbreviation.
154+
* @param abbreviation - The abbreviation to resolve.
155+
* @return The full name corresponding to the abbreviation.
119156
*/
120-
export function resolveAbbreviation(abbreviation: string): any;
157+
export function resolveAbbreviation(abbreviation: string): string;
121158
/**
122159
* Returns an object containing the number of books, chapters, and verses in the Bible.
123160
*
124-
* @return {Object} An object with the number of books, chapters, and verses in the Bible.
161+
* @return An object with the number of books, chapters, and verses in the Bible.
125162
*/
126163
export function bibleStats(): {
127164
books: number;
@@ -131,11 +168,11 @@ declare module "index" {
131168
/**
132169
* Returns an object containing the three validation functions: `isValidBook`, `isValidChapter`, and `isValidVerse`.
133170
*
134-
* @return {Object} An object with the validation functions as properties.
171+
* @return An object with the validation functions as properties.
135172
*/
136173
export function bibleValidation(): {
137-
isValidBook: any;
138-
isValidChapter: any;
139-
isValidVerse: any;
174+
isValidBook: (bookName: string) => boolean;
175+
isValidChapter: (bookName: string, chapterNumber: number) => boolean;
176+
isValidVerse: (bookName: string, chapterNumber: number, verseNumber: number) => boolean;
140177
};
141178
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "best-bible",
3-
"version": "1.7.1",
3+
"version": "1.7.2",
44
"description": "Fetch, parse, and analyze the Bible easily with JavaScript",
55
"scripts": {
66
"prebuild": "rm -rf dist",
@@ -12,7 +12,7 @@
1212
"prepublishOnly": "bun run build",
1313
"test": "bun test"
1414
},
15-
"packageManager": "[email protected].38",
15+
"packageManager": "[email protected].42",
1616
"files": [
1717
"dist",
1818
"README.md",

0 commit comments

Comments
 (0)