refactoring 1. step
This commit is contained in:
38
src/utils/helpers.js
Normal file
38
src/utils/helpers.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Utility helper functions for the Quote & Invoice System
|
||||
*/
|
||||
|
||||
function formatDate(date) {
|
||||
const d = new Date(date);
|
||||
const month = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
const year = d.getFullYear();
|
||||
return `${month}/${day}/${year}`;
|
||||
}
|
||||
|
||||
function formatMoney(val) {
|
||||
return parseFloat(val).toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||
}
|
||||
|
||||
function parseNumericValue(val) {
|
||||
if (val === null || val === undefined) return 0;
|
||||
if (typeof val === 'number') return val;
|
||||
return parseFloat(String(val).replace(/[^0-9.\-]/g, '')) || 0;
|
||||
}
|
||||
|
||||
function formatAddress(address) {
|
||||
if (!address) return '';
|
||||
const lines = [];
|
||||
if (address.line1) lines.push(address.line1);
|
||||
if (address.line2) lines.push(address.line2);
|
||||
if (address.line3) lines.push(address.line3);
|
||||
if (address.line4) lines.push(address.line4);
|
||||
return lines.join('<br>');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatDate,
|
||||
formatMoney,
|
||||
parseNumericValue,
|
||||
formatAddress
|
||||
};
|
||||
Reference in New Issue
Block a user