26 lines
773 B
JavaScript
26 lines
773 B
JavaScript
const SHARED_GAME_CHAPTERS = new Set([1])
|
|
|
|
function normalizeChapterNumber(value) {
|
|
const number = Number(value)
|
|
if (!Number.isFinite(number)) return 1
|
|
return Math.min(15, Math.max(1, Math.floor(number)))
|
|
}
|
|
|
|
function chapterPackageRoot(value) {
|
|
const chapter = normalizeChapterNumber(value)
|
|
if (SHARED_GAME_CHAPTERS.has(chapter)) return 'package-game'
|
|
return `package-chapter-${String(chapter).padStart(2, '0')}`
|
|
}
|
|
|
|
function chapterRoute(value, options = {}) {
|
|
const chapter = normalizeChapterNumber(value)
|
|
const replay = options && options.replay === true ? '&replay=1' : ''
|
|
return `/${chapterPackageRoot(chapter)}/pages/chapter/chapter?chapter=${chapter}${replay}`
|
|
}
|
|
|
|
module.exports = {
|
|
normalizeChapterNumber,
|
|
chapterPackageRoot,
|
|
chapterRoute,
|
|
}
|