Skip to main content

@storyteller-platform/epub API

Epub

Defined in: libraries/epub/index.ts:267

A single EPUB instance.

The entire EPUB contents will be read into memory.

Example usage:

import {
Epub,
getBody,
findByName,
textContent,
} from "@storyteller-platform/epub"

const epub = await Epub.from("./path/to/book.epub")
const title = await epub.getTitle()
const spineItems = await epub.getSpineItems()
const chptOne = spineItems[0]
const chptOneXml = await epub.readXhtmlItemContents(chptOne.id)

const body = getBody(chptOneXml)
const h1 = Epub.findXmlChildByName("h1", body)
const headingText = textContent(h1)

await epub.setTitle(headingText)
await epub.writeToFile("./path/to/updated.epub")
await epub.close()

https://www.w3.org/TR/epub-33/

Constructors

Constructor

new Epub(adapterClass, adapter, inputPath, readonlyOverride): Epub

Defined in: libraries/epub/index.ts:533

Prefer the static factories (Epub.using, Epub.from, Epub.create, Epub.upgrade) over calling this constructor directly. It's public so EpubFactory can construct instances; nothing else should need to.

Parameters
ParameterTypeDefault value
adapterClassEpubStorageAdapterClassundefined
adapterEpubStorageAdapterundefined
inputPathundefined | stringundefined
readonlyOverridebooleanfalse
Returns

Epub

Properties

adapter

protected adapter: EpubStorageAdapter

Defined in: libraries/epub/index.ts:535

adapterClass

protected adapterClass: EpubStorageAdapterClass

Defined in: libraries/epub/index.ts:534

inputPath

protected inputPath: undefined | string

Defined in: libraries/epub/index.ts:536

readonlyOverride

protected readonlyOverride: boolean = false

Defined in: libraries/epub/index.ts:537

storage

readonly storage: EpubStorageKind

Defined in: libraries/epub/index.ts:525

Storage backend kind in use for this instance

