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.0-alpha.5 to 0.3.0-alpha-6

478

lib/EpubParser.js

@@ -111,2 +111,4 @@ 'use strict';

var logger = new _parserCore.Logger('EpubParser');
var EpubParser = function () {

@@ -135,2 +137,12 @@ (0, _createClass3.default)(EpubParser, [{

/**
* Get logger
*/
}, {
key: 'logger',
get: function get() {
return logger;
}
/**
* Create new EpubParser

@@ -274,54 +286,50 @@ * @param {string} input file or directory

EpubParser.prototype.parse = function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
var _this = this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var context, book;
return _regenerator2.default.wrap(function _callee$(_context) {
var tasks, context;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context.prev = _context.next) {
switch (_context2.prev = _context2.next) {
case 0:
_context.next = 2;
return this._prepareParse(options);
tasks = [{ func: this._prepareParse, name: 'prepareParse' }, { func: this._validatePackageIfNeeded, name: 'validatePackageIfNeeded' }, { func: this._parseMetaInf, name: 'parseMetaInf' }, { func: this._parseOpf, name: 'parseOpf' }, { func: this._parseNcx, name: 'parseNcx' }, { func: this._unzipIfNeeded, name: 'unzipIfNeeded' }, { func: this._createBook, name: 'createBook' }];
context = options;
_context2.next = 4;
return tasks.reduce(function (prevPromise, task) {
// eslint-disable-line arrow-body-style
return prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
var func, name;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
func = task.func, name = task.name;
_context.next = 3;
return logger.measure(func, _this, [context], name);
case 2:
context = _context.sent;
_context.next = 5;
return this._validatePackageIfNeeded(context);
case 3:
context = _context.sent;
case 5:
context = _context.sent;
_context.next = 8;
return this._parseMetaInf(context);
case 4:
case 'end':
return _context.stop();
}
}
}, _callee, _this);
})));
}, _promise2.default.resolve());
case 8:
context = _context.sent;
_context.next = 11;
return this._parseOpf(context);
case 4:
if (!(0, _parserCore.isExists)(context.cover)) {
logger.warn('Cover image not found in EPUB.');
}
return _context2.abrupt('return', context);
case 11:
context = _context.sent;
_context.next = 14;
return this._parseNcx(context);
case 14:
context = _context.sent;
_context.next = 17;
return this._unzipIfNeeded(context);
case 17:
context = _context.sent;
_parserCore.Logger.warn('Cover image not found in EPUB.');
_context.next = 21;
return this._createBook(context);
case 21:
book = _context.sent;
return _context.abrupt('return', book);
case 23:
case 6:
case 'end':
return _context.stop();
return _context2.stop();
}
}
}, _callee, this);
}, _callee2, this);
}));

@@ -349,8 +357,8 @@

EpubParser.prototype._prepareParse = function () {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var context;
return _regenerator2.default.wrap(function _callee2$(_context2) {
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context2.prev = _context2.next) {
switch (_context3.prev = _context3.next) {
case 0:

@@ -361,19 +369,19 @@ (0, _parserCore.validateOptions)(options, EpubParser.parseOptionTypes);

context.options = (0, _parserCore.mergeObjects)(EpubParser.parseDefaultOptions, options);
_context2.next = 5;
return (0, _parserCore.readEntries)(this.input, this.cryptoProvider);
_context3.next = 5;
return (0, _parserCore.readEntries)(this.input, this.cryptoProvider, logger);
case 5:
context.entries = _context2.sent;
return _context2.abrupt('return', context);
context.entries = _context3.sent;
return _context3.abrupt('return', context);
case 7:
case 'end':
return _context2.stop();
return _context3.stop();
}
}
}, _callee2, this);
}, _callee3, this);
}));
function _prepareParse() {
return _ref2.apply(this, arguments);
return _ref3.apply(this, arguments);
}

@@ -394,8 +402,8 @@

EpubParser.prototype._validatePackageIfNeeded = function () {
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(context) {
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(context) {
var entries, options, firstEntry, signature, reason, _reason;
return _regenerator2.default.wrap(function _callee3$(_context3) {
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context3.prev = _context3.next) {
switch (_context4.prev = _context4.next) {
case 0:

@@ -405,3 +413,3 @@ entries = context.entries, options = context.options;

if (!(!(0, _parserCore.isString)(entries.source) && options.validatePackage)) {
_context3.next = 22;
_context4.next = 22;
break;

@@ -412,10 +420,10 @@ }

_context3.next = 5;
_context4.next = 5;
return firstEntry.getFile('utf8');
case 5:
signature = _context3.sent;
signature = _context4.sent;
if (!(firstEntry.entryPath !== 'mimetype')) {
_context3.next = 10;
_context4.next = 10;
break;

@@ -428,3 +436,3 @@ }

if (!(firstEntry.method !== 0 /* STORED */)) {
_context3.next = 14;
_context4.next = 14;
break;

@@ -437,3 +445,3 @@ }

if (!(signature !== 'application/epub+zip')) {
_context3.next = 19;
_context4.next = 19;
break;

@@ -447,3 +455,3 @@ }

if (!(firstEntry.extraFieldLength > 0)) {
_context3.next = 22;
_context4.next = 22;
break;

@@ -456,14 +464,14 @@ }

case 22:
return _context3.abrupt('return', context);
return _context4.abrupt('return', context);
case 23:
case 'end':
return _context3.stop();
return _context4.stop();
}
}
}, _callee3, this);
}, _callee4, this);
}));
function _validatePackageIfNeeded(_x3) {
return _ref3.apply(this, arguments);
return _ref4.apply(this, arguments);
}

