Skip to content

Commit

Permalink
Improve canon (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
irahopkinson authored Jul 14, 2023
2 parents 0870eb4 + 1c9515e commit 0fb7661
Show file tree
Hide file tree
Showing 6 changed files with 643 additions and 400 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"url": "http://json.schemastore.org/tsconfig"
}
],
"cSpell.words": ["Parseable"]
"cSpell.words": ["deutero", "otnt", "parseable"]
}
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

</div>

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.
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.

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

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

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

console.log(Canon.bookIdToNumber('MAT')); // 40

console.log(Canon.bookNumberToId(1)); // 'GEN'
console.log(Canon.bookNumberToId(40)); // 'MAT'

console.log(Canon.bookNumberToId('MAT')); // 40

console.log(Canon.bookNumberToEnglishName(1)); // 'Genesis'

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

console.log(Canon.isBookIdValid('MAT')); // true

console.log(Canon.isBookNT('MAT')); // true
console.log(Canon.isBookNT(1)); // false

console.log(Canon.isBookOT('MAT')); // false
console.log(Canon.isBookOT(1)); // true

console.log(Canon.isBookOTNT('MAT')); // true
console.log(Canon.isBookOTNT(1)); // true

console.log(Canon.isBookDC('TOB')); // true
console.log(Canon.isBookDC(1)); // false

console.log(Canon.isCanonical('XXA')); // false
console.log(Canon.isCanonical(1)); // true

console.log(Canon.isExtraMaterial('XXA')); // true
console.log(Canon.isExtraMaterial(1)); // false

console.log(Canon.isObsolete(87)); // true
```

Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sillsdev/scripture",
"version": "1.2.0",
"version": "1.3.0",
"description": "TypeScript partial port of `libpalaso/SIL.Scripture`",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
Expand Down
79 changes: 79 additions & 0 deletions src/canon.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,62 @@
import { Canon } from './canon';

describe('Canon', () => {
describe('isBookNT()', () => {
it("should return whether it's NT or not", () => {
let isBookNT = Canon.isBookNT(1);
expect(isBookNT).toBe(false);
isBookNT = Canon.isBookNT('GEN');
expect(isBookNT).toBe(false);
isBookNT = Canon.isBookNT(42);
expect(isBookNT).toBe(true);
isBookNT = Canon.isBookNT('MAT');
expect(isBookNT).toBe(true);
});
});

describe('isBookOT()', () => {
it("should return whether it's OT or not", () => {
let isBookOT = Canon.isBookOT(1);
expect(isBookOT).toBe(true);
isBookOT = Canon.isBookOT('GEN');
expect(isBookOT).toBe(true);
isBookOT = Canon.isBookOT(42);
expect(isBookOT).toBe(false);
isBookOT = Canon.isBookOT('MAT');
expect(isBookOT).toBe(false);
});
});

describe('isBookDC()', () => {
it("should return whether it's Deutero Canon or not", () => {
let isBookDC = Canon.isBookDC(66);
expect(isBookDC).toBe(false);
isBookDC = Canon.isBookDC('REV');
expect(isBookDC).toBe(false);
isBookDC = Canon.isBookDC(67);
expect(isBookDC).toBe(true);
isBookDC = Canon.isBookDC('TOB');
expect(isBookDC).toBe(true);
});
});

describe('allBookNumbers()', () => {
it('should yield each book number', () => {
const iterator = Canon.allBookNumbers();
expect(iterator.next().value).toEqual(1);
expect(iterator.next().value).toEqual(2);
expect(iterator.next().value).toEqual(3);
});
});

describe('extraBooks()', () => {
it('should return array of extra book IDs', () => {
const extraBooks = Canon.extraBooks();
expect(extraBooks[0]).toEqual('XXA');
expect(extraBooks.length).toEqual(7);
});
});

describe('bookNumberToId()', () => {
it('should return bookId', () => {
const bookId = Canon.bookNumberToId(1);
Expand Down Expand Up @@ -32,6 +88,29 @@ describe('Canon', () => {
});
});

describe('isCanonical()', () => {
it("should return whether it's canonical or not", () => {
// `num` overload is tested in `isBookDC()`.
let isCanonical = Canon.isCanonical('GEN');
expect(isCanonical).toBe(true);
isCanonical = Canon.isCanonical('XXA');
expect(isCanonical).toBe(false);
});
});

describe('isExtraMaterial()', () => {
it("should return whether it's extra material or not", () => {
let isExtraMaterial = Canon.isExtraMaterial(1);
expect(isExtraMaterial).toBe(false);
isExtraMaterial = Canon.isExtraMaterial('GEN');
expect(isExtraMaterial).toBe(false);
isExtraMaterial = Canon.isExtraMaterial(93);
expect(isExtraMaterial).toBe(true);
isExtraMaterial = Canon.isExtraMaterial('XXA');
expect(isExtraMaterial).toBe(true);
});
});

describe('isObsolete()', () => {
it("should return whether it's obsolete or not", () => {
let isObsolete = Canon.isObsolete(1);
Expand Down
Loading

0 comments on commit 0fb7661

Please sign in to comment.