metascraper-logo 5.36.0 → 5.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +20 -0
  2. package/index.js +26 -17
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -14,6 +14,26 @@
14
14
  $ npm install metascraper-logo --save
15
15
  ```
16
16
 
17
+ ## API
18
+
19
+ ### metascraper-logo([options])
20
+
21
+ #### options
22
+
23
+ ##### filter
24
+
25
+ Type: `function`
26
+
27
+ A function to filter results in case it passes a test implemented by the provided function. It is the `url` as the first parameter:
28
+
29
+ ```js
30
+ const metascraper = require('metascraper')([
31
+ require('metascraper-logo')({
32
+ filter: url => url.endsWith('.png')
33
+ })
34
+ ])
35
+ ```
36
+
17
37
  ## License
18
38
 
19
39
  **metascraper-logo** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/metascraper/blob/master/LICENSE.md) License.<br>
package/index.js CHANGED
@@ -3,8 +3,6 @@
3
3
  const { $jsonld, url: urlFn, toRule } = require('@metascraper/helpers')
4
4
  const { eq, get } = require('lodash')
5
5
 
6
- const toUrl = toRule(urlFn)
7
-
8
6
  const toLogoUrl = ($, propName) => {
9
7
  const logo = $jsonld(propName)($)
10
8
  const width = get(logo, 'width')
@@ -12,18 +10,29 @@ const toLogoUrl = ($, propName) => {
12
10
  return width && height && eq(width, height) && get(logo, 'url')
13
11
  }
14
12
 
15
- module.exports = () => ({
16
- logo: [
17
- toUrl($ => $('meta[property="og:logo"]').attr('content')),
18
- toUrl($ => $('meta[itemprop="logo"]').attr('content')),
19
- toUrl($ => $('img[itemprop="logo"]').attr('src')),
20
- toUrl($ => toLogoUrl($, 'brand.logo')),
21
- toUrl($ => toLogoUrl($, 'organization.logo')),
22
- toUrl($ => toLogoUrl($, 'place.logo')),
23
- toUrl($ => toLogoUrl($, 'product.logo')),
24
- toUrl($ => toLogoUrl($, 'service.logo')),
25
- toUrl($ => toLogoUrl($, 'publisher.logo')),
26
- toUrl($ => toLogoUrl($, 'logo.url')),
27
- toUrl($ => toLogoUrl($, 'logo'))
28
- ]
29
- })
13
+ module.exports = ({ filter } = {}) => {
14
+ const mapper = filter
15
+ ? async value => {
16
+ const result = urlFn(value)
17
+ return typeof result === 'string' ? await filter(result) : result
18
+ }
19
+ : urlFn
20
+
21
+ const toUrl = toRule(mapper)
22
+
23
+ return {
24
+ logo: [
25
+ toUrl($ => $('meta[property="og:logo"]').attr('content')),
26
+ toUrl($ => $('meta[itemprop="logo"]').attr('content')),
27
+ toUrl($ => $('img[itemprop="logo"]').attr('src')),
28
+ toUrl($ => toLogoUrl($, 'brand.logo')),
29
+ toUrl($ => toLogoUrl($, 'organization.logo')),
30
+ toUrl($ => toLogoUrl($, 'place.logo')),
31
+ toUrl($ => toLogoUrl($, 'product.logo')),
32
+ toUrl($ => toLogoUrl($, 'service.logo')),
33
+ toUrl($ => toLogoUrl($, 'publisher.logo')),
34
+ toUrl($ => toLogoUrl($, 'logo.url')),
35
+ toUrl($ => toLogoUrl($, 'logo'))
36
+ ]
37
+ }
38
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "metascraper-logo",
3
3
  "description": "Get logo property from HTML markup",
4
4
  "homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-logo",
5
- "version": "5.36.0",
5
+ "version": "5.37.1",
6
6
  "main": "index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -22,7 +22,7 @@
22
22
  "metascraper"
23
23
  ],
24
24
  "dependencies": {
25
- "@metascraper/helpers": "^5.36.0",
25
+ "@metascraper/helpers": "^5.37.1",
26
26
  "lodash": "~4.17.21"
27
27
  },
28
28
  "engines": {
@@ -35,5 +35,5 @@
35
35
  "test": "exit 0"
36
36
  },
37
37
  "license": "MIT",
38
- "gitHead": "c10dbbb9e98c16b72d34dcea301c7fecd71d760f"
38
+ "gitHead": "5b969c5c306acda8f10503cc6da472493dd044f7"
39
39
  }