@@ -486,8 +494,8 @@

EpubParser.prototype._parseMetaInf = function () {
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(context) {
var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(context) {
var entryPath, containerEntry, _xmlLoader, container, rootfiles, rootfile, opfPath;
return _regenerator2.default.wrap(function _callee4$(_context4) {
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context5.prev = _context5.next) {
case 0:

@@ -498,3 +506,3 @@ entryPath = 'META-INF/container.xml';

if ((0, _parserCore.isExists)(containerEntry)) {
_context4.next = 4;
_context5.next = 4;
break;

@@ -506,13 +514,13 @@ }

case 4:
_context4.t0 = _xmlLoader5.default;
_context4.next = 7;
_context5.t0 = _xmlLoader5.default;
_context5.next = 7;
return containerEntry.getFile('utf8');
case 7:
_context4.t1 = _context4.sent;
_xmlLoader = (0, _context4.t0)(_context4.t1);
_context5.t1 = _context5.sent;
_xmlLoader = (0, _context5.t0)(_context5.t1);
container = _xmlLoader.container;
if ((0, _parserCore.isExists)(container)) {
_context4.next = 12;
_context5.next = 12;
break;

@@ -525,3 +533,3 @@ }

if ((0, _parserCore.isExists)(container.rootfiles)) {
_context4.next = 14;
_context5.next = 14;
break;

@@ -541,3 +549,3 @@ }

if ((0, _parserCore.isExists)(rootfile)) {
_context4.next = 18;
_context5.next = 18;
break;

@@ -552,3 +560,3 @@ }

if ((0, _parserCore.isExists)(opfPath)) {
_context4.next = 21;
_context5.next = 21;
break;

@@ -564,14 +572,14 @@ }

return _context4.abrupt('return', context);
return _context5.abrupt('return', context);
case 24:
case 'end':
return _context4.stop();
return _context5.stop();
}
}
}, _callee4, this);
}, _callee5, this);
}));
function _parseMetaInf(_x4) {
return _ref4.apply(this, arguments);
return _ref5.apply(this, arguments);
}

@@ -593,14 +601,14 @@

