src/assets/utils/functions.ts   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 0

Size

Lines of Code 22
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 17
mnd 5
bc 5
fnc 0
dl 0
loc 22
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
type TDateType = string | number | Date
2
3
export const formatDate = (date: TDateType) => {
4
  const returnDate = new Date(date).toLocaleDateString("nb-NO", {
5
    year: "numeric",
6
    month: "long",
7
    day: "numeric",
8
  })
9
  if (returnDate === "Invalid Date") {
10
    return date
11
  }
12
  if (returnDate === "1. januar 1970") {
13
    return "Søknadsfrist er ikke registrert"
14
  }
15
  return returnDate
16
}
17
18
export const truncateTextLength = (inputString: string, maxLength: number, suffix: string) =>
19
  inputString.length < maxLength
20
    ? inputString
21
    : `${inputString.substr(0, inputString.substr(0, maxLength - suffix.length).lastIndexOf(" "))}${suffix}`
22