| Total Complexity | 14 |
| Complexity/F | 7 |
| Lines of Code | 37 |
| Function Count | 2 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 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 | } |