Public so callers can declare type-level requirements via InMemoryEpubReader Orthogonal to the read-only / writable axis (controlled by readonlyOverride and the adapter's capability bag)

xhtmlBuilder

static xhtmlBuilder: XMLBuilder

Defined in: libraries/epub/index.ts:315

xhtmlParser

static xhtmlParser: XMLParser

Defined in: libraries/epub/index.ts:275

xmlBuilder

static xmlBuilder: XMLBuilder

Defined in: libraries/epub/index.ts:308

xmlParser

static xmlParser: XMLParser

Defined in: libraries/epub/index.ts:268

Methods

[dispose]()

[dispose](): void

Defined in: libraries/epub/index.ts:3461

Returns

void

addCollection()

addCollection(collection, index?): Promise<void>

Defined in: libraries/epub/index.ts:2159

Add a collection to the EPUB metadata.

If index is provided, the collection will be placed at that index in the list of collections. Otherwise, it will be added to the end of the list.

Parameters
ParameterType
collectionCollection
index?number
Returns

Promise<void>

addContributor()

addContributor(contributor, index?): Promise<void>

Defined in: libraries/epub/index.ts:2504

Add a contributor to the EPUB metadata.

If index is provided, the creator will be placed at that index in the list of creators. Otherwise, it will be added to the end of the list.

This is a convenience method for epub.addCreator(contributor, index, 'contributor').

Parameters
ParameterType
contributorDcCreator
index?number
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dccreator

addCreator()

addCreator(creator, index?, type?): Promise<void>

Defined in: libraries/epub/index.ts:2349

Add a creator to the EPUB metadata.

If index is provided, the creator will be placed at that index in the list of creators. Otherwise, it will be added to the end of the list.

Parameters
ParameterTypeDefault value
creatorDcCreatorundefined
index?numberundefined
type?"creator" | "contributor""creator"
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dccreator

addManifestItem()

Call Signature

addManifestItem(item, contents, encoding): Promise<void>

Defined in: libraries/epub/index.ts:3047

Create a new manifest item and write its contents to a new entry.

Parameters
ParameterTypeDescription
itemManifestItem-
contentsParsedXmlThe new contents. May be either a parsed XML tree or a unicode string, as determined by the as argument.
encoding"xml"Optional - whether to interpret contents as a parsed XML tree, a unicode string, or a byte array. Defaults to a byte array.
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-pkg-manifest

https://www.w3.org/TR/epub-33/#sec-contentdocs

Call Signature

addManifestItem(item, contents, encoding): Promise<void>

Defined in: libraries/epub/index.ts:3052

Create a new manifest item and write its contents to a new entry.

Parameters
ParameterTypeDescription
itemManifestItem-
contentsstringThe new contents. May be either a parsed XML tree or a unicode string, as determined by the as argument.
encoding"utf-8"Optional - whether to interpret contents as a parsed XML tree, a unicode string, or a byte array. Defaults to a byte array.
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-pkg-manifest

https://www.w3.org/TR/epub-33/#sec-contentdocs

Call Signature

addManifestItem(item, contents): Promise<void>

Defined in: libraries/epub/index.ts:3057

Create a new manifest item and write its contents to a new entry.

Parameters
ParameterTypeDescription
itemManifestItem-
contentsUint8ArrayThe new contents. May be either a parsed XML tree or a unicode string, as determined by the as argument.
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-pkg-manifest

https://www.w3.org/TR/epub-33/#sec-contentdocs

addMetadata()

addMetadata(entry): Promise<void>

Defined in: libraries/epub/index.ts:3168

Add a new metadata entry to the Epub.

This method, like epub.getMetadata(), operates on metadata entries. For more useful semantic representations of metadata, use specific methods such as setTitle() and setLanguage().

Parameters
ParameterType
entryMetadataEntry
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-pkg-metadata

addSpineItem()

addSpineItem(manifestId, index?): Promise<void>

Defined in: libraries/epub/index.ts:2558

Add an item to the spine of the EPUB.

If index is undefined, the item will be added to the end of the spine. Otherwise it will be inserted at the specified index.

If the manifestId does not correspond to an item in the manifest, this will throw an error.

Parameters
ParameterType
manifestIdstring
index?number
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-spine-elem

addSubject()

addSubject(subject): Promise<void>

Defined in: libraries/epub/index.ts:1688

Add a subject to the EPUB metadata.

Parameters
ParameterTypeDescription
subjectstring | DcSubjectMay be a string representing just a schema-less subject name, or a DcSubject object
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dcsubject

copy()

copy(path?): Promise<Epub>

Defined in: libraries/epub/index.ts:630

Parameters
ParameterType
path?string
Returns

Promise<Epub>

createXhtmlDocument()

createXhtmlDocument(body, head?, language?): Promise<(XmlElement<"?xml"> | XmlElement<"html">)[]>

Defined in: libraries/epub/index.ts:2864

Create a new XHTML document with the given body and head.

Parameters
ParameterTypeDescription
bodyParsedXmlThe XML nodes to place in the body of the document
head?ParsedXmlOptional - the XMl nodes to place in the head
language?LocaleOptional - defaults to the EPUB's language
Returns

Promise<(XmlElement<"?xml"> | XmlElement<"html">)[]>

discardAndClose()

discardAndClose(): void

Defined in: libraries/epub/index.ts:3411

Returns

void

findAllMetadataItems()

findAllMetadataItems(predicate): Promise<object[]>

Defined in: libraries/epub/index.ts:895

Returns the item in the metadata element's children array that matches the provided predicate.

Parameters
ParameterType
predicate(entry) => boolean
Returns

Promise<object[]>

findMetadataItem()

findMetadataItem(predicate): Promise<null | { id: undefined | string; properties: {[k: string]: string; }; type: `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}` | `?${string}`; value: undefined | string; }>

Defined in: libraries/epub/index.ts:886

Returns the item in the metadata element's children array that matches the provided predicate.

Parameters
ParameterType
predicate(entry) => boolean
Returns

Promise<null | { id: undefined | string; properties: {[k: string]: string; }; type: `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}` | `?${string}`; value: undefined | string; }>

getBaseDirection()

getBaseDirection(): Promise<"auto" | "rtl" | "ltr">

Defined in: libraries/epub/index.ts:1642

Retrieve the base direction from the package element.

If there is no dir attribute on the package element, returns 'auto'.

Returns

Promise<"auto" | "rtl" | "ltr">

https://www.w3.org/TR/epub-33/#attrdef-dir

getCollections()

getCollections(): Promise<Collection[]>

Defined in: libraries/epub/index.ts:2119

Retrieve the list of collections.

Returns

Promise<Collection[]>

getContributors()

getContributors(): Promise<DcCreator[]>

Defined in: libraries/epub/index.ts:2336

Retrieve the list of contributors.

This is a convenience method for epub.getCreators('contributor').

Returns

Promise<DcCreator[]>

https://www.w3.org/TR/epub-33/#sec-opf-dccontributor

getCoverImage()

getCoverImage(): Promise<null | Uint8Array<ArrayBufferLike>>

Defined in: libraries/epub/index.ts:1538

Retrieve the cover image data as a byte array.

This does not include, for example, the cover image's filename or mime type. To retrieve the image manifest item, use epub.getCoverImageItem().

Returns

Promise<null | Uint8Array<ArrayBufferLike>>

https://www.w3.org/TR/epub-33/#sec-cover-image

getCoverImageItem()

getCoverImageItem(): Promise<null | ManifestItem>

Defined in: libraries/epub/index.ts:1519

Retrieve the cover image manifest item.

This does not return the actual image data. To retrieve the image data, pass this item's id to epub.readItemContents, or use epub.getCoverImage() instead.

Returns

Promise<null | ManifestItem>

https://www.w3.org/TR/epub-33/#sec-cover-image

getCreators()

getCreators(type): Promise<DcCreator[]>

Defined in: libraries/epub/index.ts:2272

Retrieve the list of creators.

Parameters
ParameterTypeDefault value
type"creator" | "contributor""creator"
Returns

Promise<DcCreator[]>

https://www.w3.org/TR/epub-33/#sec-opf-dccreator

getDescription()

getDescription(): Promise<null | string>

Defined in: libraries/epub/index.ts:1970

Retrieve the Epub's description as specified in its package document metadata.

If no description metadata is specified, returns null. Returns the description as a string. Descriptions may include HTML markup.

Returns

Promise<null | string>

getGuideEntries()

getGuideEntries(): Promise<GuideItem[]>

Defined in: libraries/epub/index.ts:3388

Retrieve the guide entries from the package document.

The guide element is deprecated in EPUB 3 in favor of the landmarks nav, but many publications still include it.

Returns

Promise<GuideItem[]>

getIdentifier()

getIdentifier(): Promise<null | string>

Defined in: libraries/epub/index.ts:993

Retrieve the first identifier from the dc:identifier element in the EPUB metadata.

If there is no dc:identifier element, returns null.

Returns

Promise<null | string>

https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier

Deprecated

Use getUniqueIdentifier instead to get the unique identifier, or getIdentifiers to get all identifiers.

getIdentifiers()

getIdentifiers(): Promise<EpubIdentifier[]>

Defined in: libraries/epub/index.ts:1168

Retrieve every dc:identifier entry, returned as found.

Values are not interpreted. Any refining identifier-type meta (spec D.3.8) or legacy opf:scheme attribute is surfaced on the entry, but no parsing of the value itself is attempted. To read dc:source entries, use getSources.

Returns

Promise<EpubIdentifier[]>

https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier

getItemArchiveLength()

getItemArchiveLength(id): Promise<number>

Defined in: libraries/epub/index.ts:672

Length of the underlying archive entry for a manifest item, in bytes Necessary to compute the readium page count which is for COMPRESSED content

Parameters
ParameterType
idstring
Returns

Promise<number>

See

https://github.com/readium/architecture/issues/123

getLandmarks()

getLandmarks(__namedParameters): Promise<null | Navigation>

Defined in: libraries/epub/index.ts:2737

Returns the structured landmarks navigation document as a Navigation object

Parameters
ParameterType
__namedParameters{ resolveToRoot?: boolean; }
__namedParameters.resolveToRoot?boolean
Returns

Promise<null | Navigation>

https://www.w3.org/TR/epub-33/#sec-nav-landmarks

getLanguage()

getLanguage(): Promise<null | Locale>

Defined in: libraries/epub/index.ts:1807

Retrieve the Epub's language as specified in its package document metadata.

If no language metadata is specified, returns null. Returns the language as an Intl.Locale instance.

Returns

Promise<null | Locale>

https://www.w3.org/TR/epub-33/#sec-opf-dclanguage

getLayout()

getLayout(): Promise<"pre-paginated" | "reflowable">

Defined in: libraries/epub/index.ts:1623

Retrieve the layout from the rendition:layout meta element in the EPUB metadata.

If there is no meta element, returns 'reflowable'.

Returns

Promise<"pre-paginated" | "reflowable">

https://www.w3.org/TR/epub-33/#layout

getManifest()

getManifest(): Promise<Record<string, ManifestItem>>

Defined in: libraries/epub/index.ts:811

Retrieve the manifest for the Epub.

This is represented as a map from each manifest items' id to the rest of its properties.

Returns

Promise<Record<string, ManifestItem>>

https://www.w3.org/TR/epub-33/#sec-pkg-manifest

getMetadata()

getMetadata(): Promise<EpubMetadata>

Defined in: libraries/epub/index.ts:962

Retrieve the metadata entries for the Epub.

This is represented as an array of metadata entries, in the order that they're presented in the Epub package document.

For more useful semantic representations of metadata, use specific methods such as getTitle() and getAuthors().

Returns

Promise<EpubMetadata>

https://www.w3.org/TR/epub-33/#sec-pkg-metadata

getModifiedDate()

getModifiedDate(): Promise<null | Date>

Defined in: libraries/epub/index.ts:1606

Retrieve the modified date from the dcterms:modified metadata in the EPUB metadata as a Date object.

If there is no meta element with dcterms:modified, returns null.

Returns

Promise<null | Date>

https://www.w3.org/TR/epub-33/#sec-metadata-last-modified

getNcxTableOfContents()

getNcxTableOfContents(): Promise<NavigationList>

Defined in: libraries/epub/index.ts:3293

Parse the NCX table of contents, if one exists, and return a tree of TocEntry nodes.

Useful for both EPUB 2 publications (where the NCX is the primary navigation) and EPUB 3 publications that retain an NCX for backwards compatibility.

Returns

Promise<NavigationList>

getPackageElement()

getPackageElement(): Promise<XmlElement<"package">>

Defined in: libraries/epub/index.ts:746

Returns

Promise<XmlElement<"package">>

getPackageVocabularyPrefixes()

getPackageVocabularyPrefixes(): Promise<Record<string, string>>

Defined in: libraries/epub/index.ts:1987

Return the set of custom vocabulary prefixes set on this publication's root package element.

Returns a map from prefix to URI

Returns

Promise<Record<string, string>>

https://www.w3.org/TR/epub-33/#sec-prefix-attr

getPageBreakSource()

getPageBreakSource(): Promise<null | EpubSource>

Defined in: libraries/epub/index.ts:1205

Retrieve the pageBreakSource property (EPUB 3.4, spec D.2.9), the publication-level source for the source of its page break markers.

This property replaces the refining source-of="pagination" meta (spec D.3.11), see EpubSource.sourceOf. If no pageBreakSource property is found, we fall back to finding a dc:source with a source-of="pagination" refinement.

Returns

Promise<null | EpubSource>

https://www.w3.org/TR/epub/#pageBreakSource

getPageList()

getPageList(__namedParameters): Promise<null | Navigation>

Defined in: libraries/epub/index.ts:2749

Returns the structured page list navigation document as a Navigation object

Parameters
ParameterType
__namedParameters{ resolveToRoot?: boolean; }
__namedParameters.resolveToRoot?boolean
Returns

Promise<null | Navigation>

https://www.w3.org/TR/epub-33/#sec-nav-landmarks

getPublicationDate()

getPublicationDate(): Promise<null | Date>

Defined in: libraries/epub/index.ts:1575

Retrieve the publication date from the dc:date element in the EPUB metadata as a Date object.

If there is no dc:date element, returns null.

Returns

Promise<null | Date>

https://www.w3.org/TR/epub-33/#sec-opf-dcdate

getRootfile()

getRootfile(): Promise<string>

Defined in: libraries/epub/index.ts:682

Returns

Promise<string>

getSources()

getSources(): Promise<EpubSource[]>

Defined in: libraries/epub/index.ts:1182

Retrieve every dc:source entry, returned as found.

Like getIdentifiers, values are not interpreted. In addition to a refining identifier-type, a refining source-of meta (spec D.3.11) is surfaced as sourceOf.

Returns

Promise<EpubSource[]>

https://www.w3.org/TR/epub-33/#sec-opf-dcsource

getSpineItems()

getSpineItems(): Promise<ManifestItem[]>

Defined in: libraries/epub/index.ts:2539

Retrieve the manifest items that make up the Epub's spine.

The spine specifies the order that the contents of the Epub should be displayed to users by default.

Returns

Promise<ManifestItem[]>

https://www.w3.org/TR/epub-33/#sec-spine-elem

getSubjects()

getSubjects(): Promise<(string | DcSubject)[]>

Defined in: libraries/epub/index.ts:1762

Retrieve the list of subjects for this EPUB.

Subjects without associated authority and term metadata will be returned as strings. Otherwise, they will be represented as DcSubject objects, with a value, authority, and term.

Returns

Promise<(string | DcSubject)[]>

https://www.w3.org/TR/epub-33/#sec-opf-dcsubject

getSubtitle()

getSubtitle(): Promise<null | string>

Defined in: libraries/epub/index.ts:1877

Retrieve the subtitle of the Epub, if it exists.

Returns

Promise<null | string>

https://www.w3.org/TR/epub-33/#sec-opf-dctitle

getTableOfContents()

getTableOfContents(__namedParameters): Promise<null | Navigation>

Defined in: libraries/epub/index.ts:2720

Returns the structured table of contents navigation document as a Navigation object.

Parameters
ParameterType
__namedParameters{ resolveToRoot?: boolean; }
__namedParameters.resolveToRoot?boolean
Returns

Promise<null | Navigation>

https://www.w3.org/TR/epub-33/#sec-nav-toc

getTitle()

getTitle(expanded): Promise<null | string>

Defined in: libraries/epub/index.ts:1853

Retrieve the title of the Epub.

Parameters
ParameterTypeDefault value
expandedbooleanfalse
Returns

Promise<null | string>

https://www.w3.org/TR/epub-33/#sec-opf-dctitle

getTitles()

getTitles(): Promise<object[]>

Defined in: libraries/epub/index.ts:1889

Retrieve all title entries of the Epub.

Returns

Promise<object[]>

https://www.w3.org/TR/epub-33/#sec-opf-dctitle

getType()

getType(): Promise<null | MetadataEntry>

Defined in: libraries/epub/index.ts:1675

Retrieve the publication type from the dc:type element in the EPUB metadata.

If there is no dc:type element, returns null.

Returns

Promise<null | MetadataEntry>

https://www.w3.org/TR/epub-33/#sec-opf-dctype

getUniqueIdentifier()

getUniqueIdentifier(): Promise<null | string>

Defined in: libraries/epub/index.ts:1025

Retrieve the identifier with the unique identifier id in the EPUB metadata.

If there is no unique identifier id, returns the first dc:identifier element.

Returns

Promise<null | string>

https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier

getUniqueIdentifierId()

getUniqueIdentifierId(): Promise<null | string>

Defined in: libraries/epub/index.ts:1106

Retrieve the id of the publication's unique identifier, as declared by the package element's unique-identifier attribute.

Returns

Promise<null | string>

https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier

getVersion()

getVersion(): Promise<string>

Defined in: libraries/epub/index.ts:3280

Returns the EPUB version declared on the package element.

Returns

Promise<string>

readFileContents()

Call Signature

readFileContents(href, relativeTo?): Promise<Uint8Array<ArrayBufferLike>>

Defined in: libraries/epub/index.ts:2803

Retrieve the contents of a file, given its href.

Optionally takes the href that this href should be resolved relative to, and an encoding parameter.

Parameters
ParameterTypeDescription
hrefstringThe href of the file to retrieve
relativeTo?string-
Returns

Promise<Uint8Array<ArrayBufferLike>>

Call Signature

readFileContents(href, relativeTo, encoding): Promise<string>

Defined in: libraries/epub/index.ts:2804

Retrieve the contents of a file, given its href.

Optionally takes the href that this href should be resolved relative to, and an encoding parameter.

Parameters
ParameterTypeDescription
hrefstringThe href of the file to retrieve
relativeToundefined | string-
encoding"utf-8"Optional - Must be the string "utf-8". If provided, the function will encode the data into a unicode string. Otherwise, the data will be returned as a byte array.
Returns

Promise<string>

readItemContents()

Call Signature

readItemContents(id): Promise<Uint8Array<ArrayBufferLike>>

Defined in: libraries/epub/index.ts:2836

Retrieve the contents of a manifest item, given its id.

Parameters
ParameterTypeDescription
idstringThe id of the manifest item to retrieve
Returns

Promise<Uint8Array<ArrayBufferLike>>

https://www.w3.org/TR/epub-33/#sec-contentdocs

Call Signature

readItemContents(id, encoding): Promise<string>

Defined in: libraries/epub/index.ts:2837

Retrieve the contents of a manifest item, given its id.

Parameters
ParameterTypeDescription
idstringThe id of the manifest item to retrieve
encoding"utf-8"Optional - must be the string "utf-8". If provided, the function will encode the data into a unicode string. Otherwise, the data will be returned as a byte array.
Returns

Promise<string>

https://www.w3.org/TR/epub-33/#sec-contentdocs

readXhtmlItemContents()

Call Signature

readXhtmlItemContents(id, as?): Promise<ParsedXml>

Defined in: libraries/epub/index.ts:2899

Retrieves the contents of an XHTML item, given its manifest id.

Parameters
ParameterTypeDescription
idstringThe id of the manifest item to retrieve
as?"xhtml"Optional - whether to return the parsed XML document tree, or the concatenated text of the document. Defaults to the parsed XML tree.
Returns

Promise<ParsedXml>

https://www.w3.org/TR/epub-33/#sec-xhtml

Call Signature

readXhtmlItemContents(id, as): Promise<string>

Defined in: libraries/epub/index.ts:2900

Retrieves the contents of an XHTML item, given its manifest id.

Parameters
ParameterTypeDescription
idstringThe id of the manifest item to retrieve
as"text"Optional - whether to return the parsed XML document tree, or the concatenated text of the document. Defaults to the parsed XML tree.
Returns

Promise<string>

https://www.w3.org/TR/epub-33/#sec-xhtml

removeCollection()

removeCollection(index): Promise<void>

Defined in: libraries/epub/index.ts:2228

Remove a collection from the EPUB metadata.

Removes the collection at the provided index. This index refers to the array returned by epub.getCollections().

Parameters
ParameterType
indexnumber
Returns

Promise<void>

removeContributor()

removeContributor(index): Promise<void>

Defined in: libraries/epub/index.ts:2488

Remove a contributor from the EPUB metadata.

Removes the contributor at the provided index. This index refers to the array returned by epub.getContributors().

This is a convenience method for epub.removeCreator(index, 'contributor').

Parameters
ParameterType
indexnumber
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dccreator

removeCreator()

removeCreator(index, type): Promise<void>

Defined in: libraries/epub/index.ts:2436

Remove a creator from the EPUB metadata.

Removes the creator at the provided index. This index refers to the array returned by epub.getCreators().

Parameters
ParameterTypeDefault value
indexnumberundefined
type"creator" | "contributor""creator"
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dccreator

removeManifestItem()

removeManifestItem(id): Promise<void>

Defined in: libraries/epub/index.ts:3004

Parameters
ParameterType
idstring
Returns

Promise<void>

removeMetadata()

removeMetadata(predicate): Promise<void>

Defined in: libraries/epub/index.ts:3252

Remove one or more metadata entries.

The predicate argument will be used to determine which entries to remove. The all metadata entries that match the predicate will be removed.

Parameters
ParameterTypeDescription
predicate(entry) => booleanCalls predicate once for each metadata entry, removing any for which it returns true
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-pkg-metadata

removeSpineItem()

removeSpineItem(index): Promise<void>

Defined in: libraries/epub/index.ts:2594

Remove the spine item at the specified index.

Parameters
ParameterType
indexnumber
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-spine-elem

removeSubject()

removeSubject(index): Promise<void>

Defined in: libraries/epub/index.ts:1725

Remove a subject from the EPUB metadata.

Removes the subject at the provided index. This index refers to the array returned by epub.getSubjects().

Parameters
ParameterType
indexnumber
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dccreator

replaceMetadata()

replaceMetadata(predicate, entry): Promise<void>

Defined in: libraries/epub/index.ts:3207

Replace a metadata entry with a new one.

The predicate argument will be used to determine which entry to replace. The first metadata entry that matches the predicate will be replaced.

Parameters
ParameterTypeDescription
predicate(entry) => booleanCalls predicate once for each metadata entry, until it finds one where predicate returns true
entryMetadataEntryThe new entry to replace the found entry with
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-pkg-metadata

resolveHref()

resolveHref(href, relativeTo?, __namedParameters?): Promise<string>

Defined in: libraries/epub/index.ts:2775

Returns a path-relative-scheme-less URL, relative to the container root.

Parameters
ParameterTypeDescription
hrefstringThe href to resolve
relativeTo?stringOptional - The href to resolve this href relative to. Use if resolving a relative href from a file other than the package document.
__namedParameters?{ toRoot?: boolean; }-
__namedParameters.toRoot?boolean-
Returns

Promise<string>

saveAndClose()

saveAndClose(): Promise<void>

Defined in: libraries/epub/index.ts:3426

Write the current contents of the Epub to a new EPUB archive on disk.

When this method is called, the "dcterms:modified" meta tag is automatically updated to the current UTC timestamp.

Returns

Promise<void>

setCoverImage()

setCoverImage(href, data): Promise<void>

Defined in: libraries/epub/index.ts:1552

Set the cover image for the EPUB.

Adds a manifest item with the cover-image property, per the EPUB 3 spec, and then writes the provided image data to the provided href within the publication.

Parameters
ParameterType
hrefstring
dataUint8Array
Returns

Promise<void>

setDescription()

setDescription(description): Promise<void>

Defined in: libraries/epub/index.ts:1954

Update the Epub's description metadata entry.

Updates the existing dc:description element if one exists. Otherwise creates a new element. Any non-ASCII symbols, &, <, >, ", ', and ```` will be encoded as HTML entities.

Parameters
ParameterType
descriptionstring
Returns

Promise<void>

setIdentifier()

setIdentifier(identifier): Promise<void>

Defined in: libraries/epub/index.ts:1009

Set the dc:identifier metadata element with the provided string.

Updates the existing dc:identifier element if one exists. Otherwise creates a new element

Parameters
ParameterType
identifierstring
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier

Deprecated

Use setUniqueIdentifier instead.

setIdentifiers()

setIdentifiers(identifiers): Promise<void>

Defined in: libraries/epub/index.ts:1274

Replace the publication's dc:identifier entries.

This replaces ALL existing dc:identifier elements except the publication's unique identifier (the one referenced by the package element's unique-identifier attribute), which is always preserved and must not be included in the provided list. If included anyway, it is ignored. See setUniqueIdentifier to change it.

