Skip to content
Snippets Groups Projects
Commit 7a92630f authored by Toufic Batache's avatar Toufic Batache
Browse files

Better syntax for null-safety

parent 1e05e840
Branches
Tags
1 merge request!155Ajout du contrefactuel du PLF
Pipeline #10021 passed
......@@ -18,8 +18,6 @@
| undefined
| null
$: console.log(unit)
const dispatch = createEventDispatcher()
const numberFormatter = (value: number): string =>
new Intl.NumberFormat("fr-FR", {
......@@ -31,7 +29,7 @@
? "absent"
: typeof billValue.value === "number"
? numberFormatter(
unit !== undefined && unit.ratio
unit?.ratio
? parseFloat((billValue.value * 100).toFixed(8)) // trick to round value * 100
: billValue.value,
)
......@@ -41,7 +39,7 @@
? "absent"
: typeof lawValue.value === "number"
? numberFormatter(
unit !== undefined && unit.ratio
unit?.ratio
? parseFloat((lawValue.value * 100).toFixed(8)) // trick to round value * 100
: lawValue.value,
)
......@@ -53,7 +51,7 @@
? "absent"
: typeof revaluationValue.value === "number"
? numberFormatter(
unit !== undefined && unit.ratio
unit?.ratio
? parseFloat((revaluationValue.value * 100).toFixed(8)) // trick to round value * 100
: revaluationValue.value,
)
......@@ -63,7 +61,7 @@
? "absent"
: typeof value === "number"
? numberFormatter(
unit !== undefined && unit.ratio
unit?.ratio
? parseFloat((value * 100).toFixed(8)) // trick to round value * 100
: value,
)
......@@ -75,7 +73,7 @@
function changeValue({ target }: Event) {
let { value } = target as HTMLInputElement
if (unit !== undefined && unit.ratio) {
if (unit?.ratio) {
const validValue = parseFloat(value)
if (validValue != null && !Number.isNaN(validValue)) {
value = (validValue / 100).toString()
......@@ -126,7 +124,7 @@
placeholder={value === "expected" ? "attendu" : null}
step="any"
value={typeof value === "number"
? unit !== undefined && unit.ratio
? unit?.ratio
? parseFloat((value * 100).toFixed(8)) // trick to round value * 100
: value
: null}
......
......@@ -18,10 +18,10 @@
billValue == null || billValue === "expected" || billValue.value === null
? "absent"
: typeof billValue.value === "number"
? unit !== undefined && unit.name === "year"
? unit?.name === "year"
? billValue.value.toString() // No space in years
: numberFormatter(
unit !== undefined && unit.ratio
unit?.ratio
? parseFloat((billValue.value * 100).toFixed(8)) // trick to round value * 100
: billValue.value,
)
......@@ -31,10 +31,10 @@
lawValue == null || lawValue === "expected" || lawValue.value === null
? "absent"
: typeof lawValue.value === "number"
? unit !== undefined && unit.name === "year"
? unit?.name === "year"
? lawValue.value.toString() // No space in years
: numberFormatter(
unit !== undefined && unit.ratio
unit?.ratio
? parseFloat((lawValue.value * 100).toFixed(8)) // trick to round value * 100
: lawValue.value,
)
......@@ -46,10 +46,10 @@
revaluationValue.value === null
? "absent"
: typeof revaluationValue.value === "number"
? unit !== undefined && unit.name === "year"
? unit?.name === "year"
? revaluationValue.value.toString() // No space in years
: numberFormatter(
unit !== undefined && unit.ratio
unit?.ratio
? parseFloat((revaluationValue.value * 100).toFixed(8)) // trick to round value * 100
: revaluationValue.value,
)
......
......@@ -23,7 +23,7 @@ export function valueFormatter(
value: unknown,
) => string)
: typeof baseValue === "number"
? unit !== undefined && unit.ratio // rate
? unit?.ratio // rate
? (value: unknown): string =>
new Intl.NumberFormat("fr-FR", {
maximumFractionDigits: 2,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment