@metascraper/helpers 5.43.1 → 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.
Files changed (2) hide show
  1. package/index.js +30 -22
  2. 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,29 +202,39 @@ const protocol = url => {
203
202
  return protocol.replace(':', '')
204
203
  }
205
204
 
206
- const isMediaTypeUrl = (url, type, { ext, ...opts } = {}) =>
207
- isUrl(url, opts) && isMediaTypeExtension(url, type, ext)
205
+ const isExtension = (url, type, ext = extension(url)) =>
206
+ type === EXTENSIONS[ext]
208
207
 
209
- const isMediaTypeExtension = (url, type, ext) =>
210
- eq(type, get(EXTENSIONS, ext || extension(url)))
208
+ const isExtensionUrl = (url, type, { ext, ...opts } = {}) =>
209
+ isUrl(url, opts) && isExtension(url, type, ext)
211
210
 
212
- const isMediaUrl = (url, opts) =>
213
- isImageUrl(url, opts) || isVideoUrl(url, opts) || isAudioUrl(url, opts)
211
+ const createIsUrl = type => (url, opts) => isExtensionUrl(url, type, opts)
214
212
 
215
- const isVideoUrl = (url, opts) => isMediaTypeUrl(url, VIDEO, opts)
213
+ const isVideoUrl = createIsUrl(VIDEO)
216
214
 
217
- const isAudioUrl = (url, opts) => isMediaTypeUrl(url, AUDIO, opts)
215
+ const isAudioUrl = createIsUrl(AUDIO)
218
216
 
219
- const isImageUrl = (url, opts) => isMediaTypeUrl(url, IMAGE, opts)
217
+ const isImageUrl = createIsUrl(IMAGE)
218
+
219
+ const isPdfUrl = createIsUrl(PDF)
220
+
221
+ const isMediaUrl = memoizeOne(
222
+ (url, opts) =>
223
+ isImageUrl(url, opts) || isVideoUrl(url, opts) || isAudioUrl(url, opts)
224
+ )
220
225
 
221
226
  const isMediaExtension = url =>
222
227
  isImageExtension(url) || isVideoExtension(url) || isAudioExtension(url)
223
228
 
224
- const isVideoExtension = url => isMediaTypeExtension(url, VIDEO)
229
+ const createIsExtension = type => url => isExtension(url, type)
225
230
 
226
- const isAudioExtension = url => isMediaTypeExtension(url, AUDIO)
231
+ const isVideoExtension = createIsExtension(VIDEO)
227
232
 
228
- const isImageExtension = url => isMediaTypeExtension(url, IMAGE)
233
+ const isAudioExtension = createIsExtension(AUDIO)
234
+
235
+ const isImageExtension = createIsExtension(IMAGE)
236
+
237
+ const isPdfExtension = createIsExtension(PDF)
229
238
 
230
239
  const isContentType =
231
240
  extensions =>
@@ -321,16 +330,14 @@ const lang = input => {
321
330
  const key = toLower(condenseWhitespace(input))
322
331
  if (input.length === 3) return iso6393[key]
323
332
  const lang = toLower(key.substring(0, 2))
324
- return includes(iso6393Values, lang) ? lang : undefined
333
+ return iso6393Values.includes(lang) ? lang : undefined
325
334
  }
326
335
 
327
336
  const title = (value, { removeSeparator = false, ...opts } = {}) =>
328
337
  isString(value) ? titleize(value, { removeSeparator, ...opts }) : undefined
329
338
 
330
- const isMime = (contentType, type) => {
331
- const ext = mimeExtension(contentType)
332
- return eq(type, get(EXTENSIONS, ext))
333
- }
339
+ const isMime = (contentType, type) =>
340
+ type === get(EXTENSIONS, mimeExtension(contentType))
334
341
 
335
342
  memoizeOne.EqualityUrlAndHtmlDom = (newArgs, oldArgs) =>
336
343
  newArgs[0] === oldArgs[0] && newArgs[1].html() === oldArgs[1].html()
@@ -488,7 +495,6 @@ module.exports = {
488
495
  has,
489
496
  image,
490
497
  imageExtensions,
491
- isArray,
492
498
  isAudioExtension,
493
499
  isAudioUrl,
494
500
  isAuthor,
@@ -497,6 +503,8 @@ module.exports = {
497
503
  isMediaExtension,
498
504
  isMediaUrl,
499
505
  isMime,
506
+ isPdfExtension,
507
+ isPdfUrl,
500
508
  isString,
501
509
  isUrl,
502
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.1",
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": "d923747a54c3b7244e4710227fd32a39608c3ddf"
65
+ "gitHead": "158c7d6e6c7a351d0a81529808af97f03f7e8bdf"
66
66
  }