• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

microlinkhq / metascraper / 7360669003

29 Dec 2023 11:58PM UTC coverage: 94.193%. First build
7360669003

Pull #683

github

web-flow
Merge 57740dd88 into 04d321c4b
Pull Request #683: feat(video): improve iframe detection

1729 of 1947 branches covered (0.0%)

Branch coverage included in aggregate %.

2537 of 2582 relevant lines covered (98.26%)

414.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.47
/packages/metascraper/src/rules.js
1
'use strict'
123✔
2

123✔
3
const {
123✔
4
  cloneDeep,
123✔
5
  concat,
123✔
6
  first,
123✔
7
  findIndex,
123✔
8
  forEach,
123✔
9
  chain,
123✔
10
  castArray,
123✔
11
  has,
123✔
12
  set
123✔
13
} = require('lodash')
123✔
14

123✔
15
const forEachRule = (collection, fn) => forEach(castArray(collection), fn)
123✔
16

123✔
17
const loadRules = rulesBundle =>
123✔
18
  chain(rulesBundle)
242✔
19
    .reduce((acc, { test, ...rules }) => {
242✔
20
      forEach(rules, (innerRules, propName) => {
1,836✔
21
        if (test) forEachRule(innerRules, rule => (rule.test = test))
2,884!
22

2,884✔
23
        set(
2,884✔
24
          acc,
2,884✔
25
          propName,
2,884✔
26
          has(acc, propName)
2,884✔
27
            ? concat(acc[propName], innerRules)
2,884✔
28
            : concat(innerRules)
2,884✔
29
        )
2,884✔
30

2,884✔
31
        return acc
2,884✔
32
      })
1,836✔
33
      return acc
1,836✔
34
    }, {})
242✔
35
    .toPairs()
242✔
36
    .value()
242✔
37

123✔
38
const mergeRules = (rules, baseRules) =>
123✔
39
  chain(rules)
271✔
40
    .reduce((acc, { test, ...rules }) => {
271✔
41
      forEach(rules, (innerRules, propName) => {
3✔
42
        if (test) forEachRule(innerRules, rule => (rule.test = test))
4!
43
        // find the rules associated with `propName`
4✔
44
        const index = findIndex(acc, item => first(item) === propName)
4✔
45
        // if `propName` has more rule, add the new rule from the end
4✔
46
        if (index !== -1) acc[index][1] = concat(innerRules, ...acc[index][1])
4✔
47
        // otherwise, create an array of rules
3✔
48
        else acc.push([propName, castArray(innerRules)])
3✔
49
      })
3✔
50
      return acc
3✔
51
    }, cloneDeep(baseRules))
271✔
52
    .value()
271✔
53

123✔
54
module.exports = { mergeRules, loadRules }
123✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc