oembed-spec 1.3.32 → 1.4.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.
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  ## Features
15
15
 
16
- - Always on sync with [oEmbed providers](https://oembed.com/providers.json) (as npm postinstall hook).
16
+ - Always on sync with [oEmbed providers](https://oembed.com/providers.json) (updated weekly via GitHub Actions).
17
17
  - Handle http/https & www/non-www URLs variations.
18
18
  - Ability to pass extra oEmbed parameters.
19
19
  - Built for speed (see [benchmarks](benchmarks/README.md)).
package/package.json CHANGED
@@ -2,7 +2,8 @@
2
2
  "name": "oembed-spec",
3
3
  "description": "A parser for oEmbed specification",
4
4
  "homepage": "https://github.com/microlinkhq/oembed-spec",
5
- "version": "1.3.32",
5
+ "version": "1.4.0",
6
+ "types": "src/index.d.ts",
6
7
  "main": "src/index.js",
7
8
  "author": {
8
9
  "email": "hello@microlink.io",
@@ -21,6 +22,10 @@
21
22
  {
22
23
  "name": "Rémi Berson",
23
24
  "email": "remi@cliqz.com"
25
+ },
26
+ {
27
+ "name": "Michael Lip",
28
+ "email": "51033404+theluckystrike@users.noreply.github.com"
24
29
  }
25
30
  ],
26
31
  "repository": {
@@ -57,7 +62,6 @@
57
62
  "oembed-parser": "latest",
58
63
  "simple-git-hooks": "latest",
59
64
  "standard": "latest",
60
- "standard-markdown": "latest",
61
65
  "standard-version": "latest"
62
66
  },
63
67
  "engines": {
@@ -67,6 +71,18 @@
67
71
  "scripts",
68
72
  "src"
69
73
  ],
74
+ "scripts": {
75
+ "benchmark": "node ./benchmarks/benchmark.js",
76
+ "clean": "rm -rf node_modules",
77
+ "contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
78
+ "lint": "standard",
79
+ "postrelease": "pnpm release:tags && pnpm release:github && (ci-publish || npm publish --access=public)",
80
+ "pretest": "pnpm lint",
81
+ "release": "standard-version -a",
82
+ "release:github": "github-generate-release",
83
+ "release:tags": "git push --follow-tags origin HEAD:master",
84
+ "test": "c8 ava"
85
+ },
70
86
  "license": "MIT",
71
87
  "ava": {
72
88
  "files": [
@@ -89,9 +105,6 @@
89
105
  "prettier-standard",
90
106
  "standard --fix"
91
107
  ],
92
- "*.md": [
93
- "standard-markdown"
94
- ],
95
108
  "package.json": [
96
109
  "finepack"
97
110
  ]
@@ -99,18 +112,5 @@
99
112
  "simple-git-hooks": {
100
113
  "commit-msg": "npx commitlint --edit",
101
114
  "pre-commit": "npx nano-staged"
102
- },
103
- "scripts": {
104
- "benchmark": "node ./benchmarks/benchmark.js",
105
- "clean": "rm -rf node_modules",
106
- "contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
107
- "lint": "standard-markdown README.md && standard",
108
- "postinstall": "node scripts/postinstall.js",
109
- "postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
110
- "pretest": "npm run lint",
111
- "release": "standard-version -a",
112
- "release:github": "github-generate-release",
113
- "release:tags": "git push --follow-tags origin HEAD:master",
114
- "test": "c8 ava"
115
115
  }
116
- }
116
+ }
@@ -117,11 +117,19 @@ function buildIndex (providers) {
117
117
  }
118
118
  }
119
119
 
