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

microlinkhq / metascraper / 7249584693

18 Dec 2023 02:36PM UTC coverage: 94.158%. First build
7249584693

Pull #678

github

web-flow
Merge a775adae1 into 9235196f5
Pull Request #678: refactor(media-provider): remove unnecessary dependency

1713 of 1930 branches covered (0.0%)

Branch coverage included in aggregate %.

7 of 7 new or added lines in 2 files covered. (100.0%)

2510 of 2555 relevant lines covered (98.24%)

411.76 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'
122✔
2

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

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

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

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

2,877✔
31
        return acc
2,877✔
32
      })
1,832✔
33
      return acc
1,832✔
34
    }, {})
238✔
35
    .toPairs()
238✔
36
    .value()
238✔
37

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

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