EpubParser.prototype._parseOpf = function () {
var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(context) {
var _context5, entries, opfPath, opfEntry, _xmlLoader2, root;
var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6(context) {
var _context6, entries, opfPath, opfEntry, _xmlLoader2, root;
return _regenerator2.default.wrap(function _callee5$(_context6) {
return _regenerator2.default.wrap(function _callee6$(_context7) {
while (1) {
switch (_context6.prev = _context6.next) {
switch (_context7.prev = _context7.next) {
case 0:
_context5 = context, entries = _context5.entries, opfPath = _context5.opfPath;
_context6 = context, entries = _context6.entries, opfPath = _context6.opfPath;
opfEntry = entries.find(opfPath);
if ((0, _parserCore.isExists)(opfEntry)) {
_context6.next = 4;
_context7.next = 4;
break;

@@ -612,13 +620,13 @@ }

case 4:
_context6.t0 = _xmlLoader5.default;
_context6.next = 7;
_context7.t0 = _xmlLoader5.default;
_context7.next = 7;
return opfEntry.getFile('utf8');
case 7:
_context6.t1 = _context6.sent;
_xmlLoader2 = (0, _context6.t0)(_context6.t1);
_context7.t1 = _context7.sent;
_xmlLoader2 = (0, _context7.t0)(_context7.t1);
root = _xmlLoader2.package;
if ((0, _parserCore.isExists)(root)) {
_context6.next = 12;
_context7.next = 12;
break;

@@ -631,3 +639,3 @@ }

if (!(!(0, _parserCore.isExists)(root.metadata) || !(0, _parserCore.isExists)(root.manifest) || !(0, _parserCore.isExists)(root.spine))) {
_context6.next = 14;
_context7.next = 14;
break;

@@ -641,29 +649,29 @@ }

context.rawBook.version = root.version;
_context6.next = 17;
_context7.next = 17;
return this._parseMetadata(root.metadata, context);
case 17:
context = _context6.sent;
_context6.next = 20;
context = _context7.sent;
_context7.next = 20;
return this._parseManifestAndSpine(root.manifest, root.spine, context);
case 20:
context = _context6.sent;
_context6.next = 23;
context = _context7.sent;
_context7.next = 23;
return this._parseGuide(root.guide, context);
case 23:
context = _context6.sent;
return _context6.abrupt('return', context);
context = _context7.sent;
return _context7.abrupt('return', context);
case 25:
case 'end':
return _context6.stop();
return _context7.stop();
}
}
}, _callee5, this);
}, _callee6, this);
}));
function _parseOpf(_x5) {
return _ref5.apply(this, arguments);
return _ref6.apply(this, arguments);
}

@@ -742,9 +750,9 @@

EpubParser.prototype._parseManifestAndSpine = function () {
var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7(manifest, spine, context) {
var _this = this;
var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(manifest, spine, context) {
var _this2 = this;
var rawBook, basePath, options, entries, tocId, items, itemRefs, coverMeta, inlineStyles;
return _regenerator2.default.wrap(function _callee7$(_context8) {
return _regenerator2.default.wrap(function _callee8$(_context9) {
while (1) {
switch (_context8.prev = _context8.next) {
switch (_context9.prev = _context9.next) {
case 0:

@@ -762,10 +770,10 @@ rawBook = context.rawBook, basePath = context.basePath, options = context.options, entries = context.entries;

rawBook.items = [];
_context8.next = 9;
_context9.next = 9;
return items.reduce(function (prevPromise, item, idx) {
// eslint-disable-line arrow-body-style
return prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6() {
return prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7() {
var rawItem, itemEntry, refIndex, ref, result;
return _regenerator2.default.wrap(function _callee6$(_context7) {
return _regenerator2.default.wrap(function _callee7$(_context8) {
while (1) {
switch (_context7.prev = _context7.next) {
switch (_context8.prev = _context8.next) {
case 0:

@@ -780,6 +788,6 @@ rawItem = {};

rawItem.mediaType = item['media-type'];
rawItem.itemType = _this.getItemTypeFromMediaType(rawItem.mediaType);
rawItem.itemType = _this2.getItemTypeFromMediaType(rawItem.mediaType);
if (rawItem.itemType === _DeadItem2.default) {
rawItem.reason = _DeadItem2.default.Reason.NOT_SUPPORT_TYPE;
_parserCore.Logger.warn('Referenced resource \'' + rawItem.id + '\' ignored. (reason: ' + rawItem.reason + ')');
logger.warn('Referenced resource \'%s\' ignored. (reason: %s)', rawItem.id, rawItem.reason);
}

@@ -790,3 +798,3 @@

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

@@ -815,3 +823,3 @@ }

rawItem.reason = _DeadItem2.default.Reason.NOT_SPINE;
_parserCore.Logger.warn('Referenced resource \'' + rawItem.id + '\' ignored. (reason: ' + rawItem.reason + ')');
logger.warn('Referenced resource \'%s\' ignored. (reason: %s)', rawItem.id, rawItem.reason);
}

@@ -837,3 +845,3 @@ } else if (rawItem.itemType === _ImageItem2.default) {

rawItem.reason = _DeadItem2.default.Reason.NOT_NCX;
_parserCore.Logger.warn('Referenced resource \'' + rawItem.id + '\' ignored. (reason: ' + rawItem.reason + ')');
logger.warn('Referenced resource \'%s\' ignored. (reason: %s)', rawItem.id, rawItem.reason);
}

@@ -843,3 +851,3 @@ }

if (!options.parseStyle) {
_context7.next = 21;
_context8.next = 21;
break;

@@ -849,3 +857,3 @@ }

if (!(rawItem.itemType === _CssItem2.default)) {
_context7.next = 15;
_context8.next = 15;
break;

@@ -855,3 +863,3 @@ }

rawItem.namespace = '' + options.styleNamespacePrefix + idx;
_context7.next = 21;
_context8.next = 21;
break;

@@ -861,11 +869,11 @@

if (!(rawItem.itemType === _SpineItem2.default)) {
_context7.next = 21;
_context8.next = 21;
break;
}
_context7.next = 18;
return _this._parseSpineStyle(rawItem, itemEntry, options);
_context8.next = 18;
return _this2._parseSpineStyle(rawItem, itemEntry, options);
case 18:
result = _context7.sent;
result = _context8.sent;

@@ -876,3 +884,3 @@ rawItem.styles = result.styles;

case 21:
_context7.next = 26;
_context8.next = 26;
break;

@@ -883,3 +891,3 @@

rawItem.reason = _DeadItem2.default.Reason.NOT_EXISTS;
_parserCore.Logger.warn('Referenced resource \'' + rawItem.id + '\' ignored. (reason: ' + rawItem.reason + ')');
logger.warn('Referenced resource \'%s\' ignored. (reason: %s)', rawItem.id, rawItem.reason);

@@ -891,6 +899,6 @@ case 26:

case 'end':
return _context7.stop();
return _context8.stop();
}
}
}, _callee6, _this);
}, _callee7, _this2);
})));

@@ -903,14 +911,14 @@ }, _promise2.default.resolve());

return _context8.abrupt('return', context);
return _context9.abrupt('return', context);
case 11:
case 'end':
return _context8.stop();
return _context9.stop();
}
}
}, _callee7, this);
}, _callee8, this);
}));
function _parseManifestAndSpine(_x6, _x7, _x8) {
return _ref6.apply(this, arguments);
return _ref7.apply(this, arguments);
}

