Passed
Push — main ( c81d48...f3c905 )
by Andrii
03:15
created

src/bem.core.ts   A

Complexity

Total Complexity 11
Complexity/F 11

Size

Lines of Code 62
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 49
mnd 10
bc 10
fnc 1
dl 0
loc 62
bpm 10
cpm 11
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
C bem.core.ts ➔ bem2arr 0 43 11
1
const elementDelimiter = "__"
2
, modDelimiter = "--"
3
, blockModKey = "$" as const
4
5
export type BemAbsraction = {
6
  [block: string]: boolean | {
7
    [blockModKey]?: {
8
      [mod: string]: boolean | string
9
    }
10
    [el: string]: undefined|boolean | {
11
      [mod: string]: boolean | string
12
    }
13
  }
14
}
15
16
export {
17
  bem2arr
18
}
19
20
function bem2arr(query: BemAbsraction) {
21
  const $return: string[] = []
22
23
  for (const block in query) {
24
    const blockQ = query[block]
25
    
26
    if (!blockQ) 
27
      continue
28
    if (typeof blockQ !== "object") {
29
      $return.push(block)
30
      continue
31
    }
32
33
    for (const el in blockQ) {
34
      const elementQ = blockQ[el]
35
      , element = el === blockModKey ? block : `${block}${elementDelimiter}${el}`
36
      
37
      if (!elementQ) {
38
        el === blockModKey && $return.push(element)
39
        continue
40
      }
41
      
42
      $return.push(element)
43
44
      if (typeof elementQ !== "object")
45
        continue
46
47
      for (const mod in elementQ) {
48
        const modValue: string|boolean = elementQ[mod]
49
        if (!modValue)
50
          continue
51
52
        $return.push(`${element}${modDelimiter}${mod}${
53
          typeof modValue !== "string"
54
          ? ""
55
          : `${modDelimiter}${modValue}`
56
        }`)
57
      }
58
    }
59
  }
60
  
61
  return $return
62
}