Skip to main content

Parse a string representing page sequence with support for merged pages, ignored pages, and ranges of pages in decimal, letters and roman.

JSR Score
88%
Published
3 months ago (1.3.2)
class PageSequence

A page sequence is a string describing the numeration of every page in a PDF. The number written on the page is considered a label.

The index is the number of the page in the PDF. (Starting with 0)

If pages for example has been duplicated, it is possible to ignore them by prefixing the section with a !

Pages in the PDF that has mor than one real page, ans therefor more than one label, can be described be using | between 2 labels.

Labels for pages following each other is separated by ,

Enumerations can be described by a range separated by -

The following enumerations are supported:

  • Number: E.g 1-12 and 2-7
  • Letters, E.g A-C and B-H
  • Roman: E.g I-III and IV-XII

Examples of page sequences:

  • 1-8
  • 1-3, A, B, 4-6
  • 1-5|6-8
  • 1-5,i-iv,6-16
  • Frontpage|1-8
  • Appendix A - Appendix C
  • 1-3, !3, 4-16|17, I-VI, 18-20

Constructors

new
PageSequence(sequence: string, indexLengthAll?: number)

Properties

private
indexList: number[]
private
labelList: string[]
private
labelMap: Map<string, { index: number; label: string; }>

key: label.toLowerCase()

Methods

Length of used PDF-pages. Excludes ignored pages.

Length of PDF. Includes ignored pages. Used to verify length of PDF

getIndexList(pages?: string): number[] | undefined

Returns an array with index specified page labels. If pages is not specified, index for every page in the PDF. Excludes ignored pages.

Number of real pages. Exclude ignored pages.

getLabelList(pages?: string): string[] | undefined

An array with label for every page. Excludes ignored pages.

private
parseLabel(part: string): ParsedLabel

Static Methods

create(...args: ConstructorParameters<PageSequence>): PageSequence | undefined

Add Package

deno add @tvartom/pagesequence

Import symbol

import { PageSequence } from "@tvartom/pagesequence";

Add Package

npx jsr add @tvartom/pagesequence

Import symbol

import { PageSequence } from "@tvartom/pagesequence";

Add Package

yarn dlx jsr add @tvartom/pagesequence

Import symbol

import { PageSequence } from "@tvartom/pagesequence";

Add Package

pnpm dlx jsr add @tvartom/pagesequence

Import symbol

import { PageSequence } from "@tvartom/pagesequence";

Add Package

bunx jsr add @tvartom/pagesequence

Import symbol

import { PageSequence } from "@tvartom/pagesequence";