Identifiers are placed in the order they are provided.

dc:source entries are not touched, use setSources for those.

When an entry has an identifierType, it is written in the refining form (a meta with property="identifier-type", carrying the scheme attribute when provided). An entry with only a scheme is written using the legacy opf:scheme attribute.

Parameters
ParameterType
identifiersEpubIdentifier[]
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier

setLanguage()

setLanguage(locale): Promise<void>

Defined in: libraries/epub/index.ts:1836

Update the Epub's language metadata entry.

Updates the existing dc:language element if one exists. Otherwise creates a new element

Parameters
ParameterType
localeLocale
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dclanguage

setPackageVocabularyPrefix()

setPackageVocabularyPrefix(prefix, uri): Promise<void>

Defined in: libraries/epub/index.ts:2005

Set a custom vocabulary prefix on the root package element.

Parameters
ParameterType
prefixstring
uristring
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-prefix-attr

setPageBreakSource()

setPageBreakSource(value): Promise<void>

Defined in: libraries/epub/index.ts:1241

Set the pageBreakSource property (EPUB 3.4, spec D.2.9), or remove it when passed null. Replaces an existing pageBreakSource meta if present.

Pass none to indicate the pagination is unique to this publication.

Parameters
ParameterType
valuenull | string
Returns

Promise<void>

