Skip to content

Commit 3a412be

Browse files
committed
Refactor
1 parent eb75363 commit 3a412be

File tree

4 files changed

+5
-15
lines changed

4 files changed

+5
-15
lines changed

packages/metascraper-amazon/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@ const { titleize, isUrl } = require('@metascraper/helpers')
55
const REGEX_AMAZON_URL = /https?:\/\/(.*amazon\..*\/.*|.*amzn\..*\/.*|.*a\.co\/.*)/i
66
const isAmazonUrl = url => REGEX_AMAZON_URL.test(url)
77

8-
const wrap = rule => ({ htmlDom, url }) => {
9-
if (!isAmazonUrl(url)) return
10-
const value = rule(htmlDom)
11-
return value
12-
}
8+
const wrap = rule => ({ htmlDom, url }) => isAmazonUrl(url) && rule(htmlDom)
139

1410
const wrapUrl = rule => ({ htmlDom, url }) => {
1511
const value = wrap(rule)({htmlDom, url})
16-
if (!isUrl(value)) return
17-
return value
12+
return isUrl(value) && value
1813
}
1914

2015
module.exports = () => ({

packages/metascraper-author/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ const wrap = rule => ({ htmlDom }) => {
2929

3030
const strict = rule => $ => {
3131
const value = rule($)
32-
if (!REGEX_STRICT.test(value)) return
33-
return value
32+
return REGEX_STRICT.test(value) && value
3433
}
3534

3635
const getFirst = ($, collection) =>

packages/metascraper-description/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ const removeLocation = value => value.replace(REGEX_LOCATION, '')
1616

1717
const wrap = rule => ({ htmlDom }) => {
1818
const value = rule(htmlDom)
19-
20-
if (!isString(value)) return
21-
return titleize(removeLocation(value), { capitalize: false })
19+
return isString(value) && titleize(removeLocation(value), { capitalize: false })
2220
}
2321

2422
/**

packages/metascraper-publisher/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ const REGEX_TITLE = /^.*?\|\s+(.*)$/
1515

1616
const wrap = rule => ({ htmlDom }) => {
1717
const value = rule(htmlDom)
18-
19-
if (!isString(value)) return
20-
return condenseWhitespace(value)
18+
return isString(value) && condenseWhitespace(value)
2119
}
2220

2321
/**

0 commit comments

Comments
 (0)