metascraper
Version:
A library to easily scrape metadata from an article on the web using Open Graph metadata, regular HTML metadata, and series of fallbacks.
21 lines (17 loc) • 433 B
JavaScript
const { has, set, concat, forEach, chain } = require('lodash')
module.exports = rules =>
chain(rules)
.reduce((acc, rules) => {
forEach(rules, function (innerRules, propName) {
set(
acc,
propName,
has(acc, propName) ? concat(acc[propName], innerRules) : concat(innerRules)
)
return acc
})
return acc
}, {})
.toPairs()
.value()