https://www.w3.org/TR/epub/#pageBreakSource

setPublicationDate()

setPublicationDate(date): Promise<void>

Defined in: libraries/epub/index.ts:1590

Set the dc:date metadata element with the provided date.

Updates the existing dc:date element if one exists. Otherwise creates a new element

Parameters
ParameterType
dateDate
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dcdate

setSources()

setSources(sources): Promise<void>

Defined in: libraries/epub/index.ts:1392

Replace the publication's dc:source entries.

This replaces ALL existing dc:source elements (and their refining identifier-type / source-of metas). dc:identifier entries are not touched; use setIdentifiers for those. Pass an empty array to remove all sources.

When an entry has an identifierType, it is written in the refining form. A sourceOf value is written as a refining source-of meta (spec D.3.11). An entry with only a scheme uses the legacy opf:scheme attribute.

Parameters
ParameterType
sourcesEpubSource[]
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dcsource

setTitle()

setTitle(title): Promise<void>

Defined in: libraries/epub/index.ts:2029

Set the title of the Epub.

This will replace all existing dc:title elements with this title. It will be given title-type "main".

To set specific titles and their types, use epub.setTitles().

Parameters
ParameterType
titlestring
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dctitle

setTitles()

setTitles(entries): Promise<void>

Defined in: libraries/epub/index.ts:2057

Parameters
ParameterType
entriesobject[]
Returns

Promise<void>

setType()

setType(type): Promise<void>

Defined in: libraries/epub/index.ts:1659

Set the dc:type metadata element.

Updates the existing dc:type element if one exists. Otherwise creates a new element.

Parameters
ParameterType
typestring
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dctype

setUniqueIdentifier()

setUniqueIdentifier(identifier): Promise<void>

Defined in: libraries/epub/index.ts:1050

Set the unique identifier id for the EPUB.

Updates the existing dc:identifier element referenced by the unique identifier id if one exists. Otherwise creates a new element with the provided identifier, and sets the unique identifier id to the new element's id.

Note: you likely shouldn't change the unique identifier id unless you are producing a new EPUB.

Parameters
ParameterType
identifierstring
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-opf-dcidentifier

updateManifestItem()

updateManifestItem(id, newItem): Promise<void>

Defined in: libraries/epub/index.ts:3119

Update the manifest entry for an existing item.

To update the contents of an entry, use epub.writeItemContents() or epub.writeXhtmlItemContents()

Parameters
ParameterType
idstring
newItemOmit<ManifestItem, "id">
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-pkg-manifest

withPackage()

withPackage(producer): Promise<void>

Defined in: libraries/epub/index.ts:772

Safely modify the package document, without race conditions.

Since the reading the package document is an async process, multiple simultaneously dispatched function calls that all attempt to modify it can clobber each other's changes. This method uses a mutex to ensure that each update runs exclusively.

Parameters
ParameterTypeDescription
producer(packageElement) => void | (packageElement) => PackageElement | (packageElement) => Promise<PackageElement> | (packageElement) => Promise<void>The function to update the package document. If it returns a new package document, that will be persisted, otherwise it will be assumed that the package document was modified in place.
Returns

Promise<void>

writeItemContents()

Call Signature

writeItemContents(id, contents): Promise<void>

Defined in: libraries/epub/index.ts:2956

Write new contents for an existing manifest item, specified by its id.

The id must reference an existing manifest item. If creating a new item, use epub.addManifestItem() instead.

Parameters
ParameterTypeDescription
idstringThe id of the manifest item to write new contents for
contentsUint8ArrayThe new contents. May be either a utf-8 encoded string or a byte array, as determined by the encoding
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-contentdocs

Call Signature

writeItemContents(id, contents, encoding): Promise<void>

Defined in: libraries/epub/index.ts:2957

Write new contents for an existing manifest item, specified by its id.

The id must reference an existing manifest item. If creating a new item, use epub.addManifestItem() instead.

Parameters
ParameterTypeDescription
idstringThe id of the manifest item to write new contents for
contentsstringThe new contents. May be either a utf-8 encoded string or a byte array, as determined by the encoding
encoding"utf-8"Optional - must be the string "utf-8". If provided, the contents will be interpreted as a unicode string. Otherwise, the contents must be a byte array.
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-contentdocs

writeXhtmlItemContents()

writeXhtmlItemContents(id, contents): Promise<void>

Defined in: libraries/epub/index.ts:2996

Write new contents for an existing XHTML item, specified by its id.

The id must reference an existing manifest item. If creating a new item, use epub.addManifestItem() instead.

Parameters
ParameterTypeDescription
idstringThe id of the manifest item to write new contents for
contentsParsedXmlThe new contents. Must be a parsed XML tree.
Returns

Promise<void>

https://www.w3.org/TR/epub-33/#sec-xhtml

addLinkToXhtmlHead()

static addLinkToXhtmlHead(xml, link): void

Defined in: libraries/epub/index.ts:345

Given an XML structure representing a complete XHTML document, add a link element to the head of the document.

This method modifies the provided XML structure.

Parameters
ParameterType
xmlParsedXml
link{ href: string; rel: string; type: string; }
link.hrefstring
link.relstring
link.typestring
Returns

void

assertEpub3()

static assertEpub3(epub): Promise<void>

Defined in: libraries/epub/index.ts:620

Parameters
ParameterType
epubEpub
Returns

Promise<void>

create()

static create(path, dublinCore, additionalMetadata): Promise<Epub>

Defined in: libraries/epub/index.ts:568

Construct a new EPUB on a writable backend, optionally seeded with the provided metadata. Equivalent to Epub.using(TmpFsAdapter).create(...).

Parameters
ParameterTypeDefault valueDescription
pathstringundefined-
dublinCoreDublinCoreundefinedCore metadata terms
additionalMetadataEpubMetadata[]An array of additional metadata entries
Returns

Promise<Epub>

createXmlElement()

static createXmlElement<Name>(name, properties, children): XmlElement<Name>

Defined in: libraries/epub/index.ts:380

Type Parameters
Type Parameter
Name extends `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}` | `?${string}`
Parameters
ParameterTypeDefault value
nameNameundefined
propertiesRecord<string, string>undefined
childrenXmlNode[][]
Returns

XmlElement<Name>

createXmlTextNode()

static createXmlTextNode(text): XmlTextNode

Defined in: libraries/epub/index.ts:393

Parameters
ParameterType
textstring
Returns

XmlTextNode

findXmlChildByName()

static findXmlChildByName<Name>(name, xml, filter?): undefined | XmlElement<Name>

Defined in: libraries/epub/index.ts:466

Given an XML structure, find the first child matching the provided name and optional filter.

Type Parameters
Type Parameter
Name extends `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}` | `?${string}`
Parameters
ParameterType
nameName
xmlParsedXml
filter?(node) => boolean
Returns

