Skip to content

Commit

Permalink
feat(helper): ✨ cleanup chapter titles with underscore
Browse files Browse the repository at this point in the history
such as "Chapter_01"
  • Loading branch information
djdembeck committed Dec 18, 2023
1 parent e4b7fcd commit 7ff0148
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/helpers/books/audible/ChapterHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class ChapterHelper {
let chapterTitle = strippedTitle
// Check if title is just numbers
const isNotNumber = isNaN(Number(strippedTitle))
// Check if title has an underscore between Chapter and number
const hasUnderscore = strippedTitle.includes('_')
if (!isNotNumber && strippedTitle.length <= 3) {
// Remove trailing period in some cases
const stripPeriod: string = strippedTitle
Expand All @@ -67,7 +69,11 @@ class ChapterHelper {
// Convert back to string for concat
const strTitle: string = numTitle.toString()
chapterTitle = `${chapterNameLocale} ${strTitle}`
}
} else if (hasUnderscore) {
const splitTitle = strippedTitle.split('_')
const numTitle = splitTitle[1]
chapterTitle = `${chapterNameLocale} ${numTitle}`
}

return chapterTitle
}
Expand Down
2 changes: 2 additions & 0 deletions tests/helpers/books/audible/ChapterHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ describe('ChapterHelper should', () => {
expect(helper.chapterTitleCleanup('Chapter 1.')).toBe('Chapter 1')
// Title with just a number is changed
expect(helper.chapterTitleCleanup('123')).toBe('Chapter 123')
// Title with an underscore is changed
expect(helper.chapterTitleCleanup('Chapter_1')).toBe('Chapter 1')
})

test('sign request', () => {
Expand Down

0 comments on commit 7ff0148

Please sign in to comment.