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

microlinkhq / metascraper / 5807461439

pending completion
5807461439

Pull #651

github

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

1683 of 1889 branches covered (89.09%)

Branch coverage included in aggregate %.

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

2484 of 2524 relevant lines covered (98.42%)

501.34 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'
121✔
2

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

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

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

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

2,869✔
31
        return acc
2,869✔
32
      })
1,824✔
33
      return acc
1,824✔
34
    }, {})
230✔
35
    .toPairs()
230✔
36
    .value()
230✔
37

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

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