undefined | XmlElement<Name>

findXmlDescendantByName()

static findXmlDescendantByName<Name>(name, xml, filter?): undefined | XmlElement<Name>

Defined in: libraries/epub/index.ts:484

Given an XML structure, find the first descendant matching the provided name and optional filter.

Will perform a breadth first search for the element, returning the highest element in the tree matching the name and filter.

Type Parameters
Type Parameter
Name extends `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}` | `?${string}`
Parameters
ParameterType
nameName
xmlParsedXml
filter?(node) => boolean
Returns

undefined | XmlElement<Name>

formatSmilDuration()

static formatSmilDuration(duration): string

Defined in: libraries/epub/index.ts:328

Format a duration, provided as a number of seconds, as a SMIL clock value, to be used for Media Overlays.

Parameters
ParameterType
durationnumber
Returns

string

https://www.w3.org/TR/epub-33/#sec-duration

from()

Call Signature

static from(pathOrData): Promise<Epub>

Defined in: libraries/epub/index.ts:604

Open an existing EPUB publication, extracting it to a temp directory so writes can mutate the unpacked tree and rezip with saveAndClose.

Pass { readonly: true } to gate mutations at runtime.

prefer Epub.using(TmpFsAdapter).from(path) (or Epub.using(MemoryAdapter).from(path) for read-only, in-memory access)

Parameters
ParameterType
pathOrDatastring | Uint8Array<ArrayBufferLike>
Returns

Promise<Epub>

Throws

when the archive is not a valid EPUB 3

Call Signature

static from(pathOrData, options): Promise<EpubReader>

Defined in: libraries/epub/index.ts:605

Open an existing EPUB publication, extracting it to a temp directory so writes can mutate the unpacked tree and rezip with saveAndClose.

Pass { readonly: true } to gate mutations at runtime.

prefer Epub.using(TmpFsAdapter).from(path) (or Epub.using(MemoryAdapter).from(path) for read-only, in-memory access)

Parameters
ParameterType
pathOrDatastring | Uint8Array<ArrayBufferLike>
optionsFromOptions & object
Returns

Promise<EpubReader>

Throws

when the archive is not a valid EPUB 3

Call Signature

static from(pathOrData, options?): Promise<Epub | EpubReader>

Defined in: libraries/epub/index.ts:609

Open an existing EPUB publication, extracting it to a temp directory so writes can mutate the unpacked tree and rezip with saveAndClose.

Pass { readonly: true } to gate mutations at runtime.

prefer Epub.using(TmpFsAdapter).from(path) (or Epub.using(MemoryAdapter).from(path) for read-only, in-memory access)

Parameters
ParameterType
pathOrDatastring | Uint8Array<ArrayBufferLike>
options?FromOptions
Returns

Promise<Epub | EpubReader>

Throws

when the archive is not a valid EPUB 3

getXhtmlBody()

static getXhtmlBody(xml): ParsedXml

Defined in: libraries/epub/index.ts:370

Given an XML structure representing a complete XHTML document, return the sub-structure representing the children of the document's body element.

Parameters
ParameterType
xmlParsedXml
Returns

ParsedXml

getXhtmlTextContent()

static getXhtmlTextContent(xml): string

Defined in: libraries/epub/index.ts:402

Given an XML structure representing a complete XHTML document, return a string representing the concatenation of all text nodes in the document.

Parameters
ParameterType
xmlParsedXml
Returns

string

getXmlAttributes()

static getXmlAttributes(element): Record<string, string>

Defined in: libraries/epub/index.ts:419

Given an XMLElement, return its attributes.

Parameters
ParameterType
elementXmlElement
Returns

Record<string, string>

getXmlChildren()

static getXmlChildren<Name>(element): ParsedXml

Defined in: libraries/epub/index.ts:446

Given an XMLElement, return a list of its children

Type Parameters
Type Parameter
Name extends `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}` | `?${string}`
Parameters
ParameterType
elementXmlElement<Name>
Returns

ParsedXml

getXmlElementName()

static getXmlElementName<Name>(element): Name

Defined in: libraries/epub/index.ts:431

Given an XMLElement, return its tag name.

Type Parameters
Type Parameter
Name extends `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}` | `?${string}`
Parameters
ParameterType
elementXmlElement<Name>
Returns

Name

isXmlTextNode()

static isXmlTextNode(node): node is XmlTextNode

Defined in: libraries/epub/index.ts:506

Given an XMLNode, determine whether it represents a text node or an XML element.

Parameters
ParameterType
nodeXmlNode
Returns

node is XmlTextNode

replaceXmlChildren()

static replaceXmlChildren<Name>(element, children): void

Defined in: libraries/epub/index.ts:454

Type Parameters
Type Parameter
Name extends `a${string}` | `b${string}` | `c${string}` | `d${string}` | `e${string}` | `f${string}` | `g${string}` | `h${string}` | `i${string}` | `j${string}` | `k${string}` | `l${string}` | `m${string}` | `n${string}` | `o${string}` | `p${string}` | `q${string}` | `r${string}` | `s${string}` | `t${string}` | `u${string}` | `v${string}` | `w${string}` | `x${string}` | `y${string}` | `z${string}` | `A${string}` | `B${string}` | `C${string}` | `D${string}` | `E${string}` | `F${string}` | `G${string}` | `H${string}` | `I${string}` | `J${string}` | `K${string}` | `L${string}` | `M${string}` | `N${string}` | `O${string}` | `P${string}` | `Q${string}` | `R${string}` | `S${string}` | `T${string}` | `U${string}` | `V${string}` | `W${string}` | `X${string}` | `Y${string}` | `Z${string}` | `?${string}`
Parameters
ParameterType
elementXmlElement<Name>
childrenXmlNode[]
Returns

void

upgrade()

static upgrade(path, options): Promise<Epub>

Defined in: libraries/epub/index.ts:3454

Upgrade an EPUB 2 publication to EPUB 3 in place, returning a new, valid Epub 3 instance. Equivalent to Epub.using(TmpFsAdapter).upgrade(...).

Parameters
ParameterType
pathstring
optionsEpub2UpgradeOptions
Returns

Promise<Epub>

using()

static using<A>(adapterClass): EpubFactory<A>

Defined in: libraries/epub/index.ts:588

Specify the storage backend to use for the EPUB

The returned factory exposes from, create, and upgrade, which route through the supplied adapter.

Type Parameters
Type Parameter
A extends EpubStorageAdapterClass<object>
Parameters
ParameterType
adapterClassA
Returns

EpubFactory<A>

Example
using epub = await Epub.using(TmpFsAdapter).from(path)
using reader = await Epub.using(MemoryAdapter).from(buffer, { cache: false })

EpubFactory<A>

Defined in: libraries/epub/index.ts:3483

Adapter-bound factory returned by Epub.using.

Mirrors the static factory surface (from, create, upgrade) but routes all I/O through the supplied adapter. Each method's signature degrades gracefully when the adapter doesn't support the operation: create and upgrade throw at runtime if the adapter is read-only or lacks initEmpty.

Type Parameters

Type Parameter
A extends EpubStorageAdapterClass

Constructors

Constructor

new EpubFactory<A>(adapterClass): EpubFactory<A>

Defined in: libraries/epub/index.ts:3484

Parameters
ParameterType
adapterClassA
Returns

EpubFactory<A>

Properties

adapterClass

readonly adapterClass: A

Defined in: libraries/epub/index.ts:3484

Methods

create()

create(path, __namedParameters, additionalMetadata): Promise<EpubInstanceFor<A>>

Defined in: libraries/epub/index.ts:3540

Construct a new EPUB on this factory's adapter, optionally seeded with the provided metadata. Requires a writable adapter that implements initEmpty (today: TmpFsAdapter).

Parameters
ParameterTypeDefault value
pathstringundefined
__namedParametersDublinCoreundefined
additionalMetadataEpubMetadata[]
Returns

Promise<EpubInstanceFor<A>>

Throws

when the adapter is read-only or does not implement initEmpty

from()

Call Signature

from(source, options): Promise<Pick<Epub, "storage" | "getItemArchiveLength" | "getRootfile" | "getPackageElement" | "getManifest" | "findMetadataItem" | "findAllMetadataItems" | "getMetadata" | "getIdentifier" | "getUniqueIdentifier" | "getUniqueIdentifierId" | "getIdentifiers" | "getSources" | "getPageBreakSource" | "getCoverImageItem" | "getCoverImage" | "getPublicationDate" | "getModifiedDate" | "getLayout" | "getBaseDirection" | "getType" | "getSubjects" | "getLanguage" | "getTitle" | "getSubtitle" | "getTitles" | "getDescription" | "getPackageVocabularyPrefixes" | "getCollections" | "getCreators" | "getContributors" | "getSpineItems" | "getTableOfContents" | "getLandmarks" | "getPageList" | "resolveHref" | "readFileContents" | "readItemContents" | "readXhtmlItemContents" | "getVersion" | "getNcxTableOfContents" | "getGuideEntries" | "discardAndClose"> & Disposable & object>

