license import { EpubContent , EpubMetadataMeta } from './types' ; export default function getEpubCoverImageFilename ( contents ) { for ( const item of contents . package . manifest . item ) { if ( item [ '@_properties' ] === 'cover-image' ) { return item [ '@_href' ] ; } } const { meta } = contents . package . metadata ; if ( meta ) { let coverItemId ; if ( Array . isArray ( meta ) ) { for ( const m of meta ) { coverItemId = getCoverItemIdFromMeta ( m ) ; if ( coverItemId ) { break ; } } } else { coverItemId = getCoverItemIdFromMeta ( meta ) ; } if ( coverItemId ) { for ( const item of contents . package . manifest . item ) { if ( item [ '@_id' ] === coverItemId ) { return item [ '@_href' ] ; } } } } return undefined ; } function getCoverItemIdFromMeta ( meta ) { if ( meta [ '@_name' ] === 'cover' ) { return meta [ '@_content' ] ; } return undefined ; }