julien-c / epub

node.js epub reader
https://www.npmjs.com/package/epub
Other
333 stars 307 forks source link

TOC title properties are inaccurately defined as empty strings #38

Open phoenix-violeus opened 6 years ago

phoenix-violeus commented 6 years ago

The following ternary (lines 529-530 of epub.js) defines title as an empty string even when the given TOC title is truthy:

title = branch[i].navLabel && branch[i].navLabel.text || branch[i].navLabel===branch[i].navLabel ? '' : (branch[i].navLabel && branch[i].navLabel.text || branch[i].navLabel || "").trim();

Unless I'm mistaken, the solution is a simple matter of switching the expressions like so:

title = branch[i].navLabel && branch[i].navLabel.text || branch[i].navLabel===branch[i].navLabel ? (branch[i].navLabel && branch[i].navLabel.text || branch[i].navLabel || '').trim() : '';