Total Complexity | 11 |
Complexity/F | 11 |
Lines of Code | 62 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 | } |