Passed
Push — master ( 61dd3f...482d1b )
by greg
01:51
created

src/cli/cms/editor/handlebars/recursivePrintConfig.js   A

Complexity

Total Complexity 5
Complexity/F 2.5

Size

Lines of Code 23
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 5
c 1
b 0
f 0
nc 1
mnd 2
bc 5
fnc 2
dl 0
loc 23
rs 10
bpm 2.5
cpm 2.5
noi 0
1
2
export default function recursivePrintConfig(obj, key = '') {
3
  var res = ''
4
5
  if(typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Object]') {
6
    Array.prototype.forEach.call(Object.keys(obj), (k) => {
7
      var strKey = key
8
      if(strKey !== '') {
9
        strKey += '.'
10
      }
11
      strKey += k
12
      res += recursivePrintConfig(obj[k], strKey)
13
    })
14
  }else {
15
    res += `<div class="form-group">
16
      <label class="col-sm-4 control-label" for="${key}">${key}</label>
17
      <div class="col-sm-8">
18
        <input type="text" class="form-control" id="${key}" data-json-key="${key}" placeholder="${obj}" value="${obj}">
19
      </div>
20
    </div>`
21
  }
22
23
  return res
24
}
25