Defined in: libraries/epub/index.ts:3491

Open an existing EPUB through this factory's adapter

Parameters
ParameterType
sourcestring | Uint8Array<ArrayBufferLike>
optionsFromOptions & object & AdapterOptions<A>
Returns

Promise<Pick<Epub, "storage" | "getItemArchiveLength" | "getRootfile" | "getPackageElement" | "getManifest" | "findMetadataItem" | "findAllMetadataItems" | "getMetadata" | "getIdentifier" | "getUniqueIdentifier" | "getUniqueIdentifierId" | "getIdentifiers" | "getSources" | "getPageBreakSource" | "getCoverImageItem" | "getCoverImage" | "getPublicationDate" | "getModifiedDate" | "getLayout" | "getBaseDirection" | "getType" | "getSubjects" | "getLanguage" | "getTitle" | "getSubtitle" | "getTitles" | "getDescription" | "getPackageVocabularyPrefixes" | "getCollections" | "getCreators" | "getContributors" | "getSpineItems" | "getTableOfContents" | "getLandmarks" | "getPageList" | "resolveHref" | "readFileContents" | "readItemContents" | "readXhtmlItemContents" | "getVersion" | "getNcxTableOfContents" | "getGuideEntries" | "discardAndClose"> & Disposable & object>

Throws

when the archive is not a valid EPUB 3

Call Signature

from(source, options?): Promise<EpubInstanceFor<A> & object>

Defined in: libraries/epub/index.ts:3495

Open an existing EPUB through this factory's adapter

Parameters
ParameterType
sourcestring | Uint8Array<ArrayBufferLike>
options?FromOptions & AdapterOptions<A>
Returns

Promise<EpubInstanceFor<A> & object>

Throws

when the archive is not a valid EPUB 3

upgrade()

upgrade(path, options): Promise<EpubInstanceFor<A>>

Defined in: libraries/epub/index.ts:3653

Upgrade an EPUB 2 publication to EPUB 3 in place using this factory's adapter, returning a new, valid Epub 3 instance.

Performs the following transformations:

  • upgrades OPF metadata to EPUB 3 conventions
  • scans XHTML documents and adds manifest item properties
  • parses the NCX into a TOC tree and generates a nav.xhtml
  • removes the NCX file and the guide element (configurable)
  • fixes common font MIME types
  • bumps the package version to 3.0
  • goes over each xhtml item and rewrites it using XMLParser to make sure the output is valid XHTML

Requires a writable adapter. When Upgrade.Epub2UpgradeOptions.outputPath is set, the source file is copied to that path on disk first; this only makes sense for adapters whose source is a real fs path.

Parameters
ParameterType
pathstring
optionsEpub2UpgradeOptions
Returns

Promise<EpubInstanceFor<A>>

Throws

when the adapter is read-only


EpubReadOnlyError

Defined in: libraries/epub/index.ts:238

Extends

  • Error

Constructors

Constructor

new EpubReadOnlyError(message?): EpubReadOnlyError

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1082

Parameters
ParameterType
message?string
Returns

EpubReadOnlyError

Inherited from

Error.constructor

Constructor

new EpubReadOnlyError(message?, options?): EpubReadOnlyError

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1082

Parameters
ParameterType
message?string
options?ErrorOptions
Returns

EpubReadOnlyError

Inherited from

Error.constructor

Properties

cause?

optional cause: unknown

Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:26

Inherited from

Error.cause

message

message: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1077

Inherited from

Error.message

name

name: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076

Inherited from

Error.name

stack?

optional stack: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078

Inherited from

Error.stack

stackTraceLimit

static stackTraceLimit: number

Defined in: node_modules/@types/node/globals.d.ts:68

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

Inherited from

Error.stackTraceLimit

Methods

captureStackTrace()

static captureStackTrace(targetObject, constructorOpt?): void

Defined in: node_modules/@types/node/globals.d.ts:52

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

const myObject = {}
Error.captureStackTrace(myObject)
myObject.stack // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

function a() {
b()
}

function b() {
c()
}

function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error
Error.stackTraceLimit = 0
const error = new Error()
Error.stackTraceLimit = stackTraceLimit

// Capture the stack trace above function b
Error.captureStackTrace(error, b) // Neither function c, nor b is included in the stack trace
throw error
}

a()
Parameters
ParameterType
targetObjectobject
constructorOpt?Function
Returns

void

Inherited from

Error.captureStackTrace

isError()

static isError(error): error is Error

Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23

Indicates whether the argument provided is a built-in Error instance or not.

Parameters
ParameterType
errorunknown
Returns

error is Error

Inherited from

Error.isError

prepareStackTrace()

static prepareStackTrace(err, stackTraces): any

Defined in: node_modules/@types/node/globals.d.ts:56

Parameters
ParameterType
errError
stackTracesCallSite[]
Returns

any

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from

Error.prepareStackTrace


EpubVersionError

Defined in: libraries/epub/index.ts:237

Extends

  • Error

Constructors

Constructor

new EpubVersionError(message?): EpubVersionError

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1082

Parameters
ParameterType
message?string
Returns

EpubVersionError

Inherited from

Error.constructor

Constructor

new EpubVersionError(message?, options?): EpubVersionError

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1082

Parameters
ParameterType
message?string
options?ErrorOptions
Returns

EpubVersionError

Inherited from

Error.constructor

Properties

cause?

optional cause: unknown

Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:26

Inherited from

Error.cause

message

message: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1077

Inherited from

Error.message

name

name: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076

Inherited from

Error.name

stack?

optional stack: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078

Inherited from

Error.stack

stackTraceLimit

static stackTraceLimit: number

Defined in: node_modules/@types/node/globals.d.ts:68

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

Inherited from

Error.stackTraceLimit

Methods

captureStackTrace()

static captureStackTrace(targetObject, constructorOpt?): void

Defined in: node_modules/@types/node/globals.d.ts:52

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

const myObject = {}
Error.captureStackTrace(myObject)
myObject.stack // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

function a() {
b()
}

function b() {
c()
}

function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error
Error.stackTraceLimit = 0
const error = new Error()
Error.stackTraceLimit = stackTraceLimit

// Capture the stack trace above function b
Error.captureStackTrace(error, b) // Neither function c, nor b is included in the stack trace
throw error
}

a()
Parameters
ParameterType
targetObjectobject
constructorOpt?Function
Returns

void

Inherited from

Error.captureStackTrace

isError()

static isError(error): error is Error

Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23

Indicates whether the argument provided is a built-in Error instance or not.

Parameters
ParameterType
errorunknown
Returns

error is Error

Inherited from

Error.isError

prepareStackTrace()

static prepareStackTrace(err, stackTraces): any

Defined in: node_modules/@types/node/globals.d.ts:56

Parameters
ParameterType
errError
stackTracesCallSite[]
Returns

any

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from

Error.prepareStackTrace


MemoryAdapter

Defined in: libraries/epub/adapters/memory.ts:32

Loads an EPUB archive into memory and serves all I/O off the in-memory zip handle.

read only

Implements

Properties

rootPath

readonly rootPath: string

Defined in: libraries/epub/adapters/memory.ts:71

Opaque path prefix used by resolveInternalHref to anchor absolute paths within the archive. For TmpFsAdapter this is the tmp dir; for MemoryAdapter it's a virtual prefix that's never written to disk

Implementation of

EpubStorageAdapter.rootPath

capabilities

readonly static capabilities: object

Defined in: libraries/epub/adapters/memory.ts:34

writable

readonly writable: false = false

kind

readonly static kind: "in-memory"

Defined in: libraries/epub/adapters/memory.ts:33

Methods

archiveLength()

archiveLength(path): Promise<number>

Defined in: libraries/epub/adapters/memory.ts:114

Length of an entry in bytes, for the readium page-count heuristic which expects compressed size when available

Parameters
ParameterType
pathstring
Returns

Promise<number>

Implementation of

EpubStorageAdapter.archiveLength

dispose()

dispose(): void

Defined in: libraries/epub/adapters/memory.ts:120

Always called on close or error

Returns

void

Implementation of

EpubStorageAdapter.dispose

read()

Call Signature

read(path): Promise<Uint8Array<ArrayBufferLike>>

Defined in: libraries/epub/adapters/memory.ts:85

Parameters
ParameterType
pathstring
Returns

Promise<Uint8Array<ArrayBufferLike>>

Implementation of

EpubStorageAdapter.read

Call Signature

read(path, encoding): Promise<string>

Defined in: libraries/epub/adapters/memory.ts:86

Parameters
ParameterType
pathstring
encoding"utf-8"
Returns

Promise<string>

Implementation of

EpubStorageAdapter.read

init()

static init(source, opts): Promise<MemoryAdapter>

Defined in: libraries/epub/adapters/memory.ts:36

