-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the ability to pass the config in grab()
- Loading branch information
Showing
5 changed files
with
107 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
const tough = require('tough-cookie') | ||
const { merge } = require('lodash') | ||
|
||
module.exports.load = load | ||
module.exports.parse = parse | ||
|
||
function load(config) { | ||
if (!config.site) throw new Error("The required 'site' property is missing") | ||
if (!config.url) throw new Error("The required 'url' property is missing") | ||
if (typeof config.url !== 'function' && typeof config.url !== 'string') | ||
throw new Error("The 'url' property should return the function or string") | ||
if (!config.parser) throw new Error("The required 'parser' function is missing") | ||
if (typeof config.parser !== 'function') | ||
throw new Error("The 'parser' property should return the function") | ||
if (config.logo && typeof config.logo !== 'function') | ||
throw new Error("The 'logo' property should return the function") | ||
function parse(config) { | ||
if (!config.site) throw new Error("The required 'site' property is missing") | ||
if (!config.url) throw new Error("The required 'url' property is missing") | ||
if (typeof config.url !== 'function' && typeof config.url !== 'string') | ||
throw new Error("The 'url' property should return the function or string") | ||
if (!config.parser) throw new Error("The required 'parser' function is missing") | ||
if (typeof config.parser !== 'function') | ||
throw new Error("The 'parser' property should return the function") | ||
if (config.logo && typeof config.logo !== 'function') | ||
throw new Error("The 'logo' property should return the function") | ||
|
||
const defaultConfig = { | ||
days: 1, | ||
lang: 'en', | ||
delay: 3000, | ||
output: 'guide.xml', | ||
request: { | ||
method: 'GET', | ||
maxContentLength: 5 * 1024 * 1024, | ||
timeout: 5000, | ||
withCredentials: true, | ||
jar: new tough.CookieJar(), | ||
responseType: 'arraybuffer', | ||
cache: false | ||
} | ||
} | ||
const defaultConfig = { | ||
days: 1, | ||
lang: 'en', | ||
delay: 3000, | ||
output: 'guide.xml', | ||
request: { | ||
method: 'GET', | ||
maxContentLength: 5 * 1024 * 1024, | ||
timeout: 5000, | ||
withCredentials: true, | ||
jar: new tough.CookieJar(), | ||
responseType: 'arraybuffer', | ||
cache: false | ||
} | ||
} | ||
|
||
return merge(defaultConfig, config) | ||
return merge(defaultConfig, config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters