Passed
Push — main ( 792997...b64a3d )
by Andrii
02:52
created

src/bem.core.ts   A

Complexity

Total Complexity 10
Complexity/F 3.33

Size

Lines of Code 60
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 45
mnd 7
bc 7
fnc 3
dl 0
loc 60
rs 10
bpm 2.3333
cpm 3.3333
noi 0
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A bem.core.ts ➔ getOptions 0 4 1
B bem.core.ts ➔ bem2arr 0 30 8
A bem.core.ts ➔ setOptions 0 6 1
1
import type { BemInGeneral } from "./bem.types"
2
3
let modDelimiter = "--"
4
// TODO #30 , elementDelimiter = "__"
5
6
export type BemOptions = {
7
  // TODO #30 elementDelimiter: string
8
  modDelimiter: string
9
}
10
11
export {
12
  bem2arr,
13
  setOptions,
14
  getOptions
15
}
16
17
function bem2arr(query: BemInGeneral) {
18
  const $return: string[] = []
19
20
  for (const base in query) {
21
    const baseQ = query[base]
22
    $return.push(base)
23
    
24
    if (!baseQ) 
25
      continue
26
    if (typeof baseQ !== "object") {
27
      if (typeof baseQ === "string")
28
        $return.push(`${base}${modDelimiter}${baseQ}`)
29
      continue
30
    }
31
32
    for (const mod in baseQ) {
33
      const modValue = baseQ[mod]
34
      if (!modValue)
35
        continue
36
37
      $return.push(`${base}${modDelimiter}${mod}${
38
        typeof modValue !== "string"
39
        ? ""
40
        : `${modDelimiter}${modValue}`
41
      }`)
42
    }
43
  }
44
  
45
  return $return
46
}
47
48
function setOptions({
49
  // TODO #30 elementDelimiter: elD = elementDelimiter,
50
  modDelimiter: modDel = modDelimiter
51
}: Partial<BemOptions>) {
52
  modDelimiter = modDel
53
}
54
55
function getOptions() {
56
  return {
57
    // TODO #30 elementDelimiter,
58
    modDelimiter,
59
  }
60
}