New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ridi/epub-parser

Package Overview
Dependencies
Maintainers
12
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ridi/epub-parser - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

131

lib/EpubParser.js

@@ -205,3 +205,3 @@ 'use strict';

* @param {string} input file or directory
* @param {CryptoProvider} cryptoProvider en/decrypto provider
* @param {?CryptoProvider} cryptoProvider en/decrypto provider
* @throws {Errors.ENOENT} no such file or directory

@@ -261,3 +261,3 @@ * @throws {Errors.EINVAL} invalid input

EpubParser.prototype._parseTasks = function _parseTasks() {
return [].concat((0, _toConsumableArray3.default)(_Parser.prototype._parseTasks.call(this)), [{ func: this._validatePackageIfNeeded, name: 'validatePackageIfNeeded' }, { func: this._parseMetaInf, name: 'parseMetaInf' }, { func: this._parseOpf, name: 'parseOpf' }, { func: this._parseNcx, name: 'parseNcx' }]);
return [].concat((0, _toConsumableArray3.default)(_Parser.prototype._parseTasks.call(this)), [{ fun: this._validatePackageIfNeeded, name: 'validatePackageIfNeeded' }, { fun: this._parseMetaInf, name: 'parseMetaInf' }, { fun: this._parseOpf, name: 'parseOpf' }, { fun: this._parseNcx, name: 'parseNcx' }]);
};

@@ -271,3 +271,3 @@

EpubParser.prototype._parseAfterTasks = function _parseAfterTasks() {
return [].concat((0, _toConsumableArray3.default)(_Parser.prototype._parseAfterTasks.call(this)), [{ func: this._checkResult, name: 'checkResult' }]);
return [].concat((0, _toConsumableArray3.default)(_Parser.prototype._parseAfterTasks.call(this)), [{ fun: this._checkResult, name: 'checkResult' }]);
};

@@ -299,6 +299,5 @@

firstEntry = context.entries.first; // TODO: If no first one
firstEntry = context.entries.first;
_context.next = 5;
return firstEntry.getFile('utf8');
return firstEntry.getFile({ encoding: 'utf8' });

@@ -391,3 +390,3 @@ case 5:

_context2.next = 7;
return containerEntry.getFile('utf8');
return containerEntry.getFile({ encoding: 'utf8' });

@@ -416,5 +415,3 @@ case 7:

