@ -1,19 +1,29 @@
|
||||
const DEBUG_MODE = false;
|
||||
|
||||
export function canBeCastAsIntegerOrNull(
|
||||
probableNumberOrNull: string | undefined | number | null,
|
||||
): probableNumberOrNull is number | null {
|
||||
if (probableNumberOrNull === undefined) {
|
||||
if (DEBUG_MODE) console.log('probableNumberOrNull === undefined');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof probableNumberOrNull === 'number') {
|
||||
if (DEBUG_MODE) console.log('typeof probableNumberOrNull === "number"');
|
||||
|
||||
return Number.isInteger(probableNumberOrNull);
|
||||
}
|
||||
|
||||
if (probableNumberOrNull === null) {
|
||||
if (DEBUG_MODE) console.log('probableNumberOrNull === null');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (probableNumberOrNull === '') {
|
||||
if (DEBUG_MODE) console.log('probableNumberOrNull === ""');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -21,9 +31,13 @@ export function canBeCastAsIntegerOrNull(
|
||||
const stringAsNumber = +probableNumberOrNull;
|
||||
|
||||
if (isNaN(stringAsNumber)) {
|
||||
if (DEBUG_MODE) console.log('isNaN(stringAsNumber)');
|
||||
|
||||
return false;
|
||||
}
|
||||
if (Number.isInteger(stringAsNumber)) {
|
||||
if (DEBUG_MODE) console.log('Number.isInteger(stringAsNumber)');
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
4
front/src/utils/formatNumber.ts
Normal file
4
front/src/utils/formatNumber.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export function formatNumber(value: number) {
|
||||
// Formats the value to a string and add commas to it ex: 50,000 | 500,000
|
||||
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
}
|
||||
Reference in New Issue
Block a user