Skip to content

Commit 18bd4b6

Browse files
committed
Added bbbcccvvv support to VerseRef constructor
1 parent 0fb7661 commit 18bd4b6

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ console.log(verseRef.chapterNum); // 3
5353
console.log(verseRef.verse); // '4b-5a'
5454
console.log(verseRef.verseNum); // 4
5555

56+
// construct from a bbbcccvvv number
57+
verseRef = new VerseRef(42003004);
58+
console.log(verseRef.bookNum); // 42
59+
console.log(verseRef.chapterNum); // 3
60+
console.log(verseRef.verseNum); // 4
61+
5662
// construct from an existing VerseRef
5763
verseRef = new VerseRef(verseRef);
5864
console.log(verseRef.book); // 'LUK'

src/verse-ref.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe('VerseRef', () => {
116116
expect(vref.allVerses().length).toEqual(2);
117117
expect(vref.versification).toEqual(ScrVers.Vulgate);
118118
});
119-
/*
119+
120120
it('should construct from BBBCCCVV without versification', () => {
121121
const vref = new VerseRef(12015013);
122122
expect(vref.BBBCCCVVV).toEqual(12015013);
@@ -128,7 +128,18 @@ describe('VerseRef', () => {
128128
expect(vref.verse).toEqual('13');
129129
expect(vref.versification).toEqual(VerseRef.defaultVersification);
130130
});
131-
*/
131+
132+
it('should construct from BBBCCCVV with versification', () => {
133+
const vref = new VerseRef(42003004, ScrVers.Vulgate);
134+
expect(vref.BBBCCCVVV).toEqual(42003004);
135+
// expect(vref.BBBCCCVVVS).toEqual('042003004');
136+
expect(vref.book).toEqual('LUK');
137+
expect(vref.bookNum).toEqual(42);
138+
expect(vref.chapterNum).toEqual(3);
139+
expect(vref.verseNum).toEqual(4);
140+
expect(vref.verse).toEqual('4');
141+
expect(vref.versification).toEqual(ScrVers.Vulgate);
142+
});
132143
});
133144

134145
describe('Chapter and Verse as Empty Strings', () => {

src/verse-ref.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class VerseRef {
156156
private _verseNum = 0;
157157
private _verse?: string;
158158

159-
constructor(verseStr: string, versification?: ScrVers);
159+
constructor(verseStr: string | number, versification?: ScrVers);
160160
constructor(verseRef: VerseRef);
161161
constructor(versification?: ScrVers);
162162
constructor(book: string, chapter: string, verse: string, versification?: ScrVers);
@@ -175,6 +175,16 @@ export class VerseRef {
175175
chapterEtc != null && chapterEtc instanceof ScrVers ? chapterEtc : undefined;
176176
this.setEmpty(_versification);
177177
this.parse(_verserStr);
178+
} else if (bookEtc != null && typeof bookEtc === 'number') {
179+
// constructor(bbbcccvvv: number, versification?: ScrVers);
180+
const _versification: ScrVers | undefined =
181+
chapterEtc != null && chapterEtc instanceof ScrVers ? chapterEtc : undefined;
182+
this.setEmpty(_versification);
183+
this._verseNum = bookEtc % VerseRef.chapterDigitShifter;
184+
this._chapterNum = Math.floor(
185+
(bookEtc % VerseRef.bookDigitShifter) / VerseRef.chapterDigitShifter
186+
);
187+
this._bookNum = Math.floor(bookEtc / VerseRef.bookDigitShifter);
178188
} else if (chapterEtc == null) {
179189
if (bookEtc != null && bookEtc instanceof VerseRef) {
180190
// constructor(verseRef: VerseRef);

0 commit comments

Comments
 (0)