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

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 29
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 21
mnd 2
bc 2
fnc 0
dl 0
loc 29
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
// Convert time to hours and minutes
2
export const calcTime = (time: number): string => {
3
  const hours = (time / 60) | 0
4
  const mins = time % 60
5
  return `${hours}h ${mins}m`
6
}
7
8
// Convert a number to money formatting
9
export const convertMoney = (money: number | bigint): string => {
10
  const formatter = new Intl.NumberFormat('en-US', {
11
    style: 'currency',
12
    currency: 'USD',
13
    minimumFractionDigits: 0,
14
  })
15
  return formatter.format(money)
16
}
17
18
export const isPersistedState = (stateName: string) => {
19
  try {
20
    const sessionState = sessionStorage.getItem(stateName)
21
    if (sessionState !== null) {
22
      return JSON.parse(sessionState)
23
    }
24
    return null
25
  } catch (error) {
26
    console.error(error)
27
  }
28
}
29