Skip to content

Commit

Permalink
Fix VerseRef.equals()
Browse files Browse the repository at this point in the history
- add a test
- prettier dist *.d.ts files
- also fix some 2x security vulnerabilities
  • Loading branch information
irahopkinson committed Jul 3, 2023
1 parent 59cbb54 commit 9d59230
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 105 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
dist/**
!dist/**/*.d.ts
coverage
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"fileMatch": ["*tsconfig*.json"],
"url": "http://json.schemastore.org/tsconfig"
}
]
],
"cSpell.words": ["Parseable"]
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ TypeScript partial port of C# library [libpalaso/SIL.Scripture][github-libpalaso

- {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 single references and ranges, such as: GEN 2:3, LUK 3:4b-5a
- Represents a single reference, e.g. GEN 2:3
- Represents a reference range, e.g. LUK 3:4b-5a
- Supports versification types: Unknown, Original, Septuagint, Vulgate, English, RussianProtestant, RussianOrthodox.

## Installation
Expand Down
116 changes: 58 additions & 58 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "@sillsdev/scripture",
"version": "1.1.0",
"version": "1.1.1",
"description": "TypeScript partial port of `libpalaso/SIL.Scripture`",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "jest",
"build": "tsc --project tsconfig.build.json && vite build && dts-bundle-generator --config ./dts-bundle-generator.config.ts",
"build": "tsc --project tsconfig.build.json && vite build && dts-bundle-generator --config ./dts-bundle-generator.config.ts && npm run prettier:dts",
"prepare": "npm run build",
"prettier": "prettier --write \"**/*.{ts,js,json,md,yml}\"",
"prettier:dts": "prettier --write \"dist/**/*.d.ts\"",
"prettier:ci": "prettier --list-different \"**/*.{ts,js,json,md,yml}\"",
"test:ci": "jest --config jest.config.js --ci --reporters=jest-junit --coverage",
"lint": "eslint . --max-warnings 0"
Expand All @@ -32,8 +33,8 @@
"homepage": "https://github.com/sillsdev/scripture#readme",
"devDependencies": {
"@types/jest": "^29.5.2",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"@typescript-eslint/eslint-plugin": "^5.60.1",
"@typescript-eslint/parser": "^5.60.1",
"dts-bundle-generator": "^7.2.0",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
Expand Down
9 changes: 5 additions & 4 deletions src/canon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ export class Canon {
/**
* Gets the 1-based number of the specified book
* This is a fairly performance-critical method.
* @param string id
* @param boolean ignoreCase
* @param id - book ID
* @param ignoreCase - should case be ignored. Defaults to `true`.
* @returns book number, or 0 if id doesn't exist
*/
static bookIdToNumber(id: string, ignoreCase = true): number {
Expand All @@ -337,8 +337,9 @@ export class Canon {

/**
* Gets the id if a book based on its 1-based number
* @param number number Book number (this is 1-based, not an index)
* @param string errorValue The string to return if the book number does not correspond to a valid book
* @param number - Book number (this is 1-based, not an index)
* @param errorValue - The string to return if the book number does not correspond to a valid book.
* Defaults to `'***'`.
*/
static bookNumberToId(number: number, errorValue = '***'): string {
const index: number = number - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { BookSet } from './book-set';
export { Canon } from './canon';
export { ScrVers } from './scr-vers';
export { VerseRef, VerseRefException, ValidStatusType } from './verse-ref';
export { VerseRef, VerseRefException } from './verse-ref';
export { ScrVersType } from './versification';
18 changes: 17 additions & 1 deletion src/verse-ref.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ScrVers } from './scr-vers';
import { VerseRef } from './verse-ref';

describe('VerseRef constructor', () => {
describe('VerseRef Constructor', () => {
const RTL_MARKER = '\u200F';

it('should construct with versification', () => {
const vref = new VerseRef(1, 2, 3, ScrVers.Septuagint);
expect(vref.valid).toBe(true);
Expand Down Expand Up @@ -54,4 +56,18 @@ describe('VerseRef constructor', () => {
expect(vref.allVerses().length).toEqual(2);
expect(vref.versification).toEqual(ScrVers.Vulgate);
});

it('should construct with a verse range and removes RTL marker', () => {
const vref = new VerseRef('LUK', '3', '4b' + RTL_MARKER + '-5a', ScrVers.Vulgate);
expect(vref.valid).toBe(true);
expect(vref.BBBCCCVVV).toEqual(42003004);
// expect(vref.BBBCCCVVVS).toEqual('042003004b');
expect(vref.bookNum).toEqual(42);
expect(vref.chapterNum).toEqual(3);
expect(vref.verseNum).toEqual(4);
expect(vref.verse).toEqual('4b-5a');
// expect(vref.segment()).toEqual('b');
expect(vref.allVerses().length).toEqual(2);
expect(vref.versification).toEqual(ScrVers.Vulgate);
});
});
Loading

0 comments on commit 9d59230

Please sign in to comment.