@metascraper/helpers 5.54.0 → 5.55.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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +4 -4
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@metascraper/helpers",
3
3
  "description": "Shared helper utilities used across metascraper rules for parsing and normalizing metadata.",
4
4
  "homepage": "https://github.com/microlinkhq/metascraper/packages/metascraper-helpers",
5
- "version": "5.54.0",
5
+ "version": "5.55.0",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -73,5 +73,5 @@
73
73
  "publishConfig": {
74
74
  "access": "public"
75
75
  },
76
- "gitHead": "23db3208c1dcc6367a705bdb9bf723fbaae259e0"
76
+ "gitHead": "c6fdffea348dcee4ff5ce22613518c4c68f50f2a"
77
77
  }
package/src/index.js CHANGED
@@ -548,12 +548,11 @@ const validator = {
548
548
 
549
549
  const truthyTest = () => true
550
550
 
551
- const isValidValue = async (rule, value, args) => {
551
+ const isValidValue = async (value, args) => {
552
552
  try {
553
- return await rule.validate(value, args, debug)
553
+ return await args.validate(value, args, debug)
554
554
  } catch (error) {
555
555
  debug('validate:error', {
556
- pkgName: rule.pkgName,
557
556
  errorName: error?.name,
558
557
  errorMessage: error?.message
559
558
  })
@@ -565,6 +564,7 @@ const findRule = async (rules, args = {}, propName) => {
565
564
  let index = 0
566
565
  let value
567
566
  let hasValue = false
567
+ const validateArgs = args.validate ? { ...args, propName } : args
568
568
 
569
569
  do {
570
570
  const rule = rules[index++]
@@ -574,7 +574,7 @@ const findRule = async (rules, args = {}, propName) => {
574
574
  value = await rule(args)
575
575
  hasValue = has(value)
576
576
  const isRejected =
577
- hasValue && rule.validate && !(await isValidValue(rule, value, args))
577
+ hasValue && args.validate && !(await isValidValue(value, validateArgs))
578
578
  if (isRejected) {
579
579
  value = undefined
580
580
  hasValue = false