Parameters
ParameterType
sourcestring | Uint8Array<ArrayBufferLike>
optsMemoryAdapterOptions
Returns

Promise<MemoryAdapter>


TmpFsAdapter

Defined in: libraries/epub/adapters/tmpfs.ts:59

Extracts an EPUB archive to a temp directory and serves all I/O off the real filesystem. Epub.using(TmpFsAdapter).from(...) returns a writable Epub.

Implements

Properties

rootPath

readonly rootPath: string

Defined in: libraries/epub/adapters/tmpfs.ts:102

Opaque path prefix used by resolveInternalHref to anchor absolute paths within the archive. For TmpFsAdapter this is the tmp dir; for MemoryAdapter it's a virtual prefix that's never written to disk

Implementation of

EpubStorageAdapter.rootPath

capabilities

readonly static capabilities: object

Defined in: libraries/epub/adapters/tmpfs.ts:61

writable

readonly writable: true = true

kind

readonly static kind: "extracted-dir"

Defined in: libraries/epub/adapters/tmpfs.ts:60

Methods

archiveLength()

archiveLength(path): Promise<number>

Defined in: libraries/epub/adapters/tmpfs.ts:125

Length of an entry in bytes, for the readium page-count heuristic which expects compressed size when available

Parameters
ParameterType
pathstring
Returns

Promise<number>

Implementation of

EpubStorageAdapter.archiveLength

dispose()

dispose(): void

Defined in: libraries/epub/adapters/tmpfs.ts:198

Always called on close or error

Returns

void

Implementation of

EpubStorageAdapter.dispose

duplicate()

duplicate(): Promise<TmpFsAdapter>

Defined in: libraries/epub/adapters/tmpfs.ts:149

Required for Epub.copy

Returns

Promise<TmpFsAdapter>

Implementation of

EpubStorageAdapter.duplicate

list()

list(): AsyncIterable<EpubListEntry>

Defined in: libraries/epub/adapters/tmpfs.ts:134

Required for Epub.saveAndClose to walk the contents

Returns

AsyncIterable<EpubListEntry>

Implementation of

EpubStorageAdapter.list

read()

Call Signature

read(path): Promise<Uint8Array<ArrayBufferLike>>

Defined in: libraries/epub/adapters/tmpfs.ts:104

Parameters
ParameterType
pathstring
Returns

Promise<Uint8Array<ArrayBufferLike>>

Implementation of

EpubStorageAdapter.read

Call Signature

read(path, encoding): Promise<string>

Defined in: libraries/epub/adapters/tmpfs.ts:105

Parameters
ParameterType
pathstring
encoding"utf-8"
Returns

Promise<string>

Implementation of

EpubStorageAdapter.read

remove()

remove(path): Promise<void>

Defined in: libraries/epub/adapters/tmpfs.ts:121

Required for removeManifestItem / setCoverImage replacement

Parameters
ParameterType
pathstring
Returns

Promise<void>

Implementation of

EpubStorageAdapter.remove

serialize()

serialize(targetPath): Promise<void>

Defined in: libraries/epub/adapters/tmpfs.ts:160

Required for Epub.saveAndClose

Parameters
ParameterType
targetPathstring
Returns

Promise<void>

Implementation of

EpubStorageAdapter.serialize

write()

Call Signature

write(path, data): Promise<void>

Defined in: libraries/epub/adapters/tmpfs.ts:110

Required for any mutation method on Epub

Parameters
ParameterType
pathstring
dataUint8Array
Returns

Promise<void>

Implementation of

EpubStorageAdapter.write

Call Signature

write(path, data, encoding): Promise<void>

Defined in: libraries/epub/adapters/tmpfs.ts:111

Parameters
ParameterType
pathstring
datastring
encoding"utf-8"
Returns

Promise<void>

Implementation of

EpubStorageAdapter.write

init()

static init(source): Promise<TmpFsAdapter>

Defined in: libraries/epub/adapters/tmpfs.ts:63

Parameters
ParameterType
sourcestring | Uint8Array<ArrayBufferLike>
Returns

Promise<TmpFsAdapter>

initEmpty()

static initEmpty(): Promise<TmpFsAdapter>

Defined in: libraries/epub/adapters/tmpfs.ts:96

Returns

Promise<TmpFsAdapter>


AlternateScript

Defined in: libraries/epub/index.ts:154

Properties

locale

locale: Locale

Defined in: libraries/epub/index.ts:156

name

name: string

Defined in: libraries/epub/index.ts:155


Collection

Defined in: libraries/epub/index.ts:178

Properties

name

name: string

Defined in: libraries/epub/index.ts:179

position?

optional position: string

Defined in: libraries/epub/index.ts:181

type?

optional type: string

Defined in: libraries/epub/index.ts:180


DcCreator

Defined in: libraries/epub/index.ts:159

Properties

alternateScripts?

optional alternateScripts: AlternateScript[]

Defined in: libraries/epub/index.ts:164

fileAs?

optional fileAs: string

Defined in: libraries/epub/index.ts:163

name

name: string

Defined in: libraries/epub/index.ts:160

role?

optional role: string

Defined in: libraries/epub/index.ts:161

roleScheme?

optional roleScheme: string

Defined in: libraries/epub/index.ts:162


DcSubject

Defined in: libraries/epub/index.ts:121

Properties

authority

authority: string

Defined in: libraries/epub/index.ts:123

term

term: string

Defined in: libraries/epub/index.ts:124

value

value: string

Defined in: libraries/epub/index.ts:122


DublinCore

Defined in: libraries/epub/index.ts:167

Properties

contributors?

optional contributors: DcCreator[]

Defined in: libraries/epub/index.ts:174

creators?

optional creators: DcCreator[]

Defined in: libraries/epub/index.ts:173

date?

optional date: Date

Defined in: libraries/epub/index.ts:171

identifier

identifier: string

Defined in: libraries/epub/index.ts:170

language

language: Locale

Defined in: libraries/epub/index.ts:169

subjects?

optional subjects: (string | DcSubject)[]

Defined in: libraries/epub/index.ts:172

title

title: string

Defined in: libraries/epub/index.ts:168

type?

optional type: string

Defined in: libraries/epub/index.ts:175


Epub2UpgradeOptions

Defined in: libraries/epub/upgrade.ts:93

Properties

outputPath?

optional outputPath: string

Defined in: libraries/epub/upgrade.ts:97

The path to the output file. If provided, the input file will be copied to the output path.

removeNcx?

optional removeNcx: boolean

Defined in: libraries/epub/upgrade.ts:101

Whether to remove the NCX file, as it's technically optional in EPUB 3.


EpubIdentifier

Defined in: libraries/epub/index.ts:127

Properties

id?

optional id: string

Defined in: libraries/epub/index.ts:129

identifierType?

optional identifierType: string

Defined in: libraries/epub/index.ts:131

the value of a refining identifier-type meta, if present

scheme?

optional scheme: string

Defined in: libraries/epub/index.ts:133

the scheme of a refining identifier-type meta, or a legacy opf:scheme attribute

value

value: string

Defined in: libraries/epub/index.ts:128


EpubListEntry

Defined in: libraries/epub/adapters/interface.ts:17

Properties

absolutePath

absolutePath: string

Defined in: libraries/epub/adapters/interface.ts:19

absolute path under EpubStorageAdapter.rootPath

relativePath

relativePath: string

Defined in: libraries/epub/adapters/interface.ts:21

path relative to EpubStorageAdapter.rootPath, slash-separated


EpubSource

Defined in: libraries/epub/index.ts:136

Properties

id?

optional id: string

Defined in: libraries/epub/index.ts:138

identifierType?

optional identifierType: string

Defined in: libraries/epub/index.ts:140

the value of a refining identifier-type meta, if present

isPageBreakSource?

optional isPageBreakSource: boolean

Defined in: libraries/epub/index.ts:151

whether this source has a source-of="pagination" refinement or of a <meta property="pageBreakSource"> element

as of EPUB 3.4 source-of is advised-deprecated in favour of the publication-level pageBreakSource property. if you want to be sure to get the source of pagination, use Epub.getPageBreakSource

scheme?

optional scheme: string

Defined in: libraries/epub/index.ts:142

the scheme of a refining identifier-type meta, or a legacy opf:scheme attribute

value

value: string

Defined in: libraries/epub/index.ts:137


EpubStorageAdapter

Defined in: libraries/epub/adapters/interface.ts:24

Properties

rootPath

readonly rootPath: string

Defined in: libraries/epub/adapters/interface.ts:30

Opaque path prefix used by resolveInternalHref to anchor absolute paths within the archive. For TmpFsAdapter this is the tmp dir; for MemoryAdapter it's a virtual prefix that's never written to disk

Methods

archiveLength()

archiveLength(path): Promise<number>

Defined in: libraries/epub/adapters/interface.ts:39

Length of an entry in bytes, for the readium page-count heuristic which expects compressed size when available

Parameters
ParameterType
pathstring
Returns

Promise<number>

