From 5c4c3e1b37d0f70cb49dfc9b1b7cdaf323e07f65 Mon Sep 17 00:00:00 2001 From: idontreallywolf Date: Wed, 16 Apr 2025 15:48:22 +0200 Subject: [PATCH 1/5] setup unit test wf --- .github/workflows/test.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..8347bed --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: Run Unit Tests + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Install dependencies + run: npm clean install + + - name: Run tests + run: npm test From fa2eea0763d4f54b1d845314db949cf9450eea41 Mon Sep 17 00:00:00 2001 From: idontreallywolf Date: Wed, 16 Apr 2025 15:50:13 +0200 Subject: [PATCH 2/5] change wf cmd --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8347bed..09c15e5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: node-version: 20 - name: Install dependencies - run: npm clean install + run: npm ci - name: Run tests run: npm test From aeed99c2b8ab4792b203037008d32ce30fbd8619 Mon Sep 17 00:00:00 2001 From: idontreallywolf Date: Fri, 18 Apr 2025 16:45:54 +0200 Subject: [PATCH 3/5] bugfix and refactor replaceRomanNumbers fn --- package.json | 2 +- src/index.ts | 38 ++++++++++++++++++++++++++++---------- test/app.test.ts | 13 ++++++++++++- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 5cc6382..02ea20f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@idrw/bible-ref-parser", - "version": "1.0.0", + "version": "1.0.1", "main": "./build/index.js", "type": "module", "scripts": { diff --git a/src/index.ts b/src/index.ts index ec03ebc..617c57b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -72,24 +72,42 @@ function parseBook(query: string): BookData | null { function replaceRomanNumbers(query: string) { - let romanNumber = 0 - let idx + const edgeCases = [ + { words: ["isamuel", "isam", "ism"], sliceAt: 1 }, + { words: ["isaiah", "isa", "is"], sliceAt: 0 } + ] - for (let i = 0; i < query.length; i++) { - if (query[i] === "I") { - romanNumber += 1 - continue + for (const edgeCase of edgeCases) { + for (const word of edgeCase.words) { + if (query.toLowerCase().startsWith(word)) { + const ordinal = edgeCase.sliceAt === 0 ? "" : "1 " + return `${ordinal}${query.slice(edgeCase.sliceAt)}` + } } + } + + let romanNumber = "" + let idx - idx = (query[i] === " ") ? (i + 1) : i - break + const ordinals = [ + { text: "iii", properOrd: "3", endPosition: 3 }, + { text: "ii", properOrd: "2", endPosition: 2 }, + { text: "i", properOrd: "1", endPosition: 1 }, + ] + + for (const ord of ordinals) { + if (query.toLowerCase().startsWith(ord.text)) { + idx = ord.endPosition + romanNumber += ord.properOrd + break + } } - if (romanNumber === 0) { + if (romanNumber === "") { return query } - return `${romanNumber} ${query.slice(idx)}` + return `${romanNumber} ${query.slice(idx).trim()}` } diff --git a/test/app.test.ts b/test/app.test.ts index 7c7ae3e..2dd5a88 100644 --- a/test/app.test.ts +++ b/test/app.test.ts @@ -57,7 +57,10 @@ test('replaceRomanNumbers() should replace "I" with 1, "II" with 2 and "III" wit { input: "II Kings", expected: "2 Kings" }, { input: "III John", expected: "3 John" }, - { input: "IIJohn", expected: "2 John" } + { input: "IIJohn", expected: "2 John" }, + { input: "Isaiah", expected: "Isaiah" }, + { input: "Isamuel", expected: "1 samuel" }, + { input: "isAmUeL", expected: "1 sAmUeL" } ] for (const { input, expected } of cases) { @@ -72,6 +75,9 @@ test('replaceRomanNumbers() should return the original string if no book number { input: "Timothy", expected: "Timothy" }, { input: "John", expected: "John" }, { input: "Thessalonians", expected: "Thessalonians" }, + { input: "isaiah", expected: "isaiah" }, + { input: "isa", expected: "isa" }, + { input: "is", expected: "is" }, ] for (const { input, expected } of cases) { @@ -276,6 +282,11 @@ test('parseBook() should return the expected bookData', async (t) => { { input: "1st John", expected: { name: "1 John", references: [] } }, { input: "first JOHN", expected: { name: "1 John", references: [] } }, { input: "2ndtim", expected: { name: "2 Timothy", references: [] } }, + { input: "isa", expected: { name: "Isaiah", references: [] } }, + { input: "isam", expected: { name: "1 Samuel", references: [] } }, + { input: "Ism", expected: { name: "1 Samuel", references: [] } }, + { input: "IIsm", expected: { name: "2 Samuel", references: [] } }, + { input: "iSaIAH", expected: { name: "Isaiah", references: [] } }, ] for (const { input, expected } of cases) { From 164ef600ab9ddb4e7ce67e5fe17b21d57c644c00 Mon Sep 17 00:00:00 2001 From: idontreallywolf Date: Fri, 18 Apr 2025 16:46:00 +0200 Subject: [PATCH 4/5] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a17e6eb..3bde866 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## Installation ```bash -npm install bible-ref-parser +npm install @idrw/bible-ref-parser ``` ## Usage From 6669e67eae23d06b8f36ee762dfabcfd56b679cf Mon Sep 17 00:00:00 2001 From: idontreallywolf Date: Fri, 18 Apr 2025 16:46:54 +0200 Subject: [PATCH 5/5] .