rootfiles = container.rootfiles;
// eslint-disable-next-line arrow-body-style
rootfile = ((0, _parserCore.isArray)(rootfiles) ? rootfiles : [rootfiles.rootfile]).find(function (item) {
rootfile = ((0, _parserCore.isArray)(rootfiles.rootfile) ? rootfiles.rootfile : [rootfiles.rootfile]).find(function (item) {
return item['media-type'] === 'application/oebps-package+xml';

@@ -493,3 +490,3 @@ });

_context4.next = 7;
return opfEntry.getFile('utf8');
return opfEntry.getFile({ encoding: 'utf8' });

@@ -640,3 +637,2 @@ case 7:

return items.reduce(function (prevPromise, item, idx) {
// eslint-disable-line arrow-body-style
return prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4() {

@@ -821,3 +817,3 @@ var rawItem, itemEntry, refIndex, ref, result;

_context7.next = 7;
return entry.getFile('utf8');
return entry.getFile({ encoding: 'utf8' });

@@ -828,9 +824,29 @@ case 7:

html = find(document, 'tagName', 'html');
if ((0, _parserCore.isExists)(html)) {
_context7.next = 13;
break;
}
this.logger.error('Can not analyze style in \'' + rawItem.href + '\'. (reason: no html tag)');
return _context7.abrupt('return', { styles: styles, inlineStyles: inlineStyles });
case 13:
head = find(html.children, 'tagName', 'head');
if ((0, _parserCore.isExists)(head)) {
_context7.next = 17;
break;
}
this.logger.error('Can not analyze style in \'' + rawItem.href + '\'. (reason: no head tag)');
return _context7.abrupt('return', { styles: styles, inlineStyles: inlineStyles });
case 17:
// <link rel="stylesheet" type="text/css" href="..." ... />
// ^~~
filter(head.children, 'tagName', 'link').forEach(function (link) {
var attrs = link.attributes;
/* istanbul ignore else */

@@ -840,4 +856,6 @@ if ((0, _parserCore.isExists)(attrs)) {

var type = find(attrs, 'key', 'type');
/* istanbul ignore else */
if ((0, _parserCore.isExists)(rel) && rel.value === 'stylesheet' || (0, _parserCore.isExists)(type) && type.value === 'text/css') {
var href = find(attrs, 'key', 'href');
/* istanbul ignore else */
if ((0, _parserCore.isExists)(href) && (0, _parserCore.isExists)(href.value) && !(0, _parserCore.isUrl)(href.value)) {

@@ -855,6 +873,8 @@ // href="../Styles/Style0001.css" => href="OEBPS/Styles/Style0001.css"

var firstNode = style.children[0];
/* istanbul ignore else */
if ((0, _parserCore.isExists)(firstNode)) {
var namespace = '' + options.styleNamespacePrefix + idx;
var href = rawItem.href + '_' + namespace;
var content = firstNode.content || '';
var content = firstNode.content;
var inlineStyleItem = {

@@ -876,3 +896,3 @@ id: rawItem.id + '_' + namespace,

case 14:
case 20:
case 'end':

@@ -908,6 +928,7 @@ return _context7.stop();

(0, _xmlLoader4.getValues)(guide.reference).forEach(function (reference) {
reference = (0, _parserCore.mergeObjects)(reference, { href: (0, _parserCore.safePathJoin)(context.basePath, reference.href) });
// If reference.type equal 'cover' and there is an image item matching reference.href, it is cover image.
if (!foundCover && (0, _parserCore.isExists)(reference.type) && reference.type.toLowerCase() === _Guide2.default.Types.COVER) {
var imageItem = rawBook.items.find(function (item) {
return item.href === reference.href && item.itemType === _ImageItem2.default;
return item.itemType === _ImageItem2.default && item.href === reference.href;
});

@@ -919,3 +940,3 @@ if ((0, _parserCore.isExists)(imageItem)) {

}
rawBook.guides.push((0, _parserCore.mergeObjects)(reference, { href: (0, _parserCore.safePathJoin)(context.basePath, reference.href) }));
rawBook.guides.push(reference);
});

@@ -941,4 +962,6 @@ }

var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7(context) {
var rawBook, entries, options, allowNcxFileMissing, ncxItem, ncxEntry, _xmlLoader3, ncx, normalizeSrc, keyTranslator;
var _this3 = this;
var rawBook, entries, options, allowNcxFileMissing, ncxItem, ncxEntry, _xmlLoader3, ncx, normalizeSrc, keyTranslator, prevNcxItem;
return _regenerator2.default.wrap(function _callee7$(_context8) {

@@ -955,3 +978,3 @@ while (1) {

if (!(0, _parserCore.isExists)(ncxItem)) {
_context8.next = 23;
_context8.next = 21;
break;

@@ -962,15 +985,24 @@ }

if (!(!allowNcxFileMissing && !(0, _parserCore.isExists)(ncxEntry))) {
_context8.next = 7;
break;
}
// toc.ncx
// <?xml ... ?>
// <!DOCTYPE ncx ... >
// <ncx ... >
// ...
// <navMap>
// <navPoint id="..." playOrder="...">
// <navLabel><text>...</text></navLabel>
// <content src="..." />
// {<navPoint>...</navPoint>}
// </navPoint>
// ...
// </navMap>
// ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ...
// </ncx>
throw (0, _parserCore.createError)(_parserCore.Errors.ENOFILE, ncxItem.href);
case 7:
_context8.t0 = _xmlLoader5.default;
_context8.next = 10;
return ncxEntry.getFile('utf8');
_context8.next = 8;
return ncxEntry.getFile({ encoding: 'utf8' });
case 10:
case 8:
_context8.t1 = _context8.sent;

@@ -981,3 +1013,3 @@ _xmlLoader3 = (0, _context8.t0)(_context8.t1);

if ((0, _parserCore.isExists)(ncx)) {
_context8.next = 15;
_context8.next = 13;
break;

@@ -988,5 +1020,5 @@ }

case 15:
case 13:
if ((0, _parserCore.isExists)(ncx.navMap)) {
_context8.next = 17;
_context8.next = 15;
break;

@@ -997,3 +1029,3 @@ }

case 17:
case 15:

@@ -1020,10 +1052,18 @@ ncxItem.navPoints = [];

(0, _xmlLoader4.getValues)(ncx.navMap.navPoint, keyTranslator).forEach(function (navPoint) {
// eslint-disable-line arrow-body-style
return ncxItem.navPoints.push(normalizeSrc(navPoint));
});
_context8.next = 25;
_context8.next = 26;
break;
case 23:
case 21:
if (allowNcxFileMissing) {
_context8.next = 26;
break;
}
prevNcxItem = rawBook.items.find(function (item) {
return _this3.getItemTypeFromMediaType(item.mediaType) === _NcxItem2.default && item.itemType === _DeadItem2.default;
});
if (!(0, _parserCore.isExists)(prevNcxItem)) {
_context8.next = 25;

@@ -1033,8 +1073,11 @@ break;

throw (0, _parserCore.createError)(_parserCore.Errors.ENOFILE, prevNcxItem.href);
case 25:
throw (0, _parserCore.createError)(_parserCore.Errors.EINVAL, 'opf', 'reason', 'can not found ncx attribute');
case 25:
case 26:
return _context8.abrupt('return', context);
case 26:
case 27:
case 'end':

@@ -1063,2 +1106,5 @@ return _context8.stop();

}
if (!(0, _parserCore.isExists)(book.ncx)) {
this.logger.warn('NCX not found in EPUB.');
}
return book;

@@ -1078,3 +1124,3 @@ };

var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(context) {
var _this3 = this;
var _this4 = this;

@@ -1090,3 +1136,2 @@ var items, entries, options, results;

return items.reduce(function (prevPromise, item) {
// eslint-disable-line arrow-body-style
return prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8() {

@@ -1118,3 +1163,3 @@ var entry, file;

_context9.next = 8;
return entry.getFile(item.defaultEncoding);
return entry.getFile({ encoding: item.defaultEncoding });

@@ -1137,3 +1182,3 @@ case 8:

}
}, _callee8, _this3);
}, _callee8, _this4);
})));

@@ -1140,0 +1185,0 @@ }, _promise2.default.resolve());

@@ -91,2 +91,3 @@ 'use strict';

};
/* istanbul ignore else */
if ((0, _parserCore.isExists)(spine.styles)) {

@@ -133,2 +134,3 @@ spine.styles = spine.styles.map(function (href) {

/* istanbul ignore next */
function getItemTypeFromString(string) {

@@ -135,0 +137,0 @@ switch (string) {

@@ -54,3 +54,3 @@ 'use strict';

}
/* istanbul ignore else: untestable */
/* istanbul ignore else */
if (freeze && _this.constructor === CssItem) {

@@ -57,0 +57,0 @@ (0, _freeze2.default)(_this);

@@ -63,3 +63,3 @@ 'use strict';

}
/* istanbul ignore else: untestable */
/* istanbul ignore else */
if (freeze) {

@@ -66,0 +66,0 @@ (0, _freeze2.default)(_this);

@@ -34,12 +34,11 @@ 'use strict';

/* istanbul ignore next */
function FontItem() {
var rawObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _this;
var freeze = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
(0, _classCallCheck3.default)(this, FontItem);
var _ = (_this = (0, _possibleConstructorReturn3.default)(this, _Item.call(this, rawObj, freeze)), _this); // eslint-disable-line
/* istanbul ignore else: untestable */
/* istanbul ignore else */
var _this = (0, _possibleConstructorReturn3.default)(this, _Item.call(this, rawObj, freeze));
if (freeze) {

@@ -46,0 +45,0 @@ (0, _freeze2.default)(_this);

@@ -42,3 +42,3 @@ 'use strict';

_this.isCover = rawObj.isCover || false;
/* istanbul ignore else: untestable */
/* istanbul ignore else */
if (freeze && _this.constructor === ImageItem) {

@@ -45,0 +45,0 @@ (0, _freeze2.default)(_this);

@@ -42,3 +42,3 @@ 'use strict';

_this.style = rawObj.style || '';
/* istanbul ignore else: untestable */
/* istanbul ignore else */
if (freeze) {

@@ -45,0 +45,0 @@ (0, _freeze2.default)(_this);

@@ -43,3 +43,3 @@ "use strict";

this.size = rawObj.size;
/* istanbul ignore else: untestable */
/* istanbul ignore else */
if (freeze && this.constructor === Item) {

@@ -46,0 +46,0 @@ (0, _freeze2.default)(this);

@@ -36,7 +36,6 @@ 'use strict';

this.children = (rawObj.children || []).map(function (child) {
// eslint-disable-line
return new NavPoint((0, _parserCore.mergeObjects)(child, { depth: _this.depth + 1 }), freeze);
});
this.spine = undefined;
/* istanbul ignore else: untestable */
/* istanbul ignore else */
if (freeze) {

@@ -43,0 +42,0 @@ (0, _freeze2.default)(this);

@@ -56,6 +56,5 @@ 'use strict';

_this.navPoints = (rawObj.navPoints || []).map(function (navPoint) {
// eslint-disable-line arrow-body-style
return new _NavPoint2.default(navPoint, freeze);
});
/* istanbul ignore else: untestable */
/* istanbul ignore else */
if (freeze) {

@@ -62,0 +61,0 @@ (0, _freeze2.default)(_this);

@@ -65,3 +65,3 @@ 'use strict';

};
/* istanbul ignore else: untestable */
/* istanbul ignore else */
if (freeze) {

@@ -68,0 +68,0 @@ (0, _freeze2.default)(_this);

@@ -42,14 +42,15 @@ 'use strict';

}
/* istanbul ignore next */
}]);
function SvgItem() /* istanbul ignore next: untestable */{
function SvgItem() {
var rawObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _this;
var freeze = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
(0, _classCallCheck3.default)(this, SvgItem);
var _ = (_this = (0, _possibleConstructorReturn3.default)(this, _ImageItem.call(this, rawObj, freeze)), _this); // eslint-disable-line
/* istanbul ignore else: untestable */
/* istanbul ignore else */
var _this = (0, _possibleConstructorReturn3.default)(this, _ImageItem.call(this, rawObj, freeze));
if (freeze) {

@@ -56,0 +57,0 @@ (0, _freeze2.default)(_this);

{
"name": "@ridi/epub-parser",
"version": "0.3.1",
"version": "0.4.0",
"description": "Common EPUB2 data parser for Ridibooks services",

@@ -27,7 +27,9 @@ "author": {

"files": [
"lib"
"lib",
"../../CHANGELOG.md",
"../../LICENSE"
],
"main": "lib/index.js",
"dependencies": {
"@ridi/parser-core": "^0.3.1",
"@ridi/parser-core": "^0.4.0",
"css-tree": "^1.0.0-alpha.29",

@@ -34,0 +36,0 @@ "fast-xml-parser": "^3.11.2",

@@ -5,5 +5,7 @@ # @ridi/epub-parser

[![npm version](https://badge.fury.io/js/%40ridi%2Fepub-parser.svg)](https://badge.fury.io/js/%40ridi%2Fepub-parser)
[![NPM version](https://badge.fury.io/js/%40ridi%2Fepub-parser.svg)](https://badge.fury.io/js/%40ridi%2Fepub-parser)
[![Build Status](https://travis-ci.org/ridi/content-parser.svg?branch=master)](https://travis-ci.org/ridi/content-parser)
[![codecov](https://codecov.io/gh/ridi/content-parser/branch/master/graph/badge.svg)](https://codecov.io/gh/ridi/content-parser)
[![NPM total downloads](https://img.shields.io/npm/dt/%40ridi%2Fepub-parser.svg)](https://npm.im/%40ridi%2Fepub-parser)
[![Greenkeeper badge](https://badges.greenkeeper.io/ridi/content-parser.svg)](https://greenkeeper.io/)

@@ -20,2 +22,4 @@ ## Features

- [x] Customize CSS, Inline Style with options
- [ ] Truncate inner HTML of body in Spine with options
- [ ] Minify HTML, CSS, Inline Style with options
- [x] Encrypt and decrypt function when parsing or reading or unzipping

@@ -119,5 +123,5 @@ - [ ] More [spec](http://www.idpf.org/epub/30/spec/epub30-ocf.html#sec-container-metainf)

Returns `Promise<Book>` with:
Returns `Promise<EpubBook>` with:
- [Book](#book): Instance with metadata, spine list, table of contents, etc.
- [EpubBook](#book): Instance with metadata, spine list, table of contents, etc.

@@ -175,3 +179,3 @@ Or throw exception.

```js
const { Action } = EpubParser;
const { Action } = EpubParser; // PARSE, READ_ITEMS
parser.onProgress = (step, totalStep, action) => {

@@ -186,3 +190,3 @@ console.log(`[${action}] ${step} / ${totalStep}`);

### [Book](./src/model/Book.js)
### [EpubBook](./src/model/Book.js)

@@ -223,2 +227,38 @@ - titles: *string[]*

#### [Author.Roles](./src/model/Author.js#L4)
Type | Value
---|---
UNDEFINED | undefined
UNKNOWN | unknown
ADAPTER | adp
ANNOTATOR | ann
ARRANGER | arr
ARTIST | art
ASSOCIATEDNAME | asn
AUTHOR | aut
AUTHOR_IN_QUOTATIONS_OR_TEXT_EXTRACTS | aqt
AUTHOR_OF_AFTER_WORD_OR_COLOPHON_OR_ETC | aft
AUTHOR_OF_INTRODUCTIONOR_ETC | aui
BIBLIOGRAPHIC_ANTECEDENT | ant
BOOK_PRODUCER | bkp
COLLABORATOR | clb
COMMENTATOR | cmm
DESIGNER | dsr
EDITOR | edt
ILLUSTRATOR | ill
LYRICIST | lyr
METADATA_CONTACT | mdc
MUSICIAN | mus
NARRATOR | nrt
OTHER | oth
PHOTOGRAPHER | pht
PRINTER | prt
REDACTOR | red
REVIEWER | rev
SPONSOR | spn
THESIS_ADVISOR | ths
TRANSCRIBER | trc
TRANSLATOR | trl
<a id="dateTime"></a>

@@ -231,2 +271,12 @@

#### [DateTime.Events](./src/model/DateTime.js#L3)
Type | Value
---|---
UNDEFINED | undefined
UNKNOWN | unknown
CREATION | creation
MODIFICATION | modification
PUBLICATION | publication
<a id="identifier"></a>

@@ -239,2 +289,16 @@

#### [Identifier.Schemes](./src/model/Identifier.js#L3)
Type | Value
---|---
UNDEFINED | undefined
UNKNOWN | unknown
DOI | doi
ISBN | isbn
ISBN13 | isbn13
ISBN10 | isbn10
ISSN | issn
UUID | uuid
URI | uri
<a id="meta"></a>

@@ -256,2 +320,26 @@

#### [Guide.Types](./src/model/Guide.js#L3)
Type | Value
---|---
UNDEFINED | undefined
UNKNOWN | unknown
COVER | cover
TITLE_PAGE | title-page
TOC | toc
INDEX | index
GLOSSARY | glossary
ACKNOWLEDGEMENTS | acknowledgements
BIBLIOGRAPHY | bibliography
COLOPHON | colophon
COPYRIGHT_PAGE | copyright-page
DEDICATION | dedication
EPIGRAPH | epigraph
FOREWORD | foreword
LOI | loi
LOT | lot
NOTES | notes
PREFACE | preface
TEXT | text
<a id="itemTypes"></a>

@@ -275,5 +363,8 @@

- index: *number* (**Default: -1**)
- index: *number* (**Default: undefined**)
- isLinear: *boolean* (**Default: true**)
- styles: *?[CssItem](#cssItem)[]*
- first: *?[SpineItem](#spineItem)*
- prev: *?[SpineItem](#spineItem)*
- next: *?[SpineItem](#spineItem)*

@@ -314,2 +405,13 @@ <a id="ncxItem"></a>

#### [DeadItem.Reason](./src/model/DeadItem.js#L3)
Type | Value
---|---
UNDEFINED | undefined
UNKNOWN | unknown
NOT_EXISTS | not_exists
NOT_SPINE | not_spine
NOT_NCX | not_ncx
NOT_SUPPORT_TYPE | not_support_type
<a id="navPoint"></a>

@@ -406,3 +508,3 @@

In any list, [InlineCssItem](#inlineCssItem) is always positioned after [CssItem](#CssItem). ([Book](#book)`.styles`, [Book](#book)`.items`, [SpineItem](#spineItem)`.styles`, ...)
In any list, [InlineCssItem](#inlineCssItem) is always positioned after [CssItem](#CssItem). ([EpubBook](#book)`.styles`, [EpubBook](#book)`.items`, [SpineItem](#spineItem)`.styles`, ...)

@@ -422,4 +524,2 @@ **Default:** `true`

---
<a id="readOptions"></a>

@@ -592,2 +692,4 @@

---
## License
[MIT](https://github.com/ridi/content-parser/blob/master/LICENSE)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc