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

__sandbox__/config-and-ts/config.ts   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 46
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 36
mnd 0
bc 0
fnc 2
dl 0
loc 46
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10

2 Functions

Rating   Name   Duplication   Size   Complexity  
A config.ts ➔ setOpts 0 14 1
A config.ts ➔ getOpts 0 13 1
1
/// <reference path="./config-types.d.ts"/>
2
3
export {}
4
5
const options = {
6
  current: {
7
    elementDelimiter: "__" as const,
8
    modDelimiter: "--" as const,
9
    blockModKey: "$" as const,
10
  }
11
}
12
13
14
export {
15
  setOpts, getOpts
16
}
17
18
function setOpts<e extends string, m extends string, b extends string>(
19
  elementDelimiter: e,
20
  modDelimiter: m,
21
  blockModKey: b
22
) {
23
  const current = {
24
    elementDelimiter,
25
    modDelimiter,
26
    blockModKey
27
  }
28
29
  //@ts-expect-error
30
  options.current = current
31
}
32
33
function getOpts() {
34
  return options.current as {
35
    elementDelimiter: "elementDelimiter" extends keyof Bem.Options
36
    ? Bem.Options["elementDelimiter"]
37
    : Bem.Options["$default"]["elementDelimiter"]
38
    modDelimiter: "modDelimiter" extends keyof Bem.Options
39
    ? Bem.Options["modDelimiter"]
40
    : Bem.Options["$default"]["modDelimiter"]
41
    blockModKey:
42
    "blockModKey" extends keyof Bem.Options
43
    ? Bem.Options["blockModKey"]
44
    : Bem.Options["$default"]["blockModKey"]
45
  }
46
}