UNPKG

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.

15 lines (12 loc) 453 B
'use strict' const { cloneDeep, concat, first, findIndex, forEach, chain } = require('lodash') module.exports = (rules, baseRules) => chain(rules) .reduce((acc, rules) => { forEach(rules, (rule, propName) => { const index = findIndex(acc, item => first(item) === propName) if (index !== -1) acc[index][1] = concat(acc[index][1], rule) else acc.push([propName, rule]) }) return acc }, cloneDeep(baseRules)) .value()