metascraper-manifest 5.25.0

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 (4) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +38 -0
  3. package/index.js +43 -0
  4. package/package.json +55 -0
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2019 Microlink <hello@microlink.io> (microlink.io)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # metascraper-manifest
2
+
3
+ [![npm](https://img.shields.io/npm/v/metascraper-manifest.svg?style=flat-square)](https://www.npmjs.com/package/metascraper-manifest)
4
+ [![Dependency Status](https://david-dm.org/microlinkhq/metascraper.svg?path=packages/metascraper-manifest&style=flat-square)](https://david-dm.org/microlinkhq/metascraper?path=packages/metascraper-manifest)
5
+
6
+ > Metascraper integration for derecting PWA Web app [manifests](https://developer.mozilla.org/en-US/docs/Web/Manifest).
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ $ npm install metascraper-manifest --save
12
+ ```
13
+
14
+ ## API
15
+
16
+ ### metascraper-manifest([options])
17
+
18
+ #### options
19
+
20
+ #### gotOpts
21
+
22
+ Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).
23
+
24
+ In addition, these options are set by default:
25
+
26
+ ```json
27
+ {
28
+ "responseType": "json",
29
+ "timeout": 3000
30
+ }
31
+ ```
32
+
33
+ ## License
34
+
35
+ **metascraper-manifest** © [Microlink](https://microlink.io), Released under the [MIT](https://github.com/microlinkhq/metascraper/blob/master/LICENSE.md) License.<br>
36
+ Authored and maintained by [Microlink](https://microlink.io) with help from [contributors](https://github.com/microlinkhq/metascraper/contributors).
37
+
38
+ > [microlink.io](https://microlink.io) · GitHub [@microlink.io](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq)
package/index.js ADDED
@@ -0,0 +1,43 @@
1
+ 'use strict'
2
+
3
+ const { logo, composeRule, absoluteUrl } = require('@metascraper/helpers')
4
+ const asyncMemoizeOne = require('async-memoize-one')
5
+ const { first, orderBy } = require('lodash')
6
+ const got = require('got')
7
+
8
+ const DEFAULT_GOT_OPTS = {
9
+ responseType: 'json',
10
+ timeout: 3000
11
+ }
12
+
13
+ const createFetchManifest = ({ gotOpts } = {}) =>
14
+ asyncMemoizeOne(async (url, $) => {
15
+ const manifest = $('link[rel="manifest"]').attr('href')
16
+ if (!manifest) return undefined
17
+ const manifestUrl = absoluteUrl(url, manifest)
18
+ try {
19
+ const { body: manifest } = await got(manifestUrl, {
20
+ ...DEFAULT_GOT_OPTS,
21
+ ...gotOpts
22
+ })
23
+ return manifest
24
+ } catch (_) {}
25
+ })
26
+
27
+ module.exports = opts => {
28
+ const fetchManifest = createFetchManifest(opts)
29
+ const manifest = composeRule(($, url) => fetchManifest(url, $))
30
+
31
+ return {
32
+ lang: manifest({ from: 'lang' }),
33
+ description: manifest({ from: 'description' }),
34
+ publisher: manifest({ from: 'short_name', to: 'publisher' }),
35
+ logo: async ({ htmlDom, url }) => {
36
+ const manifest = await fetchManifest(url, htmlDom)
37
+ if (!manifest) return
38
+ const { src: srcUrl } = first(orderBy(manifest.icons, 'sizes', 'desc'))
39
+ const iconUrl = absoluteUrl(url, srcUrl)
40
+ return logo(iconUrl)
41
+ }
42
+ }
43
+ }
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "metascraper-manifest",
3
+ "description": "Metascraper integration for derecting PWA Web app manifest",
4
+ "homepage": "https://nicedoc.io/microlinkhq/metascraper/packages/metascraper-manifest",
5
+ "version": "5.25.0",
6
+ "main": "index.js",
7
+ "author": {
8
+ "email": "hello@microlink.io",
9
+ "name": "microlink.io",
10
+ "url": "https://microlink.io"
11
+ },
12
+ "repository": {
13
+ "directory": "packages/metascraper-manifest",
14
+ "type": "git",
15
+ "url": "git+https://github.com/microlinkhq/metascraper.git"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/microlinkhq/metascraper/issues"
19
+ },
20
+ "keywords": [
21
+ "manifest",
22
+ "metascraper",
23
+ "pwa"
24
+ ],
25
+ "dependencies": {
26
+ "@metascraper/helpers": "^5.25.0",
27
+ "async-memoize-one": "~1.1.0",
28
+ "got": "~11.8.2",
29
+ "lodash": "~4.17.21"
30
+ },
31
+ "devDependencies": {
32
+ "mocha": "latest",
33
+ "nyc": "latest",
34
+ "snap-shot": "latest"
35
+ },
36
+ "engines": {
37
+ "node": ">= 12"
38
+ },
39
+ "files": [
40
+ "index.js"
41
+ ],
42
+ "scripts": {
43
+ "test": "NODE_PATH=.. TZ=UTC NODE_ENV=test nyc mocha test"
44
+ },
45
+ "license": "MIT",
46
+ "mocha": {
47
+ "bail": true,
48
+ "exit": true,
49
+ "recursive": true,
50
+ "reporter": "spec",
51
+ "slow": 300,
52
+ "timeout": "120000"
53
+ },
54
+ "gitHead": "bd741119b783e48d3e90ad81a14c25e86886fc07"
55
+ }