Skip to content

Commit 0fb7661

Browse files
authored
Improve canon (#6)
2 parents 0870eb4 + 1c9515e commit 0fb7661

6 files changed

Lines changed: 643 additions & 400 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
"url": "http://json.schemastore.org/tsconfig"
1313
}
1414
],
15-
"cSpell.words": ["Parseable"]
15+
"cSpell.words": ["deutero", "otnt", "parseable"]
1616
}

README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
</div>
1111

12-
TypeScript partial port of the C# library [libpalaso/SIL.Scripture][github-libpalaso-scripture]. These libraries are used by [Paratext](https://paratext.org/) to represent and support Scripture references.
12+
TypeScript partial port of the C# library [libpalaso/SIL.Scripture][github-libpalaso-scripture]. These libraries are used by [Paratext](https://paratext.org/) and provides classes for working with Scripture data such as references and versifications.
1313

1414
v1 is a minimal partial port in TypeScript that supports use on the frontend while still using the full C# version on the backend.
1515

@@ -18,8 +18,9 @@ v1 is a minimal partial port in TypeScript that supports use on the frontend whi
1818
- {class} Canon - Canon information. Also, contains static information on complete list of books.
1919
- {class} VerseRef - Stores a reference to a specific verse in Scripture.
2020
- Represents a single reference, e.g. `'GEN 2:3'`.
21-
- Represents a reference range and segments, e.g. `'LUK 3:4b-5a'`.
22-
- Represents a reference sequence and segments, e.g. `'GEN 1:1a-3b,5'`.
21+
- Represents a reference range, e.g. `'LUK 3:4-5'`.
22+
- Represents a reference sequence, e.g. `'GEN 1:1-3,5'`.
23+
- Represents a reference with a segment, e.g. `'LUK 3:4b'`.
2324
- Validate references.
2425
- Supports versification types: Unknown, Original, Septuagint, Vulgate, English, RussianProtestant, RussianOrthodox.
2526

@@ -113,15 +114,35 @@ Useful static functions:
113114
```typescript
114115
import { Canon } from '@sillsdev/scripture';
115116

117+
console.log(Canon.bookIdToNumber('MAT')); // 40
118+
116119
console.log(Canon.bookNumberToId(1)); // 'GEN'
117120
console.log(Canon.bookNumberToId(40)); // 'MAT'
118121

119-
console.log(Canon.bookNumberToId('MAT')); // 40
120-
121122
console.log(Canon.bookNumberToEnglishName(1)); // 'Genesis'
122123

123124
console.log(Canon.bookIdToEnglishName('GEN')); // 'Genesis'
124125

126+
console.log(Canon.isBookIdValid('MAT')); // true
127+
128+
console.log(Canon.isBookNT('MAT')); // true
129+
console.log(Canon.isBookNT(1)); // false
130+
131+
console.log(Canon.isBookOT('MAT')); // false
132+
console.log(Canon.isBookOT(1)); // true
133+
134+
console.log(Canon.isBookOTNT('MAT')); // true
135+
console.log(Canon.isBookOTNT(1)); // true
136+
137+
console.log(Canon.isBookDC('TOB')); // true
138+
console.log(Canon.isBookDC(1)); // false
139+
140+
console.log(Canon.isCanonical('XXA')); // false
141+
console.log(Canon.isCanonical(1)); // true
142+
143+
console.log(Canon.isExtraMaterial('XXA')); // true
144+
console.log(Canon.isExtraMaterial(1)); // false
145+
125146
console.log(Canon.isObsolete(87)); // true
126147
```
127148

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sillsdev/scripture",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "TypeScript partial port of `libpalaso/SIL.Scripture`",
55
"main": "dist/index.cjs.js",
66
"module": "dist/index.es.js",

src/canon.test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,62 @@
11
import { Canon } from './canon';
22

33
describe('Canon', () => {
4+
describe('isBookNT()', () => {
5+
it("should return whether it's NT or not", () => {
6+
let isBookNT = Canon.isBookNT(1);
7+
expect(isBookNT).toBe(false);
8+
isBookNT = Canon.isBookNT('GEN');
9+
expect(isBookNT).toBe(false);
10+
isBookNT = Canon.isBookNT(42);
11+
expect(isBookNT).toBe(true);
12+
isBookNT = Canon.isBookNT('MAT');
13+
expect(isBookNT).toBe(true);
14+
});
15+
});
16+
17+
describe('isBookOT()', () => {
18+
it("should return whether it's OT or not", () => {
19+
let isBookOT = Canon.isBookOT(1);
20+
expect(isBookOT).toBe(true);
21+
isBookOT = Canon.isBookOT('GEN');
22+
expect(isBookOT).toBe(true);
23+
isBookOT = Canon.isBookOT(42);
24+
expect(isBookOT).toBe(false);
25+
isBookOT = Canon.isBookOT('MAT');
26+
expect(isBookOT).toBe(false);
27+
});
28+
});
29+
30+
describe('isBookDC()', () => {
31+
it("should return whether it's Deutero Canon or not", () => {
32+
let isBookDC = Canon.isBookDC(66);
33+
expect(isBookDC).toBe(false);
34+
isBookDC = Canon.isBookDC('REV');
35+
expect(isBookDC).toBe(false);
36+
isBookDC = Canon.isBookDC(67);
37+
expect(isBookDC).toBe(true);
38+
isBookDC = Canon.isBookDC('TOB');
39+
expect(isBookDC).toBe(true);
40+
});
41+
});
42+
43+
describe('allBookNumbers()', () => {
44+
it('should yield each book number', () => {
45+
const iterator = Canon.allBookNumbers();
46+
expect(iterator.next().value).toEqual(1);
47+
expect(iterator.next().value).toEqual(2);
48+
expect(iterator.next().value).toEqual(3);
49+
});
50+
});
51+
52+
describe('extraBooks()', () => {
53+
it('should return array of extra book IDs', () => {
54+
const extraBooks = Canon.extraBooks();
55+
expect(extraBooks[0]).toEqual('XXA');
56+
expect(extraBooks.length).toEqual(7);
57+
});
58+
});
59+
460
describe('bookNumberToId()', () => {
561
it('should return bookId', () => {
662
const bookId = Canon.bookNumberToId(1);
@@ -32,6 +88,29 @@ describe('Canon', () => {
3288
});
3389
});
3490

91+
describe('isCanonical()', () => {
92+
it("should return whether it's canonical or not", () => {
93+
// `num` overload is tested in `isBookDC()`.
94+
let isCanonical = Canon.isCanonical('GEN');
95+
expect(isCanonical).toBe(true);
96+
isCanonical = Canon.isCanonical('XXA');
97+
expect(isCanonical).toBe(false);
98+
});
99+
});
100+
101+
describe('isExtraMaterial()', () => {
102+
it("should return whether it's extra material or not", () => {
103+
let isExtraMaterial = Canon.isExtraMaterial(1);
104+
expect(isExtraMaterial).toBe(false);
105+
isExtraMaterial = Canon.isExtraMaterial('GEN');
106+
expect(isExtraMaterial).toBe(false);
107+
isExtraMaterial = Canon.isExtraMaterial(93);
108+
expect(isExtraMaterial).toBe(true);
109+
isExtraMaterial = Canon.isExtraMaterial('XXA');
110+
expect(isExtraMaterial).toBe(true);
111+
});
112+
});
113+
35114
describe('isObsolete()', () => {
36115
it("should return whether it's obsolete or not", () => {
37116
let isObsolete = Canon.isObsolete(1);

0 commit comments

Comments
 (0)