Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
@ridi/epub-parser
Advanced tools
Common EPUB2 data parser for Ridibooks services
npm install @ridi/epub-parser
Basic:
import { EpubParser } from '@ridi/epub-parser';
// or const { EpubParser } = require('@ridi/epub-parser');
const parser = new EpubParser('./foo/bar.epub' or './unzippedPath');
parser.parse(/* { parseOptions } */).then((book) => {
parser.readItems(book.spines/*, { readOptions } */).then((results) => {
...
});
...
});
with Cryptor:
import { CryptoProvider, Cryptor } from '@ridi/epub-parser';
// or const { CryptoProvider, Cryptor } = require('@ridi/epub-parser');
const { Status } = CryptoProvider;
const { Modes, Padding } = Cryptor;
class ContentCryptoProvider extends CryptoProvider {
constructor(key) {
super();
this.cryptor = new Cryptor(Modes.ECB, { key, padding: Padding.PKCS7 });
}
// Encrypt all content when unzipping and decrypt it when read.
run(data, filePath) {
if (this.status === Status.UNZIP) {
return this.encrypt(data);
} else if (this.status === Status.READ) {
return Buffer.from(this.decrypt(data));
}
return data;
}
encrypt(data, filePath) {
return this.cryptor.encrypt(data);
}
decrypt(data, filePath) {
return this.cryptor.decrypt(data);
}
}
const cryptoProvider = new ContentCryptoProvider(key);
const parser = new EpubParser('./foo/bar.epub' or './unzippedPath', cryptoProvider);
Returns Promise<Book>
with:
Or throw exception.
?object
Returns string
or Buffer
in Promise
with:
SpineItem, CssItem, InlineCssItem, NcxItem, SvgItem:
string
Other items:
Buffer
or throw exception.
Item
(see: Item Types)?object
Returns string[]
or Buffer[]
in Promise
with:
SpineItem, CssItem, InlineCssItem, NcxItem, SvgItem:
string[]
Other items:
Buffer[]
or throw exception.
Item[]
(see: Item Types)?object
boolean
If true, validation package specifications in IDPF listed below.
only using if input is EPUB file.
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 false, stop parsing when NCX file not exists.
Default: true
?string
If specified, uncompress to that path.
only using if input is EPUB file.
Default: undefined
boolean
If true, overwrite to unzipPath when uncompress.
only using if unzipPath specified.
Default: true
boolean
If true, ignore index
difference caused by isLinear
property of SpineItem.
// e.g. If left is false, right is true.
[{ index: 0, isLinear: true, ... }, [{ index: 0, isLinear: true, ... },
{ index: 1, isLinear: true, ... }, { index: 1, isLinear: true, ... },
{ index: -2, isLinear: false, ... }, { index: 2, isLinear: false, ... },
{ index: 3, isLinear: true, ... }] { index: 3, isLinear: true, ... }]
Default: false
boolean
If true, styles used for spine is described, and one namespace is given per CSS file or inline style.
Otherwise it CssItem.namespace
, SpineItem.styles
is undefined
.
In any list, InlineCssItem is always positioned after CssItem. (Book.styles
, Book.items
, SpineItem.styles
, ...)
Default: true
string
Prepend given string to namespace for identification.
only using if parseStyle is true.
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|function
If true, extract body. Otherwise it returns a full string. If specify a function instead of true, use function to transform body.
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>'
true
:
'<body style="background-color: #000000;">\n <p>Extract style</p>\n <img src=\"../Images/api-map.jpg\"/>\n</body>'
function
:
readOptions.extractBody = (innerHTML, attrs) => {
const string = attrs.map((attr) => {
return ` ${attr.key}=\"${attr.value}\"`;
}).join(' ');
return `<article ${string}>${innerHTML}</article>`;
};
'<article style="background-color: #000000;">\n <p>Extract style</p>\n <img src=\"../Images/api-map.jpg\"/>\n</article>'
Default: false
Boolean
If true, replace file path of anchor in spine with spine index.
...
<spine toc="ncx">
<itemref idref="Section0001.xhtml"/> <!-- index: 0 -->
<itemref idref="Section0002.xhtml"/> <!-- index: 1 -->
<itemref idref="Section0003.xhtml"/> <!-- index: 2 -->
...
</spine>
...
<!-- Before -->
<a href="./Text/Section0002.xhtml#title">Chapter 2</a>
<!-- After -->
<a href="1#title">Chapter 2</a>
Default: false
string[]
Remove at-rules.
Default: []
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: []
FAQs
Common EPUB2 data parser for Ridibooks services
The npm package @ridi/epub-parser receives a total of 43 weekly downloads. As such, @ridi/epub-parser popularity was classified as not popular.
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
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.