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

microlinkhq / metascraper / 5799694691

pending completion
5799694691

Pull #651

github

web-flow
Merge 0abd4ff1c into 42dac0d9f
Pull Request #651: feat(helpers): infer audio/video from content type

1677 of 1885 branches covered (88.97%)

Branch coverage included in aggregate %.

101 of 101 new or added lines in 4 files covered. (100.0%)

2475 of 2515 relevant lines covered (98.41%)

499.9 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'
120✔
2

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

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

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

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

2,843✔
31
        return acc
2,843✔
32
      })
1,807✔
33
      return acc
1,807✔
34
    }, {})
222✔
35
    .toPairs()
222✔
36
    .value()
222✔
37

120✔
38
const mergeRules = (rules, baseRules) =>
120✔
39
  chain(rules)
255✔
40
    .reduce((acc, { test, ...rules }) => {
255✔
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))
255✔
52
    .value()
255✔
53

120✔
54
module.exports = { mergeRules, loadRules }
120✔
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