Passed
Push — master ( 2a9974...92305b )
by Daniel
01:39 queued 11s
created

assets/utils/functions.ts   A

Complexity

Total Complexity 5
Complexity/F 0

Size

Lines of Code 29
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 23
mnd 5
bc 5
fnc 0
dl 0
loc 29
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
type TDateType = string | number | Date;
2
3
export const formatDate = (date: TDateType): 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 = (
19
  inputString: string,
20
  maxLength: number,
21
  suffix: string
22
): string =>
23
  inputString.length < maxLength
24
    ? inputString
25
    : `${inputString.substr(
26
        0,
27
        inputString.substr(0, maxLength - suffix.length).lastIndexOf(" ")
28
      )}${suffix}`;
29