UNPKG

453 BJavaScriptView Raw
1'use strict'
2
3/**
4 * Module dependencies
5 */
6const fetch = require('node-fetch')
7const cheerio = require('cheerio')
8
9module.exports = function (url, opts) {
10 if (typeof url !== 'string') {
11 throw new TypeError('Expected a string')
12 }
13
14 opts = opts || {}
15
16 return fetch(url)
17 .then(data => {
18 if (data.status !== 200) {
19 return Promise.reject(new Error(data.statusText))
20 }
21 return data.text()
22 })
23 .then(data => cheerio.load(data, opts))
24}