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

bem.core.ts ➔ bem2arr   B

Complexity

Conditions 8

Size

Total Lines 30
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 30
rs 7.3333
c 0
b 0
f 0
cc 8
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
}