@@ -936,7 +944,7 @@

EpubParser.prototype._parseSpineStyle = function () {
var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(rawItem, entry, options) {
var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(rawItem, entry, options) {
var styles, inlineStyles, find, filter, document, html, head;
return _regenerator2.default.wrap(function _callee8$(_context9) {
return _regenerator2.default.wrap(function _callee9$(_context10) {
while (1) {
switch (_context9.prev = _context9.next) {
switch (_context10.prev = _context10.next) {
case 0:

@@ -958,9 +966,9 @@ styles = [];

_context9.t0 = _himalaya.parse;
_context9.next = 7;
_context10.t0 = _himalaya.parse;
_context10.next = 7;
return entry.getFile('utf8');
case 7:
_context9.t1 = _context9.sent;
document = (0, _context9.t0)(_context9.t1);
_context10.t1 = _context10.sent;
document = (0, _context10.t0)(_context10.t1);
html = find(document, 'tagName', 'html');

@@ -1010,14 +1018,14 @@ head = find(html.children, 'tagName', 'head');

return _context9.abrupt('return', { styles: styles, inlineStyles: inlineStyles });
return _context10.abrupt('return', { styles: styles, inlineStyles: inlineStyles });
case 14:
case 'end':
return _context9.stop();
return _context10.stop();
}
}
}, _callee8, this);
}, _callee9, this);
}));
function _parseSpineStyle(_x9, _x10, _x11) {
return _ref8.apply(this, arguments);
return _ref9.apply(this, arguments);
}

@@ -1074,8 +1082,8 @@

EpubParser.prototype._parseNcx = function () {
var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(context) {
var _ref10 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(context) {
var rawBook, entries, options, allowNcxFileMissing, ncxItem, ncxEntry, _xmlLoader3, ncx, normalizeSrc, keyTranslator;
return _regenerator2.default.wrap(function _callee9$(_context10) {
return _regenerator2.default.wrap(function _callee10$(_context11) {
while (1) {
switch (_context10.prev = _context10.next) {
switch (_context11.prev = _context11.next) {
case 0:

@@ -1089,3 +1097,3 @@ rawBook = context.rawBook, entries = context.entries, options = context.options;

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

@@ -1097,3 +1105,3 @@ }

if (!(!allowNcxFileMissing && !(0, _parserCore.isExists)(ncxEntry))) {
_context10.next = 7;
_context11.next = 7;
break;

@@ -1105,13 +1113,13 @@ }

case 7:
_context10.t0 = _xmlLoader5.default;
_context10.next = 10;
_context11.t0 = _xmlLoader5.default;
_context11.next = 10;
return ncxEntry.getFile('utf8');
case 10:
_context10.t1 = _context10.sent;
_xmlLoader3 = (0, _context10.t0)(_context10.t1);
_context11.t1 = _context11.sent;
_xmlLoader3 = (0, _context11.t0)(_context11.t1);
ncx = _xmlLoader3.ncx;
if ((0, _parserCore.isExists)(ncx)) {
_context10.next = 15;
_context11.next = 15;
break;

@@ -1124,3 +1132,3 @@ }

if ((0, _parserCore.isExists)(ncx.navMap)) {
_context10.next = 17;
_context11.next = 17;
break;

@@ -1156,3 +1164,3 @@ }

});
_context10.next = 25;
_context11.next = 25;
break;

@@ -1162,3 +1170,3 @@

if (allowNcxFileMissing) {
_context10.next = 25;
_context11.next = 25;
break;

@@ -1170,14 +1178,14 @@ }

case 25:
return _context10.abrupt('return', context);
return _context11.abrupt('return', context);
case 26:
case 'end':
return _context10.stop();
return _context11.stop();
}
}
}, _callee9, this);
}, _callee10, this);
}));
function _parseNcx(_x12) {
return _ref9.apply(this, arguments);
return _ref10.apply(this, arguments);
}

