Completed
Push — master ( 273a12...880c09 )
by
unknown
02:14
created

encodeAbeTagAsComment.js ➔ encodeAbeTagAsComment   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
c 1
b 0
f 0
nc 4
dl 0
loc 28
rs 6.7272
nop 1
1
import {
2
  cmsData
3
} from '../../'
4
5
/**
6
 * Encode / Escape && add data-abe attributs
7
 * @param  {String} block
8
 * @return {String} escaped string
9
 */
10
export default function encodeAbeTagAsComment(block){
11
  var matchAbe = block.match(/>\s*\{\{abe .*\}\}/g)
12
  if(matchAbe){
13
    for (var i = 0; i < matchAbe.length; i++){
14
      var getattr = cmsData.regex.getAttr(matchAbe[i], 'key').replace('.', '[0]-')
15
      block = block.replace(
16
        matchAbe[i],
17
        ' data-abe-' + cmsData.regex.validDataAbe(getattr) + '="'  + getattr + '" >'
18
      )
19
    }
20
  }
21
  matchAbe = block.match(/( [A-Za-z0-9\-\_]+="*{{.*?}})/g)
22
  if(matchAbe){
23
    for (var i = 0; i < matchAbe.length; i++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 13. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
24
      if(typeof matchAbe !== 'undefined' && matchAbe !== null){
25
        var getattr = cmsData.regex.getAttr(matchAbe[i], 'key').replace('.', '[0]-')
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable getattr already seems to be declared on line 14. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
26
        var matchattr = (matchAbe[i].split('=')[0]).trim()
27
        block = block.replace(
28
            matchAbe[i],
29
            ' data-abe-attr-' + cmsData.regex.validDataAbe(getattr) + '="'  + matchattr + '"' +
30
            ' data-abe-' + cmsData.regex.validDataAbe(getattr) + '="'  + getattr + '" ' + matchAbe[i]
31
          )
32
          .replace(/\{\{\abe.*?}\}/, '')
33
      }
34
    }
35
  }
36
  return escape(block)
37
}