120
- fetch(PROVIDERS_URL)
121
- .then(json =>
122
- writeFile(
123
- path.resolve(__dirname, '../src/providers.json'),
124
- JSON.stringify(buildIndex(normalizeProviders(json)), null, 2)
125
- )
120
+ async function main () {
121
+ const json = await fetch(PROVIDERS_URL)
122
+ const providers = normalizeProviders(json)
123
+ const data = buildIndex(providers)
124
+ await writeFile(
125
+ path.resolve(__dirname, '../src/providers.json'),
126
+ JSON.stringify(data, null, 2)
126
127
  )
127
- .catch(error => console.error(error) || process.exit(1))
128
+ }
129
+
130
+ main()
131
+ .then(() => process.exit(0))
132
+ .catch(error => {
133
+ console.error(error)
134
+ process.exit(1)
135
+ })
@@ -50,19 +50,15 @@ const matchSchemes = (url, schemes) => {
50
50
  }
51
51
 
52
52
  const matchProvider = (url, provider) => {
53
- const {
54
- schemes,
55
- domainWithoutSuffixOfOembedUrl,
56
- domainWithoutSuffixOfUrl
57
- } = provider
53
+ const { schemes, domainWithoutSuffixOfOembedUrl, domainWithoutSuffixOfUrl } =
54
+ provider
58
55
 
59
56
  if (schemes.length !== 0) {
60
57
  return matchSchemes(url, schemes) === true ? provider : undefined
61
58
  }
62
59
 
63
60
  // Since the URL doesn't have an scheme to match, try to match over oEmbed/url
64
- // domain. These are pre-computed during postinstall so that no redundant work
65
- // is needed.
61
+ // domain. These are pre-computed so that no redundant work is needed.
66
62
  const domain = getDomainWithoutSuffix(url)
67
63
  if (
68
64
  domain !== null &&
@@ -96,7 +92,7 @@ module.exports = url => {
96
92
  // work is needed. In case of a match, we usually have a list of one or two
97
93
  // candidates, which is very quick to match against.
98
94
  //
99
- // For more details about `index`, see documentation in `scripts/postinstall.js`.
95
+ // For more details about `index`, see documentation in `scripts/fetch-providers.js`.
100
96
  const indicesOfCandidates = new Set()
101
97
  for (const token of tokenize(baseUrl)) {
102
98
  const providersForToken = index[token]
package/src/index.d.ts ADDED
@@ -0,0 +1,64 @@
1
+ 'use strict'
2
+
3
+ interface Provider {
4
+ name: string
5
+ url: string
6
+ oembedUrl: string
7
+ }
8
+
9
+ interface OembedOptions {
10
+ maxwidth?: number
11
+ maxheight?: number
12
+ [key: string]: string | number | undefined
13
+ }
14
+
15
+ interface OembedResponse {
16
+ type: string
17
+ version: string
18
+ title?: string
19
+ author_name?: string
20
+ author_url?: string
21
+ provider_name?: string
22
+ provider_url?: string
23
+ cache_age?: number
24
+ thumbnail_url?: string
25
+ thumbnail_width?: number
26
+ thumbnail_height?: number
27
+ html?: string
28
+ width?: number
29
+ height?: number
30
+ url?: string
31
+ }
32
+
33
+ /**
34
+ * oembed-spec - A parser for oEmbed specification
35
+ *
36
+ * @param url - The URL to get oembed data for
37
+ * @param opts - Optional oembed parameters
38
+ * @param gotOpts - Optional got library options for HTTP requests
39
+ * @returns Promise resolving to oembed response data, or undefined if no provider found
40
+ */
41
+ declare function oembed(
42
+ url: string,
43
+ opts?: OembedOptions,
44
+ gotOpts?: Record<string, any>
45
+ ): Promise<OembedResponse | undefined>
46
+
47
+ declare namespace oembed {
48
+ /**
49
+ * Find an oEmbed provider for a given URL
50
+ */
51
+ function findProvider(url: string): Provider | undefined
52
+
53
+ /**
54
+ * Fetch oEmbed data from a specific provider
55
+ */
56
+ function fetchProvider(
57
+ provider: Provider,
58
+ url: string,
59
+ opts?: OembedOptions,
60
+ gotOpts?: Record<string, any>
61
+ ): Promise<OembedResponse>
62
+ }
63
+
64
+ export = oembed