Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EpubParser

Hierarchy

Index

Constructors

constructor

  • Create new EpubParser

    throws

    {Errors.ENOENT} no such file or directory

    throws

    {Errors.EINVAL} invalid input

    example

    new EpubParser('./foo/bar.epub' or './foo/bar');

    Parameters

    • input: string

      file or directory

    • Optional cryptoProvider: CryptoProvider
    • Optional logLevel: string

    Returns EpubParser

Accessors

cryptoProvider

input

  • get input(): string

logger

onProgress

  • get onProgress(): (step: number, totalStep: number, action: string) => void
  • set onProgress(arg: (step: number, totalStep: number, action: string) => void): any
  • Get onProgress callback

    Returns (step: number, totalStep: number, action: string) => void

      • (step: number, totalStep: number, action: string): void
      • Parameters

        • step: number
        • totalStep: number
        • action: string

        Returns void

  • Set callback that tells progress of parse and readItems.

    example

    parser.onProgress = (step, totalStep, action) => { console.log([${action}] ${step} / ${totalStep}); }

    see

    Parser.Action

    Parameters

    • arg: (step: number, totalStep: number, action: string) => void
        • (step: number, totalStep: number, action: string): void
        • Parameters

          • step: number
          • totalStep: number
          • action: string

          Returns void

    Returns any

Static parseDefaultOptions

  • get parseDefaultOptions(): { additionalInlineStyle: any; allowNcxFileMissing: boolean; overwrite: boolean; parseStyle: boolean; styleNamespacePrefix: string; unzipPath: string; validatePackage: boolean }
  • Get default values of parse options

    Returns { additionalInlineStyle: any; allowNcxFileMissing: boolean; overwrite: boolean; parseStyle: boolean; styleNamespacePrefix: string; unzipPath: string; validatePackage: boolean }

    • additionalInlineStyle: any
    • allowNcxFileMissing: boolean
    • overwrite: boolean
    • parseStyle: boolean
    • styleNamespacePrefix: string
    • unzipPath: string
    • validatePackage: boolean

Static parseOptionTypes

  • get parseOptionTypes(): { additionalInlineStyle: string; allowNcxFileMissing: string; overwrite: string; parseStyle: string; styleNamespacePrefix: string; unzipPath: string; validatePackage: string }
  • Get types of parse options

    Returns { additionalInlineStyle: string; allowNcxFileMissing: string; overwrite: string; parseStyle: string; styleNamespacePrefix: string; unzipPath: string; validatePackage: string }

    • additionalInlineStyle: string
    • allowNcxFileMissing: string
    • overwrite: string
    • parseStyle: string
    • styleNamespacePrefix: string
    • unzipPath: string
    • validatePackage: string

Static readDefaultOptions

  • get readDefaultOptions(): { force: boolean } & { basePath: string; extractBody: boolean; ignoreScript: boolean; removeAtrules: string[]; removeClassSelector: string[]; removeIdSelector: string[]; removeTagSelector: string[]; serializedAnchor: boolean }
  • Get default values of read options

    Returns { force: boolean } & { basePath: string; extractBody: boolean; ignoreScript: boolean; removeAtrules: string[]; removeClassSelector: string[]; removeIdSelector: string[]; removeTagSelector: string[]; serializedAnchor: boolean }

Static readOptionTypes

  • get readOptionTypes(): { force: string } & { basePath: string; extractBody: string; ignoreScript: string; removeAtrules: string; removeClassSelector: string; removeIdSelector: string; removeTagSelector: string; serializedAnchor: string }
  • Get types of read option

    Returns { force: string } & { basePath: string; extractBody: string; ignoreScript: string; removeAtrules: string; removeClassSelector: string; removeIdSelector: string; removeTagSelector: string; serializedAnchor: string }

Methods

_checkResult

  • _checkResult(book: EpubBook): EpubBook
  • Parameters

    • book: EpubBook

    Returns EpubBook

Protected _createBook

Protected _getBookClass

  • _getBookClass(): {}

Protected _getParseContextClass

  • _getParseContextClass(): {}

Protected _getReadContextClass

  • _getReadContextClass(): {}

Protected _getReadItemClass

  • _getReadItemClass(): {}

Protected _parseAfterTasks

  • _parseAfterTasks(): Task[]

