https://www.npmjs.com/package/@smoores/epub
skip to:contentpackage searchsign in
* Pro
* Teams
* Pricing
* Documentation
npm
[ ]
Search
Sign UpSign In
@smoores/epub
TypeScript icon, indicating that this package has built-in type
declarations
0.1.2 * Public * Published 2 hours ago
* Readme
* Code Beta
* 5 Dependencies
* 0 Dependents
* 3 Versions
@smoores/epub
A Node.js library for inspecting, modifying, and creating EPUB 3
publications.
* Installation
* About
+ EPUB Basics
+ What this library does
* Usage
+ Reading from a file
+ Creating from scratch
+ Adding a chapter
* Development
* API Docs
Installation
npm:
npm install @smoores/epub
yarn:
yarn add @smoores/epub
About
Throughout this library's documentation, there will be many
references to the EPUB 3 specification. The lower level APIs exposed
by this library require some knowledge of this specification. Here we
will cover the very basics necessary to work with the library, but we
recommend that users read through the linked specification to gain a
deeper understanding of the format.
EPUB Basics
An EPUB file is a ZIP archive with a partially specified directory
and file structure. Most of the metadata and content is specified as
XML documents, with additional resources referenced from those XML
documents.
The most important of these documents is the package document.
The package document is an XML document that consists of a set of
elements that each encapsulate information about a particular
aspect of an EPUB publication. These elements serve to centralize
metadata, detail the individual resources, and provide the
reading order and other information necessary for its rendering.
This library is primarily concerned with providing access to the
metadata, manifest, and spine of the EPUB publication. Metadata
refers to information about the publication, such as its title or
authors. The manifest refers to the complete set of resources that
are used to render the publication, such as XHTML documents and image
files. And the spine refers to the ordered list of manifest items
that represent the default reading order -- the order that readers
will encounter the manifest items by simply turning pages one at a
time.
What this library does
@smoores/epub provides an API to interact with the metadata,
manifest, and spine of the EPUB publication. There are higher level
APIs that mostly abstract away the implementation details of the EPUB
specification, like epub.setTitle(title: string) and epub.getCreators
(), as well as lower level APIs like epub.writeItemContents(path:
string, contents: Uint8Array) and epub.addMetadata(entry:
MetadataEntry), which require some understanding of the EPUB
structure to utilize effectively.
Because EPUB publications rely heavily on the XML document format,
this library also provides utility methods for parsing, manipulating,
and building XML documents. The underlying XML operations are based
on fast-xml-parser.
Usage
The entrypoint to the library is through the Epub class. An Epub can
either be read from an existing EPUB publication file, or created
from scratch.
Reading from a file
import { Epub } from "@smoores/epub"
const epub = await Epub.from("path/to/book.epub")
console.log(await epub.getTitle())
Creating from scratch
When creating an Epub from scratch, the title, language, and
identifier must be provided, as these are required for all
publications by the EPUB 3 specification.
Other Dublin Core and non-core metadata may also be provided at
creation time, or may be added incrementally after creation.
import { randomUUID } from "node:crypto"
import { Epub } from "@smoores/epub"
const epub = await Epub.create({
title: "S'mores For Everyone",
// This should be the primary language of the publication.
// Individual content resources may specify their own languages.
language: new Intl.Locale("en-US"),
// This can be any unique identifier, including UUIDs, ISBNs, etc
identifier: randomUUID(),
})
Adding a chapter
import { Epub, ManifestItem } from "@smoores/epub"
const epub = await Epub.from("path/to/book.epub")
// Construct a manifest item describing the chapter
const manifestItem: ManifestItem = {
id: "chapter-one",
// This is the filepath for the chapter contents within the
// EPUB archive.
href: "XHTML/chapter-one.xhtml",
mediaType: "application/xhtml+xml",
}
// You can specify the contents as a string
const contents = `
Chapter 1
At first, there were s'mores.
`
// Or you can specify the contents as an XML structure
const xmlContents = epub.createXhtmlDocument([
Epub.createXmlElement("h1", {}, [Epub.createXmlTextNode("Chapter 1")]),
Epub.createXmlElement("p", {}, [
Epub.createXmlTextNode("At first, there were s'mores."),
]),
])
// First, add the new item to the manifest, and add
// its contents to the publication
await epub.addManifestItem(manifestItem, contents, "utf-8")
// OR, using the XMl:
await epub.addManifestItem(manifestItem, xmlContents, "xml")
// Then add the item to the spine
await epub.addSpineItem(manifestItem.id)
For more details about using the API, see the API documentation.
Development
This package lives in the Storyteller monorepo, and is developed
alongside the Storyteller platform.
To get started with developing in the Storyteller monorepo, check out
the development guides in the docs.
API Docs
* Epub
+ Link
+ Properties
o xhtmlBuilder
o xhtmlParser
o xmlBuilder
o xmlParser
+ Methods
o addContributor()
o addCreator()
o addManifestItem()
o addMetadata()
o addSpineItem()
o addSubject()
o close()
o createXhtmlDocument()
o getContributors()
o getCoverImage()
o getCoverImageItem()
o getCreators()
o getLanguage()
o getManifest()
o getMetadata()
o getPublicationDate()
o getSpineItems()
o getSubjects()
o getTitle()
o getType()
o readItemContents()
o readXhtmlItemContents()
o removeManifestItem()
o removeSpineItem()
o replaceMetadata()
o setCoverImage()
o setLanguage()
o setPublicationDate()
o setTitle()
o setType()
o updateManifestItem()
o writeItemContents()
o writeToFile()
o writeXhtmlItemContents()
o addLinkToXhtmlHead()
o create()
o createXmlElement()
o createXmlTextNode()
o findXmlChildByName()
o formatSmilDuration()
o from()
o getXhtmlBody()
o getXhtmlTextContent()
o getXmlChildren()
o getXmlElementName()
o isXmlTextNode()
* AlternateScript
+ Properties
o locale
o name
* DcCreator
+ Properties
o alternateScripts?
o fileAs?
o name
o role?
* DcSubject
+ Properties
o authority
o term
o value
* DublinCore
+ Properties
o contributors?
o creators?
o date?
o identifier
o language
o subjects?
o title
o type?
* ElementName
+ Defined in
* EpubMetadata
+ Defined in
* ManifestItem
+ Type declaration
o fallback?
o href
o id
o mediaOverlay?
o mediaType?
o properties?
+ Defined in
* MetadataEntry
+ Type declaration
o id?
o properties
o type
o value
+ Defined in
* ParsedXml
+ Defined in
* XmlElement
+ Type declaration
o :@?
+ Type Parameters
+ Defined in
* XmlNode
+ Defined in
* XmlTextNode
+ Type declaration
o #text
+ Defined in
Epub
A single EPUB instance.
The entire EPUB contents will be read into memory.
Example usage:
import { Epub, getBody, findByName, textContent } from "@smoores/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()
Link
https://www.w3.org/TR/epub-33/
Properties
xhtmlBuilder
static xhtmlBuilder: XMLBuilder
Defined in
index.ts:229
xhtmlParser
static xhtmlParser: XMLParser
Defined in
index.ts:197
xmlBuilder
static xmlBuilder: XMLBuilder
Defined in
index.ts:222
xmlParser
static xmlParser: XMLParser
Defined in
index.ts:190
Methods
addContributor()
addContributor(contributor, index?): Promise
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
Parameter Type
contributor DcCreator
index? number
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-opf-dccreator
Defined in
index.ts:1299
addCreator()
addCreator(creator, index?, type?): Promise
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
Parameter Type Default value
creator DcCreator undefined
index? number undefined
type? "creator" | "contributor" "creator"
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-opf-dccreator
Defined in
index.ts:1201
addManifestItem()
Call Signature
addManifestItem(item, contents, encoding): Promise
Create a new manifest item and write its contents to a new entry.
Parameters
Parameter Type Description
item ManifestItem -
The new contents. May be either a parsed XML
contents ParsedXml tree or a unicode string, as determined by the
as argument.
Optional - whether to interpret contents as a
encoding "xml" parsed XML tree, a unicode string, or a byte
array. Defaults to a byte array.
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-pkg-manifest
Link
https://www.w3.org/TR/epub-33/#sec-contentdocs
Defined in
index.ts:1680
Call Signature
addManifestItem(item, contents, encoding): Promise
Create a new manifest item and write its contents to a new entry.
Parameters
Parameter Type Description
item ManifestItem -
The new contents. May be either a parsed XML
contents string tree or a unicode string, as determined by the
as argument.
Optional - whether to interpret contents as a
encoding "utf-8" parsed XML tree, a unicode string, or a byte
array. Defaults to a byte array.
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-pkg-manifest
Link
https://www.w3.org/TR/epub-33/#sec-contentdocs
Defined in
index.ts:1685
Call Signature
addManifestItem(item, contents): Promise
Create a new manifest item and write its contents to a new entry.
Parameters
Parameter Type Description
item ManifestItem -
Uint8Array The new contents. May be either a parsed
contents XML tree or a unicode string, as
determined by the as argument.
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-pkg-manifest
Link
https://www.w3.org/TR/epub-33/#sec-contentdocs
Defined in
index.ts:1690
addMetadata()
addMetadata(entry): Promise
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
Parameter Type
entry MetadataEntry
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-pkg-metadata
Defined in
index.ts:1828
addSpineItem()
addSpineItem(manifestId, index?): Promise
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
Parameter Type
manifestId string
index? number
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-spine-elem
Defined in
index.ts:1357
addSubject()
addSubject(subject): Promise
Add a subject to the EPUB metadata.
Parameters
Parameter Type Description
subject string | May be a string representing just a schema-less
DcSubject subject name, or a DcSubject object
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-opf-dcsubject
Defined in
index.ts:890
close()
close(): Promise
Close the Epub. Must be called before the Epub goes out of scope/is
garbage collected.
Returns
Promise
Defined in
index.ts:407
createXhtmlDocument()
createXhtmlDocument(body, head?, language?): Promise<(XmlElement
<"html"> | XmlElement<"?xml">)[]>
Create a new XHTML document with the given body and head.
Parameters
Parameter Type Description
body ParsedXml The XML nodes to place in the body of the
document
head? ParsedXml Optional - the XMl nodes to place in the head
language? Locale Optional - defaults to the EPUB's language
Returns
Promise<(XmlElement<"html"> | XmlElement<"?xml">)[]>
Defined in
index.ts:1486
getContributors()
getContributors(): Promise
Retrieve the list of contributors.
This is a convenience method for epub.getCreators('contributor').
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-opf-dccontributor
Defined in
index.ts:1188
getCoverImage()
getCoverImage(): Promise>
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>
Link
https://www.w3.org/TR/epub-33/#sec-cover-image
Defined in
index.ts:793
getCoverImageItem()
getCoverImageItem(): Promise
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
Link
https://www.w3.org/TR/epub-33/#sec-cover-image
Defined in
index.ts:774
getCreators()
getCreators(type): Promise
Retrieve the list of creators.
Parameters
Parameter Type Default value
type "creator" | "contributor" "creator"
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-opf-dccreator
Defined in
index.ts:1130
getLanguage()
getLanguage(): Promise
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
Link
https://www.w3.org/TR/epub-33/#sec-opf-dclanguage
Defined in
index.ts:974
getManifest()
getManifest(): Promise>
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>
Link
https://www.w3.org/TR/epub-33/#sec-pkg-manifest
Defined in
index.ts:613
getMetadata()
getMetadata(): Promise
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
Link
https://www.w3.org/TR/epub-33/#sec-pkg-metadata
Defined in
index.ts:671
getPublicationDate()
getPublicationDate(): Promise
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
Link
https://www.w3.org/TR/epub-33/#sec-opf-dcdate
Defined in
index.ts:830
getSpineItems()
getSpineItems(): Promise
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
Link
https://www.w3.org/TR/epub-33/#sec-spine-elem
Defined in
index.ts:1338
getSubjects()
getSubjects(): Promise<(string | DcSubject)[]>
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)[]>
Link
https://www.w3.org/TR/epub-33/#sec-opf-dcsubject
Defined in
index.ts:929
getTitle()
getTitle(short): Promise
Retrieve the title of the Epub.
Parameters
Parameter Type Default Description
value
Optional - whether to return only the first
short boolean false title segment if multiple are found.
Otherwise, will follow the spec to combine
title segments
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-opf-dctitle
Defined in
index.ts:1016
getType()
getType(): Promise
Retrieve the publication type from the dc:type element in the EPUB
metadata.
If there is no dc:type element, returns null.
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-opf-dctype
Defined in
index.ts:877
readItemContents()
Call Signature
readItemContents(id): Promise>
Retrieve the contents of a manifest item, given its id.
Parameters
Parameter Type Description
id string The id of the manifest item to retrieve
Returns
Promise>
Link
https://www.w3.org/TR/epub-33/#sec-contentdocs
Defined in
index.ts:1458
Call Signature
readItemContents(id, encoding): Promise
Retrieve the contents of a manifest item, given its id.
Parameters
Parameter Type Description
id string The id of the manifest item to retrieve
Optional - must be the string "utf-8". If provided,
encoding "utf-8" the function will encode the data into a unicode
string. Otherwise, the data will be returned as a
byte array.
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-contentdocs
Defined in
index.ts:1459
readXhtmlItemContents()
Call Signature
readXhtmlItemContents(id, as?): Promise
Retrieves the contents of an XHTML item, given its manifest id.
Parameters
Parameter Type Description
id string The id of the manifest item to retrieve
Optional - whether to return the parsed XML
as? "xhtml" document tree, or the concatenated text of the
document. Defaults to the parsed XML tree.
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-xhtml
Defined in
index.ts:1519
Call Signature
readXhtmlItemContents(id, as): Promise
Retrieves the contents of an XHTML item, given its manifest id.
Parameters
Parameter Type Description
id string The id of the manifest item to retrieve
Optional - whether to return the parsed XML document
as "text" tree, or the concatenated text of the document.
Defaults to the parsed XML tree.
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-xhtml
Defined in
index.ts:1520
removeManifestItem()
removeManifestItem(id): Promise
Parameters
Parameter Type
id string
Returns
Promise
Defined in
index.ts:1620
removeSpineItem()
removeSpineItem(index): Promise
Remove the spine item at the specified index.
Parameters
Parameter Type
index number
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-spine-elem
Defined in
index.ts:1405
replaceMetadata()
replaceMetadata(predicate, entry): Promise
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
Parameter Type Description
(entry) => Calls predicate once for each metadata entry,
predicate boolean until it finds one where predicate returns
true
entry MetadataEntry The new entry to replace the found entry with
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-pkg-metadata
Defined in
index.ts:1876
setCoverImage()
setCoverImage(href, data): Promise
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
Parameter Type
href string
data Uint8Array
Returns
Promise
Defined in
index.ts:807
setLanguage()
setLanguage(locale): Promise
Update the Epub's language metadata entry.
Updates the existing dc:language element if one exists. Otherwise
creates a new element
Parameters
Parameter Type
locale Locale
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-opf-dclanguage
Defined in
index.ts:999
setPublicationDate()
setPublicationDate(date): Promise
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
Parameter Type
date Date
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-opf-dcdate
Defined in
index.ts:845
setTitle()
setTitle(title): Promise
Set the title of the Epub.
If a title already exists, only the first title metadata entry will
be modified to match the new value.
If no title currently exists, a single title metadata entry will be
created.
Parameters
Parameter Type
title string
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-opf-dctitle
Defined in
index.ts:1091
setType()
setType(type): Promise
Set the dc:type metadata element.
Updates the existing dc:type element if one exists. Otherwise creates
a new element.
Parameters
Parameter Type
type string
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-opf-dctype
Defined in
index.ts:861
updateManifestItem()
updateManifestItem(id, newItem): Promise
Update the manifest entry for an existing item.
To update the contents of an entry, use epub.writeItemContents() or
epub.writeXhtmlItemContents()
Parameters
Parameter Type
id string
newItem Omit
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-pkg-manifest
Defined in
index.ts:1764
writeItemContents()
Call Signature
writeItemContents(id, contents): Promise
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
Parameter Type Description
id string The id of the manifest item to write new
contents for
Uint8Array The new contents. May be either a utf-8
contents encoded string or a byte array, as
determined by the encoding
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-contentdocs
Defined in
index.ts:1572
Call Signature
writeItemContents(id, contents, encoding): Promise
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
Parameter Type Description
id string The id of the manifest item to write new contents
for
The new contents. May be either a utf-8 encoded
contents string string or a byte array, as determined by the
encoding
Optional - must be the string "utf-8". If provided,
encoding "utf-8" the contents will be interpreted as a unicode
string. Otherwise, the contents must be a byte
array.
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-contentdocs
Defined in
index.ts:1573
writeToFile()
writeToFile(path): Promise
Write the current contents of the Epub to a new EPUB archive on disk.
This does not close the Epub. It can continue to be modified after it
has been written to disk. Use epub.close() to close the Epub.
When this method is called, the "dcterms:modified" meta tag is
automatically updated to the current UTC timestamp.
Parameters
Parameter Type Description
The file path to write the new archive to. The
path string parent directory does not need te exist -- the path
will be recursively created.
Returns
Promise
Defined in
index.ts:1940
writeXhtmlItemContents()
writeXhtmlItemContents(id, contents): Promise
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
Parameter Type Description
id string The id of the manifest item to write new contents
for
contents ParsedXml The new contents. Must be a parsed XML tree.
Returns
Promise
Link
https://www.w3.org/TR/epub-33/#sec-xhtml
Defined in
index.ts:1612
addLinkToXhtmlHead()
static addLinkToXhtmlHead(xml, link): void
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
Parameter Type
xml ParsedXml
link { href: string; rel: string; type: string; }
link.href string
link.rel string
link.type string
Returns
void
Defined in
index.ts:259
create()
static create(dublinCore, additionalMetadata): Promise
Construct an Epub instance, optionally beginning with the provided
metadata.
Parameters
Parameter Type Default Description
value
dublinCore DublinCore undefined Core metadata terms
additionalMetadata EpubMetadata [] An array of additional
metadata entries
Returns
Promise
Defined in
index.ts:423
createXmlElement()
static createXmlElement(name, properties, children):
XmlElement
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
Parameter Type Default value
name Name undefined
properties Record undefined
children XmlNode[] []
Returns
XmlElement
Defined in
index.ts:294
createXmlTextNode()
static createXmlTextNode(text): XmlTextNode
Parameters
Parameter Type
text string
Returns
XmlTextNode
Defined in
index.ts:307
findXmlChildByName()
static findXmlChildByName(name, xml, filter?): undefined |
XmlElement
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
Parameter Type
name Name
xml ParsedXml
filter? (node) => boolean
Returns
undefined | XmlElement
Defined in
index.ts:360
formatSmilDuration()
static formatSmilDuration(duration): string
Format a duration, provided as a number of seconds, as a SMIL clock
value, to be used for Media Overlays.
Parameters
Parameter Type
duration number
Returns
string
Link
https://www.w3.org/TR/epub-33/#sec-duration
Defined in
index.ts:242
from()
static from(path): Promise
Construct an Epub instance by reading an EPUB file from path.
Parameters
Parameter Type Description
path string Must be a valid filepath to an EPUB archive
Returns
Promise
Defined in
index.ts:502
getXhtmlBody()
static getXhtmlBody(xml): ParsedXml
Given an XML structure representing a complete XHTML document, return
the sub-structure representing the children of the document's body
element.
Parameters
Parameter Type
xml ParsedXml
Returns
ParsedXml
Defined in
index.ts:284
getXhtmlTextContent()
static getXhtmlTextContent(xml): string
Given an XML structure representing a complete XHTML document, return
a string representing the concatenation of all text nodes in the
document.
Parameters
Parameter Type
xml ParsedXml
Returns
string
Defined in
index.ts:316
getXmlChildren()
static getXmlChildren(element): ParsedXml
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
Parameter Type
element XmlElement
Returns
ParsedXml
Defined in
index.ts:348
getXmlElementName()
static getXmlElementName(element): Name
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
Parameter Type
element XmlElement
Returns
Name
Defined in
index.ts:333
isXmlTextNode()
static isXmlTextNode(node): node is XmlTextNode
Given an XMLNode, determine whether it represents a text node or an
XML element.
Parameters
Parameter Type
node XmlNode
Returns
node is XmlTextNode
Defined in
index.ts:373
---------------------------------------------------------------------
AlternateScript
Properties
locale
locale: Locale
Defined in
index.ts:141
name
name: string
Defined in
index.ts:140
---------------------------------------------------------------------
DcCreator
Properties
alternateScripts?
optional alternateScripts: AlternateScript[]
Defined in
index.ts:148
fileAs?
optional fileAs: string
Defined in
index.ts:147
name
name: string
Defined in
index.ts:145
role?
optional role: string
Defined in
index.ts:146
---------------------------------------------------------------------
DcSubject
Properties
authority
authority: string
Defined in
index.ts:135
term
term: string
Defined in
index.ts:136
value
value: string
Defined in
index.ts:134
---------------------------------------------------------------------
DublinCore
Properties
contributors?
optional contributors: DcCreator[]
Defined in
index.ts:158
creators?
optional creators: DcCreator[]
Defined in
index.ts:157
date?
optional date: Date
Defined in
index.ts:155
identifier
identifier: string
Defined in
index.ts:154
language
language: Locale
Defined in
index.ts:153
subjects?
optional subjects: (string | DcSubject)[]
Defined in
index.ts:156
title
title: string
Defined in
index.ts:152
type?
optional type: string
Defined in
index.ts:159
---------------------------------------------------------------------
ElementName
ElementName: `${Letter | Uppercase | QuestionMark}$
{string}`
A valid name for an XML element (must start with a letter)
Defined in
index.ts:62
---------------------------------------------------------------------
EpubMetadata
EpubMetadata: MetadataEntry[]
Defined in
index.ts:131
---------------------------------------------------------------------
ManifestItem
ManifestItem: object
Type declaration
fallback?
optional fallback: string
href
href: string
id
id: string
mediaOverlay?
optional mediaOverlay: string
mediaType?
optional mediaType: string
properties?
optional properties: string[]
Defined in
index.ts:81
---------------------------------------------------------------------
MetadataEntry
MetadataEntry: object
Type declaration
id?
optional id: string
properties
properties: Record
type
type: ElementName
value
value: string | undefined
Defined in
index.ts:124
---------------------------------------------------------------------
ParsedXml
ParsedXml: XmlNode[]
An XML structure
Defined in
index.ts:79
---------------------------------------------------------------------
XmlElement
XmlElement: object & { [key in Name]: ParsedXml }
An XML element
Type declaration
:@?
optional :@: Record
Type Parameters
Type Parameter Default type
Name extends ElementName ElementName
Defined in
index.ts:66
---------------------------------------------------------------------
XmlNode
XmlNode: XmlElement | XmlTextNode
A valid XML node. May be either an element or a text node.
Defined in
index.ts:76
---------------------------------------------------------------------
XmlTextNode
XmlTextNode: object
A text node in an XML document
Type declaration
#text
#text: string
Defined in
index.ts:73
Readme
Keywords
none
Package Sidebar
Install
npm i @smoores/epub
Weekly Downloads
124
Version
0.1.2
License
none
Unpacked Size
139 kB
Total Files
5
Last publish
2 hours ago
Collaborators
* smoores
Try on RunKit
Report malware
Footer
Support
* Help
* Advisories
* Status
* Contact npm
Company
* About
* Blog
* Press
Terms & Policies
* Policies
* Terms of Use
* Code of Conduct
* Privacy