src/shared/lib/throttle.ts   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 15
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 11
mnd 1
bc 1
fnc 0
dl 0
loc 15
rs 10
bpm 0
cpm 0
noi 1
c 0
b 0
f 0
1
const throttle = (fn: () => void, ms: number) => {
2
  let prev: number = 0
0 ignored issues
show
introduced by
Type number trivially inferred from a number literal, remove type annotation.
Loading history...
3
4
  return () => {
5
    const now: number = new Date().valueOf()
6
7
    if (now - prev >= ms) {
8
      fn()
9
      prev = now
10
    }
11
  }
12
}
13
14
export { throttle }
15