Protected _parseBeforeTasks

  • _parseBeforeTasks(): Task[]

_parseGuide

  • Guide parsing in OPF

    Parameters

    Returns Promise<EpubParseContext>

    return Context containing guide

_parseManifestAndSpine

  • Manifest and spine parsing in OPF

    see

    EpubParser.parseDefaultOptions.parseStyle

    see

    EpubParser.parseDefaultOptions.styleNamespacePrefix

    Parameters

    • manifest: object

      manifest AST

    • spine: object

      spine AST

    • context: EpubParseContext

      intermediate result

    Returns Promise<EpubParseContext>

    return Context containing manifest and spine

_parseMetaInf

  • Locate OPF and base path in container.xml

    throws

    {Errors.ENOFILE} container.xml not found

    throws

    {Errors.EINVAL} invalid XML

    throws

    {Errors.ENOELMT} no such element in container.xml

    throws

    {Errors.ENOATTR} no such attribute in element

    Parameters

    Returns Promise<EpubParseContext>

    return Context containing OPF and base path

_parseMetadata

  • Metadata parsing in OPF

    Parameters

    Returns Promise<EpubParseContext>

    return Context containing metadata

_parseNcx

  • NCX parsing

    throws

    {Errors.EINVAL} invalid XML

    throws

    {Errors.EINVAL} can not found ncx attribute OPF

    throws

    {Errors.ENOFILE} NCX not found

    throws

    {Errors.ENOELMT} no such element in NCX

    see

    EpubParser.parseDefaultOptions.allowNcxFileMissing

    Parameters

    Returns Promise<EpubParseContext>

    return Context containing ncx if exists

_parseOpf

  • OPF parsing

    throws

    {Errors.EINVAL} invalid xml

    throws

    {Errors.ENOFILE} OPF not found

    throws

    {Errors.ENOELMT} no such element in OPF

    Parameters

    Returns Promise<EpubParseContext>

    return Context containing OPF parsing result

_parseSpineStyle

  • _parseSpineStyle(rawItem: object, entry: object, options: object): { inlineStyles: object[]; styles: string[] }
  • see

    EpubParser.parseDefaultOptions.styleNamespacePrefix

    see

    EpubParser.parseDefaultOptions.additionalInlineStyle

    Parameters

    • rawItem: object
    • entry: object

      spine entry

    • options: object

      parse options

    Returns { inlineStyles: object[]; styles: string[] }

    returns styles and inline style from spine

    • inlineStyles: object[]

      inline styles included in Spine

    • styles: string[]

      path of styles linked to spine

Protected _parseTasks

  • _parseTasks(): Task[]

_prepareParse

_prepareRead

  • Validate read options and get entries from input

    async
    throws

    {Errors.EINVAL} invalid options or value type

    throws

    {Errors.ENOENT} no such file or directory

    throws

    {Errors.ENOFILE} no such file

    Parameters

    Returns Promise<BaseReadContext>

    returns Context containing target items, read options, entries

_read

  • _read(context: any): Promise<Array<string | Buffer>>
  • Contents is read using loader suitable for context

    async
    override
    throws

    {Errors.ENOFILE} no such file

    see

    Parser.readDefaultOptions.force

    Parameters

    • context: any

      properties required for reading

    Returns Promise<Array<string | Buffer>>

    reading results

Protected _readAfterTasks

  • _readAfterTasks(): Task[]

Protected _readBeforeTasks

  • _readBeforeTasks(): Task[]

Protected _readTasks

  • _readTasks(): Task[]

_unzipIfNeeded

_validatePackageIfNeeded

  • Validate package spec if zip source and validatePackage option specified

    throws

    {Errors.EINVAL} invalid package

    see

    EpubParser.parseDefaultOptions.validatePackage

    Parameters

    Returns Promise<EpubParseContext>

    return Context (no change at this step)

getItemTypeFromMediaType

parse

readItem

readItems

unzip

  • unzip(unzipPath: string, overwrite?: boolean): Promise<boolean>
  • Unzip

    async
    throws

    {Errors.EINVAL} invalid options or value type

    throws

    {Errors.ENOENT} no such file or directory

    throws

    {Errors.ENOFILE} no such file

    Parameters

    • unzipPath: string
    • Optional overwrite: boolean

    Returns Promise<boolean>

    success

Generated using TypeDoc