@@ -1199,7 +1207,7 @@

EpubParser.prototype._unzipIfNeeded = function () {
var _ref10 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(context) {
var _ref11 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11(context) {
var options, entries, unzipPath, overwrite;
return _regenerator2.default.wrap(function _callee10$(_context11) {
return _regenerator2.default.wrap(function _callee11$(_context12) {
while (1) {
switch (_context11.prev = _context11.next) {
switch (_context12.prev = _context12.next) {
case 0:

@@ -1210,7 +1218,7 @@ options = context.options, entries = context.entries;

if (!(!(0, _parserCore.isString)(entries.source) && (0, _parserCore.isExists)(unzipPath))) {
_context11.next = 6;
_context12.next = 6;
break;
}
_context11.next = 5;
_context12.next = 5;
return entries.source.extractAll(unzipPath, overwrite);

@@ -1222,14 +1230,14 @@

case 6:
return _context11.abrupt('return', context);
return _context12.abrupt('return', context);
case 7:
case 'end':
return _context11.stop();
return _context12.stop();
}
}
}, _callee10, this);
}, _callee11, this);
}));
function _unzipIfNeeded(_x13) {
return _ref10.apply(this, arguments);
return _ref11.apply(this, arguments);
}

@@ -1269,26 +1277,26 @@

EpubParser.prototype.readItem = function () {
var _ref11 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11(item) {
var _ref12 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12(item) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var results;
return _regenerator2.default.wrap(function _callee11$(_context12) {
return _regenerator2.default.wrap(function _callee12$(_context13) {
while (1) {
switch (_context12.prev = _context12.next) {
switch (_context13.prev = _context13.next) {
case 0:
_context12.next = 2;
_context13.next = 2;
return this.readItems([item], options);
case 2:
results = _context12.sent;
return _context12.abrupt('return', results[0]);
results = _context13.sent;
return _context13.abrupt('return', results[0]);
case 4:
case 'end':
return _context12.stop();
return _context13.stop();
}
}
}, _callee11, this);
}, _callee12, this);
}));
function readItem(_x15) {
return _ref11.apply(this, arguments);
return _ref12.apply(this, arguments);
}

@@ -1315,31 +1323,51 @@

EpubParser.prototype.readItems = function () {
var _ref12 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12(items) {
var _ref13 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee14(items) {
var _this3 = this;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var context, results;
return _regenerator2.default.wrap(function _callee12$(_context13) {
var tasks, context;
return _regenerator2.default.wrap(function _callee14$(_context15) {
while (1) {
switch (_context13.prev = _context13.next) {
switch (_context15.prev = _context15.next) {
case 0:
_context13.next = 2;
return this._prepareRead(items, options);
tasks = [{ func: this._prepareRead, name: 'prepareRead' }, { func: this._read, name: 'read' }];
context = [items, options];
_context15.next = 4;
return tasks.reduce(function (prevPromise, task) {
// eslint-disable-line arrow-body-style
return prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee13() {
var func, name;
return _regenerator2.default.wrap(function _callee13$(_context14) {
while (1) {
switch (_context14.prev = _context14.next) {
case 0:
func = task.func, name = task.name;
_context14.next = 3;
return logger.measure(func, _this3, (0, _parserCore.isArray)(context) ? context : [context], name);
case 2:
context = _context13.sent;
_context13.next = 5;
return this._read(context);
case 3:
context = _context14.sent;
case 4:
case 'end':
return _context14.stop();
}
}
}, _callee13, _this3);
})));
}, _promise2.default.resolve());
case 4:
return _context15.abrupt('return', context);
case 5:
results = _context13.sent;
return _context13.abrupt('return', results);
case 7:
case 'end':
return _context13.stop();
return _context15.stop();
}
}
}, _callee12, this);
}, _callee14, this);
}));
function readItems(_x17) {
return _ref12.apply(this, arguments);
return _ref13.apply(this, arguments);
}

