generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use new lib to support book start with number and spanish
- Loading branch information
Showing
10 changed files
with
107 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getBookIdFromBookName } from './bookNameReference'; | ||
|
||
describe('test bookNameReference', () => { | ||
it('should return the book id', () => { | ||
expect(getBookIdFromBookName('Genesis')).toBe(1); | ||
}) | ||
|
||
it('should return the book id even start with number', () => { | ||
expect(getBookIdFromBookName('1 John', 'en')).toBe(62); | ||
}) | ||
|
||
it('should return the correct id in Spanish', () => { | ||
expect(getBookIdFromBookName('Génesis', 'sp')).toBe(1); | ||
}) | ||
|
||
it('shoud throw an error is code is wrong or cannot find the book', () => { | ||
try { | ||
getBookIdFromBookName('Genesis', 'wrongCode'); | ||
} catch (e) { | ||
expect(e.message).toBe('No translation found for language wrongcode'); | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Reference from 'bible-reference-toolkit' | ||
|
||
|
||
export const getBookIdFromBookName = (bookName: string, langaugeCode: string = 'en'): number => { | ||
try { | ||
return Reference.bookIdFromTranslationAndName(langaugeCode, bookName) | ||
} catch (e) { | ||
// try in slow but in all supported languages | ||
return Reference.bookIdFromName(bookName) | ||
} | ||
} | ||
|
||
export const getFullBookName = (name: string, langaugeCode: string = 'en'): string => { | ||
console.debug('getFullBookName', name, langaugeCode) | ||
const bookId = getBookIdFromBookName(name, langaugeCode) | ||
try { | ||
return Reference.bookNameFromTranslationAndId(langaugeCode, bookId) | ||
} catch (e) { | ||
return Reference.bookEnglishFullNameFromId(bookId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters