MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / parsePDFPageRange

Function parsePDFPageRange

source code/utils/pdfUtils.ts:18–52  ·  view source on GitHub ↗
(
  pages: string,
)

Source from the content-addressed store, hash-verified

16 * Pages are 1-indexed.
17 */
18export function parsePDFPageRange(
19 pages: string,
20): { firstPage: number; lastPage: number } | null {
21 const trimmed = pages.trim()
22 if (!trimmed) {
23 return null
24 }
25
26 // "N-" open-ended range
27 if (trimmed.endsWith('-')) {
28 const first = parseInt(trimmed.slice(0, -1), 10)
29 if (isNaN(first) || first < 1) {
30 return null
31 }
32 return { firstPage: first, lastPage: Infinity }
33 }
34
35 const dashIndex = trimmed.indexOf('-')
36 if (dashIndex === -1) {
37 // Single page: "5"
38 const page = parseInt(trimmed, 10)
39 if (isNaN(page) || page < 1) {
40 return null
41 }
42 return { firstPage: page, lastPage: page }
43 }
44
45 // Range: "1-10"
46 const first = parseInt(trimmed.slice(0, dashIndex), 10)
47 const last = parseInt(trimmed.slice(dashIndex + 1), 10)
48 if (isNaN(first) || isNaN(last) || first < 1 || last < 1 || last < first) {
49 return null
50 }
51 return { firstPage: first, lastPage: last }
52}
53
54/**
55 * Check if PDF reading is supported with the current model.

Callers 2

validateInputFunction · 0.85
callInnerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected