Skip to content

Commit

Permalink
Ensure to auto load rules just once
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed May 13, 2018
1 parent 0bcc5ce commit cb18d36
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/metascraper/src/index.js
Expand Up @@ -8,13 +8,12 @@ const loadHTML = require('./load-html')
const getData = require('./get-data')

const create = loader => {
return async ({url, html} = {}) => {
const rules = await loader()
const lazyRules = loader()
return async ({url, html, rules: extraRules} = {}) => {
const rules = await lazyRules

if (!isUrl(url)) throw new TypeError('You need to provide a valid url.')
if (isEmpty(html)) {
throw new TypeError('You need to provide a valid HTML markup.')
}
if (isEmpty(html)) throw new TypeError('You need to provide a valid HTML markup.')

const htmlDom = loadHTML(html)
return getData({ rules, htmlDom, url })
Expand Down

0 comments on commit cb18d36

Please sign in to comment.