Total Complexity | 10 |
Complexity/F | 3.33 |
Lines of Code | 60 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 | } |