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

src/bem.ts   A

Complexity

Total Complexity 3
Complexity/F 1.5

Size

Lines of Code 44
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 33
mnd 1
bc 1
fnc 2
dl 0
loc 44
bpm 0.5
cpm 1.5
noi 0
c 0
b 0
f 0
rs 10

2 Functions

Rating   Name   Duplication   Size   Complexity  
A bem.ts ➔ classBeming 0 13 1
A bem.ts ➔ bem 0 20 2
1
import type { BemAbsraction } from "./bem.core";
2
import type { CssModule } from "./definitions.defs";
3
import { bem2arr } from "./bem.core";
4
import { joinWithLead, picker, wrapper } from "./core"
5
import { EMPTY_OBJECT } from "./consts.json"
6
7
export {
8
  classBeming
9
}
10
11
function classBeming<
12
  Ctx extends {classnames: Source, className?: string},
13
  Source extends CssModule = Ctx["classnames"],
14
  // WithClassName extends boolean = Ctx["className"] extends string ? true : false
15
>(
16
 context: Ctx = EMPTY_OBJECT as Ctx
17
) {
18
  const {className} = context
19
  //@ts-expect-error
20
  const host = (arg0?, arg1?) => bem(context, arg0, arg1)
21
22
  return wrapper(host, className)
23
}
24
25
function bem<
26
  Source extends CssModule,
27
>(
28
  {
29
    className,
30
    classnames,
31
  }: {
32
    className?: string,
33
    classnames?: Source,
34
  },
35
  arg0?: boolean | BemAbsraction,
36
  arg1?: BemAbsraction 
37
) {
38
  const source = typeof arg0 === "object" ? arg0 : arg1
39
  , debemed = source && bem2arr(source)
40
  , picked = debemed && picker(classnames, debemed)
41
  , result = joinWithLead(arg0 === true && className, picked)
42
43
  return {className: result}
44
}