dispose()

dispose(): void | Promise<void>

Defined in: libraries/epub/adapters/interface.ts:58

Always called on close or error

Returns

void | Promise<void>

duplicate()?

optional duplicate(): Promise<EpubStorageAdapter>

Defined in: libraries/epub/adapters/interface.ts:52

Required for Epub.copy

Returns

Promise<EpubStorageAdapter>

list()?

optional list(): AsyncIterable<EpubListEntry>

Defined in: libraries/epub/adapters/interface.ts:49

Required for Epub.saveAndClose to walk the contents

Returns

AsyncIterable<EpubListEntry>

read()

Call Signature

read(path): Promise<Uint8Array<ArrayBufferLike>>

Defined in: libraries/epub/adapters/interface.ts:32

Parameters
ParameterType
pathstring
Returns

Promise<Uint8Array<ArrayBufferLike>>

Call Signature

read(path, encoding): Promise<string>

Defined in: libraries/epub/adapters/interface.ts:33

Parameters
ParameterType
pathstring
encoding"utf-8"
Returns

Promise<string>

remove()?

optional remove(path): Promise<void>

Defined in: libraries/epub/adapters/interface.ts:46

Required for removeManifestItem / setCoverImage replacement

Parameters
ParameterType
pathstring
Returns

Promise<void>

serialize()?

optional serialize(targetPath): Promise<void>

Defined in: libraries/epub/adapters/interface.ts:55

Required for Epub.saveAndClose

Parameters
ParameterType
targetPathstring
Returns

Promise<void>

write()?

Call Signature

optional write(path, data): Promise<void>

Defined in: libraries/epub/adapters/interface.ts:42

Required for any mutation method on Epub

Parameters
ParameterType
pathstring
dataUint8Array
Returns

Promise<void>

Call Signature

optional write(path, data, encoding): Promise<void>

Defined in: libraries/epub/adapters/interface.ts:43

Parameters
ParameterType
pathstring
datastring
encoding"utf-8"
Returns

Promise<void>


EpubStorageAdapterClass<Opts>

Defined in: libraries/epub/adapters/interface.ts:61

Type Parameters

Type ParameterDefault type
Opts extends objectobject

Properties

capabilities

readonly capabilities: EpubStorageCapabilities

Defined in: libraries/epub/adapters/interface.ts:63

kind

readonly kind: EpubStorageKind

Defined in: libraries/epub/adapters/interface.ts:62

Methods

init()

init(source, opts?): Promise<EpubStorageAdapter>

Defined in: libraries/epub/adapters/interface.ts:70

Open an archive from a path or buffer. The returned adapter is ready to read; the Epub class will assert it's a valid EPUB 3 afterwards.

Parameters
ParameterType
sourcestring | Uint8Array<ArrayBufferLike>
opts?Opts
Returns

Promise<EpubStorageAdapter>

initEmpty()?

optional initEmpty(opts?): Promise<EpubStorageAdapter>

Defined in: libraries/epub/adapters/interface.ts:79

Initialize an empty extract root for Epub.create.

Optional — adapters that can't be written to from scratch (e.g. read-only zip handles) should leave this off, and Epub.using(...).create(...) will throw.

Parameters
ParameterType
opts?Opts
Returns

Promise<EpubStorageAdapter>


EpubStorageCapabilities

Defined in: libraries/epub/adapters/interface.ts:12

Properties

writable

readonly writable: boolean

Defined in: libraries/epub/adapters/interface.ts:14

when false, the Epub class refuses every mutation method at runtime


FromOptions

Defined in: libraries/epub/index.ts:205

Properties

readonly?

optional readonly: boolean

Defined in: libraries/epub/index.ts:210

when true, mutation methods throw EpubReadOnlyError at runtime

Default
false

Landmark

Defined in: libraries/epub/upgrade.ts:87

Properties

href

href: string

Defined in: libraries/epub/upgrade.ts:88

title

title: string

Defined in: libraries/epub/upgrade.ts:89

type

type: string

Defined in: libraries/epub/upgrade.ts:90


MemoryAdapterOptions

Defined in: libraries/epub/adapters/memory.ts:15

Properties

cache?

optional cache: boolean

Defined in: libraries/epub/adapters/memory.ts:22

per-entry decompressed buffer cache turn it off when opening many EPUBs and reading each entry at most once keeps resident size bounded by the entry index, not the decompressed payload sum

Default
true

signal?

optional signal: AbortSignal

Defined in: libraries/epub/adapters/memory.ts:23


Defined in: libraries/epub/index.ts:192

Properties

children

children: NavigationList

Defined in: libraries/epub/index.ts:194

title?

optional title: string

Defined in: libraries/epub/index.ts:193


Defined in: libraries/epub/index.ts:184

Properties

children?

optional children: NavigationList

Defined in: libraries/epub/index.ts:187

href?

optional href: string

Defined in: libraries/epub/index.ts:186

title

title: string

Defined in: libraries/epub/index.ts:185


AdapterOptions<A>

AdapterOptions<A> = A extends EpubStorageAdapterClass<infer Opts> ? Opts : object

Defined in: libraries/epub/adapters/interface.ts:82

Type Parameters

Type Parameter
A

ElementName

ElementName = `${Letter | Uppercase<Letter> | QuestionMark}${string}`

Defined in: libraries/epub/index.ts:82

A valid name for an XML element (must start with a letter)


EpubInstanceFor<A>

EpubInstanceFor<A> = A["capabilities"]["writable"] extends true ? Epub : EpubReader

Defined in: libraries/epub/index.ts:3472

Resolves to Epub for writable adapters, EpubReader for read-only ones.

The conditional pivots on capabilities.writable, which must be a literal true/false on the adapter class (use as const) for inference to work.

Type Parameters

Type Parameter
A extends EpubStorageAdapterClass

EpubMetadata

EpubMetadata = MetadataEntry[]

Defined in: libraries/epub/index.ts:119


EpubReader

EpubReader = Pick<Epub, "storage" | "findMetadataItem" | "findAllMetadataItems" | "resolveHref" | "readFileContents" | "readItemContents" | "readXhtmlItemContents" | "discardAndClose" | Extract<keyof Epub, `get${string}`>> & Disposable

Defined in: libraries/epub/index.ts:217

Read-only view of an EPUB Returned by Epub.using(MemoryAdapter).from(...) and by Epub.from(path, { readonly: true })


EpubStorageKind

EpubStorageKind = "tmp-dir" | "in-memory" | string & object

Defined in: libraries/epub/adapters/interface.ts:10

Pluggable storage backend for an Epub instance

Built-in adapters:

  • TmpFsAdapter extracts the archive to a tmp directory and supports the full read/write/save/upgrade
  • MemoryAdapter keeps an in-memory zip handle and supports reads only

InMemoryEpubReader

InMemoryEpubReader = EpubReader & object

Defined in: libraries/epub/index.ts:235

Readonly Epub-instance backed by an in-memory zip handle Returned by Epub.using(MemoryAdapter).from(...)

Type Declaration

storage

readonly storage: "in-memory"


ManifestItem

ManifestItem = object

Defined in: libraries/epub/index.ts:103

Properties

fallback?

optional fallback: string

Defined in: libraries/epub/index.ts:107

href

href: string

Defined in: libraries/epub/index.ts:105

id

id: string

Defined in: libraries/epub/index.ts:104

mediaOverlay?

optional mediaOverlay: string

Defined in: libraries/epub/index.ts:108

mediaType?

optional mediaType: string

Defined in: libraries/epub/index.ts:106

properties?

optional properties: string[]

Defined in: libraries/epub/index.ts:109


MetadataEntry

MetadataEntry = object

Defined in: libraries/epub/index.ts:112

Properties

id?

optional id: string

Defined in: libraries/epub/index.ts:113

properties

properties: Record<string, string>

Defined in: libraries/epub/index.ts:115

type

type: ElementName

Defined in: libraries/epub/index.ts:114

value

value: string | undefined

Defined in: libraries/epub/index.ts:116


NavigationList = NavigationItem[]

Defined in: libraries/epub/index.ts:190


PackageElement

PackageElement = XmlElement<"package">

Defined in: libraries/epub/index.ts:203


ParsedXml

ParsedXml = XmlNode[]

Defined in: libraries/epub/index.ts:101

An XML structure


XmlElement<Name>

XmlElement<Name> = object & { [key in Name]: ParsedXml }

Defined in: libraries/epub/index.ts:88

An XML element

Type Declaration

:@?

optional :@: Record<`${PropertyPrefix}${string}`, string>

Type Parameters

Type ParameterDefault type
Name extends ElementNameElementName

XmlNode

XmlNode = XmlElement | XmlTextNode

Defined in: libraries/epub/index.ts:98

A valid XML node. May be either an element or a text node.


XmlTextNode

XmlTextNode = object

Defined in: libraries/epub/index.ts:95

A text node in an XML document

Properties

#text

#text: string

Defined in: libraries/epub/index.ts:95