@metascraper/helpers 5.43.3 → 5.43.4
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/index.js +29 -23
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -28,12 +28,9 @@ const urlRegex = require('url-regex-safe')({
|
|
|
28
28
|
|
|
29
29
|
const {
|
|
30
30
|
chain,
|
|
31
|
-
eq,
|
|
32
31
|
flow,
|
|
33
32
|
get,
|
|
34
|
-
includes,
|
|
35
33
|
invoke,
|
|
36
|
-
isArray,
|
|
37
34
|
isBoolean,
|
|
38
35
|
isDate,
|
|
39
36
|
isEmpty,
|
|
@@ -78,6 +75,7 @@ const toTitle = str =>
|
|
|
78
75
|
const VIDEO = 'video'
|
|
79
76
|
const AUDIO = 'audio'
|
|
80
77
|
const IMAGE = 'image'
|
|
78
|
+
const PDF = 'pdf'
|
|
81
79
|
|
|
82
80
|
const imageExtensions = chain(require('image-extensions'))
|
|
83
81
|
.concat(['avif'])
|
|
@@ -106,7 +104,8 @@ const videoExtensions = chain(require('video-extensions'))
|
|
|
106
104
|
const EXTENSIONS = {
|
|
107
105
|
...imageExtensions,
|
|
108
106
|
...audioExtensions,
|
|
109
|
-
...videoExtensions
|
|
107
|
+
...videoExtensions,
|
|
108
|
+
[PDF]: PDF
|
|
110
109
|
}
|
|
111
110
|
|
|
112
111
|
const REGEX_BY = /^[\s\n]*by[\s\n]+|@[\s\n]*/i
|
|
@@ -203,31 +202,39 @@ const protocol = url => {
|
|
|
203
202
|
return protocol.replace(':', '')
|
|
204
203
|
}
|
|
205
204
|
|
|
206
|
-
const
|
|
207
|
-
|
|
205
|
+
const isExtension = (url, type, ext = extension(url)) =>
|
|
206
|
+
type === EXTENSIONS[ext]
|
|
208
207
|
|
|
209
|
-
const
|
|
210
|
-
|
|
208
|
+
const isExtensionUrl = (url, type, { ext, ...opts } = {}) =>
|
|
209
|
+
isUrl(url, opts) && isExtension(url, type, ext)
|
|
210
|
+
|
|
211
|
+
const createIsUrl = type => (url, opts) => isExtensionUrl(url, type, opts)
|
|
212
|
+
|
|
213
|
+
const isVideoUrl = createIsUrl(VIDEO)
|
|
214
|
+
|
|
215
|
+
const isAudioUrl = createIsUrl(AUDIO)
|
|
216
|
+
|
|
217
|
+
const isImageUrl = createIsUrl(IMAGE)
|
|
218
|
+
|
|
219
|
+
const isPdfUrl = createIsUrl(PDF)
|
|
211
220
|
|
|
212
221
|
const isMediaUrl = memoizeOne(
|
|
213
222
|
(url, opts) =>
|
|
214
223
|
isImageUrl(url, opts) || isVideoUrl(url, opts) || isAudioUrl(url, opts)
|
|
215
224
|
)
|
|
216
225
|
|
|
217
|
-
const isVideoUrl = (url, opts) => isMediaTypeUrl(url, VIDEO, opts)
|
|
218
|
-
|
|
219
|
-
const isAudioUrl = (url, opts) => isMediaTypeUrl(url, AUDIO, opts)
|
|
220
|
-
|
|
221
|
-
const isImageUrl = (url, opts) => isMediaTypeUrl(url, IMAGE, opts)
|
|
222
|
-
|
|
223
226
|
const isMediaExtension = url =>
|
|
224
227
|
isImageExtension(url) || isVideoExtension(url) || isAudioExtension(url)
|
|
225
228
|
|
|
226
|
-
const
|
|
229
|
+
const createIsExtension = type => url => isExtension(url, type)
|
|
230
|
+
|
|
231
|
+
const isVideoExtension = createIsExtension(VIDEO)
|
|
227
232
|
|
|
228
|
-
const isAudioExtension =
|
|
233
|
+
const isAudioExtension = createIsExtension(AUDIO)
|
|
229
234
|
|
|
230
|
-
const isImageExtension =
|
|
235
|
+
const isImageExtension = createIsExtension(IMAGE)
|
|
236
|
+
|
|
237
|
+
const isPdfExtension = createIsExtension(PDF)
|
|
231
238
|
|
|
232
239
|
const isContentType =
|
|
233
240
|
extensions =>
|
|
@@ -323,16 +330,14 @@ const lang = input => {
|
|
|
323
330
|
const key = toLower(condenseWhitespace(input))
|
|
324
331
|
if (input.length === 3) return iso6393[key]
|
|
325
332
|
const lang = toLower(key.substring(0, 2))
|
|
326
|
-
return includes(
|
|
333
|
+
return iso6393Values.includes(lang) ? lang : undefined
|
|
327
334
|
}
|
|
328
335
|
|
|
329
336
|
const title = (value, { removeSeparator = false, ...opts } = {}) =>
|
|
330
337
|
isString(value) ? titleize(value, { removeSeparator, ...opts }) : undefined
|
|
331
338
|
|
|
332
|
-
const isMime = (contentType, type) =>
|
|
333
|
-
|
|
334
|
-
return eq(type, get(EXTENSIONS, ext))
|
|
335
|
-
}
|
|
339
|
+
const isMime = (contentType, type) =>
|
|
340
|
+
type === get(EXTENSIONS, mimeExtension(contentType))
|
|
336
341
|
|
|
337
342
|
memoizeOne.EqualityUrlAndHtmlDom = (newArgs, oldArgs) =>
|
|
338
343
|
newArgs[0] === oldArgs[0] && newArgs[1].html() === oldArgs[1].html()
|
|
@@ -490,7 +495,6 @@ module.exports = {
|
|
|
490
495
|
has,
|
|
491
496
|
image,
|
|
492
497
|
imageExtensions,
|
|
493
|
-
isArray,
|
|
494
498
|
isAudioExtension,
|
|
495
499
|
isAudioUrl,
|
|
496
500
|
isAuthor,
|
|
@@ -499,6 +503,8 @@ module.exports = {
|
|
|
499
503
|
isMediaExtension,
|
|
500
504
|
isMediaUrl,
|
|
501
505
|
isMime,
|
|
506
|
+
isPdfExtension,
|
|
507
|
+
isPdfUrl,
|
|
502
508
|
isString,
|
|
503
509
|
isUrl,
|
|
504
510
|
isVideoExtension,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@metascraper/helpers",
|
|
3
3
|
"description": "Collection of helper functions used by metascraper",
|
|
4
4
|
"homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-helpers",
|
|
5
|
-
"version": "5.43.
|
|
5
|
+
"version": "5.43.4",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "158c7d6e6c7a351d0a81529808af97f03f7e8bdf"
|
|
66
66
|
}
|