function* parseMetadata(metadata) { for (const [key, entry] of Object.entries(metadata)) { entry.textUris = entry.formaturi .filter(uri => extensionIn(uri, ['.txt', '.utf-8'])) .map(stripPGHost) entry.pictures = entry.formaturi .filter(uri => extensionIn(uri, ['.jpg', 'png'])) .map(stripPGHost) delete entry.formaturi entry.id = key yield entry } } function extensionIn(path, endings) { return endings.some(ending => path.endsWith(ending)) } function stripPGHost(uri) { return uri.replace('http://www.gutenberg.org', '') } module.exports = { parseMetadata }