@@ -1371,8 +1399,8 @@

EpubParser.prototype._prepareRead = function () {
var _ref13 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee13(items) {
var _ref15 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee15(items) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var entries;
return _regenerator2.default.wrap(function _callee13$(_context14) {
return _regenerator2.default.wrap(function _callee15$(_context16) {
while (1) {
switch (_context14.prev = _context14.next) {
switch (_context16.prev = _context16.next) {
case 0:

@@ -1382,3 +1410,3 @@ if (!items.find(function (item) {

})) {
_context14.next = 2;
_context16.next = 2;
break;

@@ -1391,8 +1419,8 @@ }

(0, _parserCore.validateOptions)(options, EpubParser.readOptionTypes);
_context14.next = 5;
return (0, _parserCore.readEntries)(this.input, this.cryptoProvider);
_context16.next = 5;
return (0, _parserCore.readEntries)(this.input, this.cryptoProvider, logger);
case 5:
entries = _context14.sent;
return _context14.abrupt('return', {
entries = _context16.sent;
return _context16.abrupt('return', {
items: items,

@@ -1405,10 +1433,10 @@ entries: entries,

case 'end':
return _context14.stop();
return _context16.stop();
}
}
}, _callee13, this);
}, _callee15, this);
}));
function _prepareRead(_x19) {
return _ref13.apply(this, arguments);
return _ref15.apply(this, arguments);
}

@@ -1428,23 +1456,23 @@

EpubParser.prototype._read = function () {
var _ref14 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee15(context) {
var _this2 = this;
var _ref16 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee17(context) {
var _this4 = this;
var items, entries, options, results;
return _regenerator2.default.wrap(function _callee15$(_context16) {
return _regenerator2.default.wrap(function _callee17$(_context18) {
while (1) {
switch (_context16.prev = _context16.next) {
switch (_context18.prev = _context18.next) {
case 0:
items = context.items, entries = context.entries, options = context.options;
results = [];
_context16.next = 4;
_context18.next = 4;
return items.reduce(function (prevPromise, item) {
// eslint-disable-line arrow-body-style
return prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee14() {
return prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee16() {
var entry, file;
return _regenerator2.default.wrap(function _callee14$(_context15) {
return _regenerator2.default.wrap(function _callee16$(_context17) {
while (1) {
switch (_context15.prev = _context15.next) {
switch (_context17.prev = _context17.next) {
case 0:
if (!(item instanceof _InlineCssItem2.default)) {
_context15.next = 3;
_context17.next = 3;
break;

@@ -1454,3 +1482,3 @@ }

results.push((0, _cssLoader2.default)(item, item.text, options));
return _context15.abrupt('return');
return _context17.abrupt('return');

@@ -1461,3 +1489,3 @@ case 3:

if ((0, _parserCore.isExists)(entry)) {
_context15.next = 6;
_context17.next = 6;
break;

@@ -1469,7 +1497,7 @@ }

case 6:
_context15.next = 8;
_context17.next = 8;
return entry.getFile(item.defaultEncoding);
case 8:
file = _context15.sent;
file = _context17.sent;

@@ -1486,6 +1514,6 @@ if (item instanceof _SpineItem2.default) {

case 'end':
return _context15.stop();
return _context17.stop();
}
}
}, _callee14, _this2);
}, _callee16, _this4);
})));

@@ -1495,14 +1523,14 @@ }, _promise2.default.resolve());

case 4:
return _context16.abrupt('return', results);
return _context18.abrupt('return', results);
case 5:
case 'end':
return _context16.stop();
return _context18.stop();
}
}
}, _callee15, this);
}, _callee17, this);
}));
function _read(_x20) {
return _ref14.apply(this, arguments);
return _ref16.apply(this, arguments);
}

@@ -1509,0 +1537,0 @@

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

Errors: _parserCore.Errors,
Logger: _parserCore.Logger,
LogLevel: _parserCore.LogLevel,
CryptoProvider: _parserCore.CryptoProvider,

@@ -21,0 +21,0 @@ Cryptor: _parserCore.Cryptor

{
"name": "@ridi/epub-parser",
"version": "0.3.0-alpha.5",
"version": "0.3.0-alpha-6",
"description": "Common EPUB2 data parser for Ridibooks services",

@@ -31,3 +31,3 @@ "author": {

"dependencies": {
"@ridi/parser-core": "^0.3.0-alpha.5",
"@ridi/parser-core": "^0.3.0-alpha-6",
"css-tree": "^1.0.0-alpha.29",

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

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