Files
makemd/fix-toFixed.js

64 lines
2.5 KiB
JavaScript
Raw Normal View History

const fs = require('fs');
const path = require('path');
const filesToFix = [
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\Finance\\Transactions.tsx',
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\Product\\ProductList.tsx',
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\Product\\CrossPlatformManage.tsx',
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\Orders\\OrderList.tsx',
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\Marketing\\index.tsx',
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\Settings\\SystemSettings.tsx',
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\MultiShopReport\\index.tsx',
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\ArbitrageMonitor\\index.tsx',
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\DynamicPricing\\index.tsx',
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\OrderMultiShopList\\index.tsx',
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\StrategyMarketplace\\index.tsx',
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\Leaderboard\\index.tsx',
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\UserAsset\\UserAssets.tsx',
'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\pages\\Suppliers\\SupplierDetail.tsx',
];
filesToFix.forEach(filePath => {
if (!fs.existsSync(filePath)) {
console.log(`File not found: ${filePath}`);
return;
}
let content = fs.readFileSync(filePath, 'utf8');
let modified = false;
// Pattern 1: value.toFixed( -> (value || 0).toFixed(
const patterns = [
{
// Match: variable.toFixed( but not already wrapped with || or ?.
regex: /(?<![|(])\b([a-zA-Z_][a-zA-Z0-9_]*(?:\.\w+)?)\.toFixed\(/g,
replacement: (match, varName) => {
// Skip if already has safe access
if (varName.includes('||') || varName.includes('?.') || varName.includes('?')) {
return match;
}
// Skip Math.random() and other safe calls
if (varName.includes('Math.random') || varName.includes('percent')) {
return match;
}
return `(${varName} || 0).toFixed(`;
}
}
];
patterns.forEach(pattern => {
const newContent = content.replace(pattern.regex, pattern.replacement);
if (newContent !== content) {
content = newContent;
modified = true;
}
});
if (modified) {
fs.writeFileSync(filePath, content, 'utf8');
console.log(`Fixed: ${path.basename(filePath)}`);
}
});
console.log('Done!');