Skip to content

Commit

Permalink
Add prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Dec 10, 2017
1 parent 3e9eff2 commit d93dd39
Show file tree
Hide file tree
Showing 78 changed files with 366 additions and 300 deletions.
22 changes: 13 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
'use strict'

const {isEmpty, reduce} = require('lodash')
const { isEmpty, reduce } = require('lodash')
const getData = require('./src/get-data')
const loadHtml = require('./src/html')
const {props, getConnector} = getData
const { props, getConnector } = getData

module.exports = async ({url, html}) => {
module.exports = async ({ url, html }) => {
const htmlDom = loadHtml(html)

const value = reduce(props, (acc, conditions, propName) => {
const data = getData({htmlDom, url, conditions})
acc[propName] = !isEmpty(data) ? data : null
return acc
}, {})
const value = reduce(
props,
(acc, conditions, propName) => {
const data = getData({ htmlDom, url, conditions })
acc[propName] = !isEmpty(data) ? data : null
return acc
},
{}
)

const connector = await getConnector({htmlDom, url})
const connector = await getConnector({ htmlDom, url })
return Object.assign({}, value, connector)
}
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@
"devDependencies": {
"coveralls": "latest",
"git-dirty": "latest",
"husky": "latest",
"json-future": "latest",
"lint-staged": "latest",
"mocha": "latest",
"nyc": "latest",
"prettier-standard": "latest",
"should": "latest",
"snap-shot": "latest",
"standard": "latest",
"standard-markdown": "latest"
},
"engines": {
"node": ">= 8"
"node": "8"
},
"files": [
"index.js",
Expand All @@ -54,10 +57,18 @@
"clean": "rm -rf node_modules",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"lint": "standard-markdown && standard",
"precommit": "lint-staged",
"pretest": "npm run lint",
"pretty": "prettier-standard index.js {test,src}/**/*.js --single-quote",
"test": "TZ=UTC NODE_ENV=test nyc mocha test"
},
"license": "MIT",
"lint-staged": {
"*.js": [
"prettier-standard",
"git add"
]
},
"standard": {
"globals": [
"describe",
Expand Down
4 changes: 2 additions & 2 deletions src/get-data/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const rules = require('req-all')('./rules')
const {isEmpty} = require('lodash')
const { isEmpty } = require('lodash')

module.exports = ({htmlDom, url, conditions}) => {
module.exports = ({ htmlDom, url, conditions }) => {
const size = conditions.length
let index = -1
let value
Expand Down
7 changes: 4 additions & 3 deletions src/get-data/util.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict'

const isRelativeUrl = require('is-relative-url')
const {resolve: resolveUrl} = require('url')
const { resolve: resolveUrl } = require('url')
const sanetizeUrl = require('normalize-url')
const urlRegex = require('url-regex')

const isUrl = value => urlRegex().test(value)
const normalizeUrl = url => sanetizeUrl(url, {stripWWW: false})
const getAbsoluteUrl = (url, baseUrl) => isRelativeUrl(url) ? resolveUrl(baseUrl, url) : url
const normalizeUrl = url => sanetizeUrl(url, { stripWWW: false })
const getAbsoluteUrl = (url, baseUrl) =>
isRelativeUrl(url) ? resolveUrl(baseUrl, url) : url
const getUrl = (url, baseUrl) => normalizeUrl(getAbsoluteUrl(url, baseUrl))

module.exports = {
Expand Down
32 changes: 16 additions & 16 deletions src/html/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
'use strict'

const sanitizeHtml = require('sanitize-html')
const {flow, isNil} = require('lodash')
const { flow, isNil } = require('lodash')
const cheerio = require('cheerio')

const normalizeAttributes = propName => (tagName, attribs) => {
if (!isNil(attribs[propName])) attribs[propName] = attribs[propName].toLowerCase()
return {tagName, attribs}
if (!isNil(attribs[propName])) {
attribs[propName] = attribs[propName].toLowerCase()
}
return { tagName, attribs }
}

const sanitize = html => sanitizeHtml(html, {
allowedTags: false,
allowedAttributes: false,
transformTags: {
meta: normalizeAttributes('name'),
a: normalizeAttributes('href'),
link: normalizeAttributes('rel')
}
})
const sanitize = html =>
sanitizeHtml(html, {
allowedTags: false,
allowedAttributes: false,
transformTags: {
meta: normalizeAttributes('name'),
a: normalizeAttributes('href'),
link: normalizeAttributes('rel')
}
})

const load = cheerio.load.bind(cheerio)

module.exports = flow([
sanitize,
load
])
module.exports = flow([sanitize, load])
9 changes: 5 additions & 4 deletions test/web/anandtech/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use strict'

const snapshot = require('snap-shot')
const {promisify} = require('util')
const {resolve} = require('path')
const { promisify } = require('util')
const { resolve } = require('path')

const fs = require('fs')

const getMetaData = require('../../..')
const readFile = promisify(fs.readFile)

const url = 'http://www.anandtech.com/show/11591/amd-launches-ryzen-pro-cpus-enhanced-security-longer-warranty-better-quality'
const url =
'http://www.anandtech.com/show/11591/amd-launches-ryzen-pro-cpus-enhanced-security-longer-warranty-better-quality'

it('anandtech', async () => {
const html = await readFile(resolve(__dirname, 'input.html'))
const metadata = await getMetaData({html, url})
const metadata = await getMetaData({ html, url })
snapshot(metadata)
})
9 changes: 5 additions & 4 deletions test/web/arstechnica/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use strict'

const snapshot = require('snap-shot')
const {promisify} = require('util')
const {resolve} = require('path')
const { promisify } = require('util')
const { resolve } = require('path')

const fs = require('fs')

const getMetaData = require('../../..')
const readFile = promisify(fs.readFile)

const url = 'https://arstechnica.com/features/2017/06/youtube-changed-my-life-a-pair-of-original-videostars-ponder-a-life-lived-online'
const url =
'https://arstechnica.com/features/2017/06/youtube-changed-my-life-a-pair-of-original-videostars-ponder-a-life-lived-online'

it('arstechnica', async () => {
const html = await readFile(resolve(__dirname, 'input.html'))
const metadata = await getMetaData({html, url})
const metadata = await getMetaData({ html, url })
snapshot(metadata)
})
6 changes: 3 additions & 3 deletions test/web/astier/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const snapshot = require('snap-shot')
const {promisify} = require('util')
const {resolve} = require('path')
const { promisify } = require('util')
const { resolve } = require('path')

const fs = require('fs')

Expand All @@ -13,6 +13,6 @@ const url = 'https://anisse.astier.eu/awk-driven-iot.html'

it('astier', async () => {
const html = await readFile(resolve(__dirname, 'input.html'))
const metadata = await getMetaData({html, url})
const metadata = await getMetaData({ html, url })
snapshot(metadata)
})
6 changes: 3 additions & 3 deletions test/web/atlasobscura/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const snapshot = require('snap-shot')
const {promisify} = require('util')
const {resolve} = require('path')
const { promisify } = require('util')
const { resolve } = require('path')

const fs = require('fs')

Expand All @@ -13,6 +13,6 @@ const url = 'http://www.atlasobscura.com/articles/ikea-bowl-blanda-blank-fire'

it('atlasobscura', async () => {
const html = await readFile(resolve(__dirname, 'input.html'))
const metadata = await getMetaData({html, url})
const metadata = await getMetaData({ html, url })
snapshot(metadata)
})
9 changes: 5 additions & 4 deletions test/web/audiense/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use strict'

const snapshot = require('snap-shot')
const {promisify} = require('util')
const {resolve} = require('path')
const { promisify } = require('util')
const { resolve } = require('path')

const fs = require('fs')

const getMetaData = require('../../..')
const readFile = promisify(fs.readFile)

const url = 'https://audiense.com/twin-peaks-2017-using-the-social-data-audience-consumer-insights-to-create-the-next-big-tv-sensation'
const url =
'https://audiense.com/twin-peaks-2017-using-the-social-data-audience-consumer-insights-to-create-the-next-big-tv-sensation'

it('audiense', async () => {
const html = await readFile(resolve(__dirname, 'input.html'))
const metadata = await getMetaData({html, url})
const metadata = await getMetaData({ html, url })
snapshot(metadata)
})
6 changes: 3 additions & 3 deletions test/web/bbc/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const snapshot = require('snap-shot')
const {promisify} = require('util')
const {resolve} = require('path')
const { promisify } = require('util')
const { resolve } = require('path')

const fs = require('fs')

Expand All @@ -13,6 +13,6 @@ const url = 'http://www.bbc.com/news/business-40504764'

it('bbc', async () => {
const html = await readFile(resolve(__dirname, 'input.html'))
const metadata = await getMetaData({html, url})
const metadata = await getMetaData({ html, url })
snapshot(metadata)
})
9 changes: 5 additions & 4 deletions test/web/bloomberg/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use strict'

const snapshot = require('snap-shot')
const {promisify} = require('util')
const {resolve} = require('path')
const { promisify } = require('util')
const { resolve } = require('path')

const fs = require('fs')

const getMetaData = require('../../..')
const readFile = promisify(fs.readFile)

const url = 'http://www.bloomberg.com/news/articles/2016-05-24/as-zenefits-stumbles-gusto-goes-head-on-by-selling-insurance'
const url =
'http://www.bloomberg.com/news/articles/2016-05-24/as-zenefits-stumbles-gusto-goes-head-on-by-selling-insurance'

it('bloomberg', async () => {
const html = await readFile(resolve(__dirname, 'input.html'))
const metadata = await getMetaData({html, url})
const metadata = await getMetaData({ html, url })
snapshot(metadata)
})
9 changes: 5 additions & 4 deletions test/web/business-today/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use strict'

const snapshot = require('snap-shot')
const {promisify} = require('util')
const {resolve} = require('path')
const { promisify } = require('util')
const { resolve } = require('path')

const fs = require('fs')

const getMetaData = require('../../..')
const readFile = promisify(fs.readFile)

const url = 'http://www.businesstoday.in/magazine/features/hackerrank-helping-cos-hire-coding-champions-via-online-tests/story/232567.html'
const url =
'http://www.businesstoday.in/magazine/features/hackerrank-helping-cos-hire-coding-champions-via-online-tests/story/232567.html'

it('business-today', async () => {
const html = await readFile(resolve(__dirname, 'input.html'))
const metadata = await getMetaData({html, url})
const metadata = await getMetaData({ html, url })
snapshot(metadata)
})
9 changes: 5 additions & 4 deletions test/web/cbr/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use strict'

const snapshot = require('snap-shot')
const {promisify} = require('util')
const {resolve} = require('path')
const { promisify } = require('util')
const { resolve } = require('path')

const fs = require('fs')

const getMetaData = require('../../..')
const readFile = promisify(fs.readFile)

const url = 'http://www.cbronline.com/news/cloud/aas/virtustream-ceo-taking-a-masochistic-approach-to-fighting-in-the-cloud-market-4884858'
const url =
'http://www.cbronline.com/news/cloud/aas/virtustream-ceo-taking-a-masochistic-approach-to-fighting-in-the-cloud-market-4884858'

it('cbr', async () => {
const html = await readFile(resolve(__dirname, 'input.html'))
const metadata = await getMetaData({html, url})
const metadata = await getMetaData({ html, url })
snapshot(metadata)
})
9 changes: 5 additions & 4 deletions test/web/cio/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use strict'

const snapshot = require('snap-shot')
const {promisify} = require('util')
const {resolve} = require('path')
const { promisify } = require('util')
const { resolve } = require('path')

const fs = require('fs')

const getMetaData = require('../../..')
const readFile = promisify(fs.readFile)

const url = 'http://www.cio.com/article/2929788/cloud-computing/20-ways-to-measure-the-success-of-your-growing-cloud-investment.html'
const url =
'http://www.cio.com/article/2929788/cloud-computing/20-ways-to-measure-the-success-of-your-growing-cloud-investment.html'

it('cio', async () => {
const html = await readFile(resolve(__dirname, 'input.html'))
const metadata = await getMetaData({html, url})
const metadata = await getMetaData({ html, url })
snapshot(metadata)
})
6 changes: 3 additions & 3 deletions test/web/cloud-pro/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const snapshot = require('snap-shot')
const {promisify} = require('util')
const {resolve} = require('path')
const { promisify } = require('util')
const { resolve } = require('path')

const fs = require('fs')

Expand All @@ -13,6 +13,6 @@ const url = 'http://www.cloudpro.co.uk/go/6024'

it('cloud-pro', async () => {
const html = await readFile(resolve(__dirname, 'input.html'))
const metadata = await getMetaData({html, url})
const metadata = await getMetaData({ html, url })
snapshot(metadata)
})
Loading

0 comments on commit d93dd39

Please sign in to comment.