
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
@ridi/epub-parser
Advanced tools
Common EPUB2 data parser for Ridibooks services written in ES6
readOptions.spine.serializedAnchor
optionreadOptions.spine.truncate
and readOption.spine.truncateMaxLength
optionsreadOptions.spine.minify
and readOptions.css.minify
optionsreadOptions.removeExternalRefs
optionnpm install @ridi/epub-parser
import EpubParser from '@ridi/epub-parser';
const parser = new EpubParser('./foo/bar.epub' or './unzippedPath');
parser.parse().then((book) => {
parser.readItems(book.spines).then((results) => {
...
});
...
});
Returns Promise<Book>
with:
Or throw exception.
object
Returns string
or object
or Buffer
in Promise
(see detail) or throw exception.
Item
(see: Item Types)object
Returns string[]
or object[]
or Buffer[]
in Promise
(see detail) or throw exception.
Item[]
(see: Item Types)object
string
(readOptions.spine.extractBody is false
)
object
(readOptions.spine.extractAdapter is undefined
):
body
: Same reuslt as document.body.innerHTML
attrs
: Attributes in body tag.object
(readOptions.spine.extractAdapter is defaultExtractAdapter):
content
: extractBody
output transformed by adapter.CssItem, InlineCssItem, NcxItem, SvgItem:
string
Other items:
Buffer
boolean
If true, validation package specifications in IDPF listed below.
mimetype
file must be first file in archive.mimetype
file should not compressed.mimetype
file should only contain string application/epub+zip
.Default: false
boolean
If true, stop parsing when XML parsing errors occur.
Default: false
boolean
If false, stop parsing when NCX file not exists.
Default: true
string?
If specified, uncompress to that path.
Only if input is EPUB file.
Default: undefined
boolean
If true, creates intermediate directories for unzipPath.
Default: true
boolean
If true, removes a previous file from unzipPath.
Default: true
boolean
If true, ignore spineIndex
difference caused by isLinear
property of SpineItem.
// e.g. If left is false, right is true.
[{ spineIndex: 0, isLinear: true, ... }, [{ spineIndex: 0, isLinear: true, ... },
{ spineIndex: 1, isLinear: true, ... }, { spineIndex: 1, isLinear: true, ... },
{ spineIndex: -1, isLinear: false, ... }, { spineIndex: 2, isLinear: false, ... },
{ spineIndex: 2, isLinear: true, ... }] { spineIndex: 3, isLinear: true, ... }]
Default: true
boolean
If true, One namespace is given per CSS file or inline style, and styles used for spine is described.
Otherwise it CssItem.namespace
, SpineItem.styles
is undefined
.
In any list, InlineCssItem is always positioned after CssItem. (Book.styles
, Book.items
, SpineItem.styles
, ...)
Default: false
string
Prepend given string to namespace for identification.
Default: 'ridi_style'
string?
If specified, change base path of paths used by spine and css.
HTML: SpineItem
...
<!-- Before -->
<div>
<img src="../Images/cover.jpg">
</div>
<!-- After -->
<div>
<img src="{basePath}/OEBPS/Images/cover.jpg">
</div>
...
CSS: CssItem, InlineCssItem
/* Before */
@font-face {
font-family: NotoSansRegular;
src: url("../Fonts/NotoSans-Regular.ttf");
}
/* After */
@font-face {
font-family: NotoSansRegular;
src: url("{basePath}/OEBPS/Fonts/NotoSans-Regular.ttf");
}
Default: undefined
boolean
If true, extract body. Otherwise it returns a full string.
true:
{
body: '\n <p>Extract style</p>\n <img src=\"../Images/api-map.jpg\"/>\n',
attrs: [
{
key: 'style',
value: 'background-color: #000000;',
},
{ // Only added if useStyleNamespace is true.
key: 'class',
value: '.ridi_style2, .ridi_style3, .ridi_style4, .ridi_style0, .ridi_style1',
},
],
}
false:
'<!doctype><html>\n<head>\n</head>\n<body style="background-color: #000000;">\n <p>Extract style</p>\n <img src=\"../Images/api-map.jpg\"/>\n</body>\n</html>'
Default: false
function
If specified, transforms output of extractBody.
Define adapter:
const extractAdapter = (body, attrs) => {
let string = '';
attrs.forEach((attr) => {
string += ` ${attr.key}=\"${attr.value}\"`;
});
return {
content: `<article${string}>${body}</article>`,
};
};
Result:
{
content: '<article style=\"background-color: #000000;\" class=\".ridi_style2, .ridi_style3, .ridi_style4, .ridi_style0, .ridi_style1\">\n <p>Extract style</p>\n <img src=\"../Images/api-map.jpg\"/>\n</article>',
}
Default: defaultExtractAdapter
string[]
Remove at-rules.
Default: ['charset', 'import', 'keyframes', 'media', 'namespace', 'supports']
string[]
Remove selector that point to specified tags.
Default: []
string[]
Remove selector that point to specified ids.
Default: []
string[]
Remove selector that point to specified classes.
Default: []
[0.0.2 (2018-09-11)]
FAQs
Common EPUB2 data parser for Ridibooks services
We found that @ridi/epub-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.