Completed
Push — master ( 430c18...52d1c6 )
by
unknown
54s
created

src/cli/cms/data/utils.js   A

Complexity

Total Complexity 14
Complexity/F 7

Size

Lines of Code 37
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 14
c 1
b 0
f 0
nc 1
mnd 6
bc 9
fnc 2
dl 0
loc 37
rs 10
bpm 4.5
cpm 7
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B utils.js ➔ getPercentOfRequiredTagsFilled 0 33 4
1
import {
2
  cmsData
3
} from '../../'
4
5
export function getPercentOfRequiredTagsFilled(text, json) {
6
  var regAbe = /{{abe[\S\s].*?key=['|"]([\S\s].*?['|"| ]}})/g
7
  var matches = text.match(regAbe)
8
  var requiredValue = 0
9
  var complete = 0
10
  if(typeof matches !== 'undefined' && matches !== null){
11
    Array.prototype.forEach.call(matches, (match) => {
12
      if(typeof match !== 'undefined' && match !== null) {
13
        
14
        var keyAttr = cmsData.regex.getAttr(match, 'key')
15
        var requiredAttr = cmsData.regex.getAttr(match, 'required')
16
        if(requiredAttr === 'true') {
17
          requiredValue++
18
19
          var minAttr = cmsData.regex.getAttr(match, 'min-length')
20
          minAttr = (minAttr !== '') ? minAttr : 0
21
22
          if(typeof json[keyAttr] !== 'undefined' && json[keyAttr] !== null && json[keyAttr] !== '') {
23
            if(minAttr > 0) {
24
              if(json[keyAttr].length >= minAttr) {
25
                complete++
26
              }
27
            }else {
28
              complete++
29
            }
30
          }
31
        }
32
      }
33
    })
34
  }
35
36
  return Math.round((requiredValue > 0) ? complete * 100 / requiredValue : 100)
37
}