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

microlinkhq / metascraper / 3873014738

pending completion
3873014738

push

github

Kiko Beats
chore(release): v5.33.4

744 of 768 branches covered (96.88%)

Branch coverage included in aggregate %.

2441 of 2476 relevant lines covered (98.59%)

491.02 hits per line

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

98.57
/packages/metascraper/src/rules.js
1
'use strict'
118✔
2

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

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

118✔
17
const loadRules = rulesBundle =>
118✔
18
  chain(rulesBundle)
217✔
19
    .reduce((acc, { test, ...rules }) => {
217✔
20
      forEach(rules, (innerRules, propName) => {
1,800✔
21
        if (test) forEachRule(innerRules, rule => (rule.test = test))
2,823✔
22

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

2,823✔
31
        return acc
2,823✔
32
      })
1,800✔
33
      return acc
1,800✔
34
    }, {})
217✔
35
    .toPairs()
217✔
36
    .value()
217✔
37

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

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