From 93d6334394ce305fd9fb149812828c0e326abe98 Mon Sep 17 00:00:00 2001 From: Simon Constans Date: Fri, 16 Mar 2018 11:50:53 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20prettier=20format=20=F0=9F=8D=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- renovate.json | 4 +--- src/index.js | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/renovate.json b/renovate.json index ada4727..8d9e510 100644 --- a/renovate.json +++ b/renovate.json @@ -1,5 +1,3 @@ { - "extends": [ - "cozy-konnector" - ] + "extends": ["cozy-konnector"] } diff --git a/src/index.js b/src/index.js index 64b01cb..1287cb8 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,9 @@ -const { BaseKonnector, requestFactory, saveFiles, addData } = require('cozy-konnector-libs') +const { + BaseKonnector, + requestFactory, + saveFiles, + addData +} = require('cozy-konnector-libs') const request = requestFactory({ cheerio: true }) const baseUrl = 'http://books.toscrape.com' @@ -8,21 +13,23 @@ module.exports = new BaseKonnector(start) // The start function is run by the BaseKonnector instance only when it got all the account // information (fields). When you run this connector yourself in "standalone" mode or "dev" mode, // the account information come from ./konnector-dev-config.json file -function start (fields) { +function start(fields) { // The BaseKonnector instance expects a Promise as return of the function - return request(`${baseUrl}/index.html`) - .then($ => { + return request(`${baseUrl}/index.html`).then($ => { // cheerio (https://cheerio.js.org/) uses the same api as jQuery (http://jquery.com/) // here I do an Array.from to convert the cheerio fake array to a real js array. - const entries = Array.from($('article')).map(article => parseArticle($, article)) - return addData(entries, 'com.toscrape.books') - .then(() => saveFiles(entries, fields)) + const entries = Array.from($('article')).map(article => + parseArticle($, article) + ) + return addData(entries, 'com.toscrape.books').then(() => + saveFiles(entries, fields) + ) }) } // The goal of this function is to parse a html page wrapped by a cheerio instance // and return an array of js objects which will be saved to the cozy by addData (https://github.com/cozy/cozy-konnector-libs/blob/master/docs/api.md#module_addData) // and saveFiles (https://github.com/cozy/cozy-konnector-libs/blob/master/docs/api.md#savefiles) -function parseArticle ($, article) { +function parseArticle($, article) { const $article = $(article) const title = $article.find('h3 a').attr('title') return { @@ -37,6 +44,6 @@ function parseArticle ($, article) { } // convert a price string to a float -function normalizePrice (price) { +function normalizePrice(price) { return parseFloat(price.trim().replace('£', '')) }