feedr
Version:
Use feedr to fetch the data from a remote url, respect its caching, and parse its data. Despite its name, it's not just for feed data but also for all data that you can feed into it (including binary data).
25 lines (21 loc) • 440 B
JavaScript
module.exports.parse = function parseYAML({ feed, response, data }, next) {
// Detect
const isYAML =
feed.parse === 'yaml' ||
['.yml', '.yaml'].indexOf(feed.extension) !== -1 ||
response.headers['content-type'].indexOf('yaml') !== -1
if (!isYAML) {
next()
return
}
// Parse
try {
data = require('js-yaml').load(data.toString().trim())
} catch (err) {
next(err)
return
}
// Write
next(null, data)
}