Passed
Push — main ( 67f6a3...fa9d82 )
by Andrii
02:11
created

src/utils.ts   A

Complexity

Total Complexity 6
Complexity/F 1.5

Size

Lines of Code 34
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 26
mnd 2
bc 2
fnc 4
dl 0
loc 34
rs 10
bpm 0.5
cpm 1.5
noi 0
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A utils.ts ➔ emptyLambda 0 3 1
A utils.ts ➔ classNamedToString 0 3 1
A utils.ts ➔ stringifyClassNamed 0 6 2
A utils.ts ➔ emptize 0 8 2
1
const stringifyProperty: SymbolConstructor["toPrimitive"] | "valueOf" | "toString"  = Symbol.toPrimitive
2
3
const {
4
  defineProperty: $defineProperty
5
} = Object
6
7
export {
8
 stringifyClassNamed, emptize
9
}
10
11
function stringifyClassNamed<T extends {className: string}>(source: T) :T {
12
  if (!source.hasOwnProperty(stringifyProperty))
13
    $defineProperty(source, stringifyProperty, {value: classNamedToString})
14
  
15
  return source
16
}
17
18
function classNamedToString(this: {className: string}) {
19
  return this.className
20
}
21
22
function emptize(source: undefined|Record<string, any>) {
23
  if (
24
    source
25
    && !source.hasOwnProperty(stringifyProperty)
26
  )
27
    $defineProperty(source, stringifyProperty, {value: emptyLambda})
28
  return source
29
}
30
31
function emptyLambda() {
32
  return "" as const
33
}
34