| import { MongoClient } from 'mongodb'; |
|
|
| async function main() { |
| const uri = "mongodb+srv://healthbuddy:healthbuddy123@healthbuddy.sdlagac.mongodb.net/"; |
| const client = new MongoClient(uri); |
| try { |
| await client.connect(); |
| const db = client.db('aptitude'); |
| const coll = db.collection('quantitative_aptitude'); |
| const doc = await coll.findOne({ chapter_no: 1 }); |
| |
| let text = doc.content; |
| const match = text.match(/(?:^|\n)Q\d+\.\s+/); |
| if (match && match.index !== undefined) { |
| text = text.slice(0, match.index).trim(); |
| } |
| |
| |
| let md = text; |
| |
| |
| md = md.replace(/^(\d+)\.\s+([A-Z0-9\s&]+)$/gm, '## $1. $2'); |
| |
| |
| |
| const lines = md.split('\n'); |
| let inTable = false; |
| let outLines = []; |
| |
| for (let i = 0; i < lines.length; i++) { |
| let line = lines[i]; |
| |
| |
| if (line.includes('\t')) { |
| if (!inTable) { |
| inTable = true; |
| |
| let cells = line.split('\t').map(c => c.trim()); |
| outLines.push('| ' + cells.join(' | ') + ' |'); |
| outLines.push('| ' + cells.map(() => '---').join(' | ') + ' |'); |
| } else { |
| |
| let cells = line.split('\t').map(c => c.trim()); |
| |
| |
| outLines.push('| ' + cells.join(' | ') + ' |'); |
| } |
| } else { |
| if (inTable) { |
| inTable = false; |
| outLines.push(''); |
| } |
| |
| |
| |
| if (line.length > 0 && line.length < 60 && !/[.,:;]$/.test(line.trim()) && !line.startsWith('#') && !line.startsWith('|')) { |
| |
| |
| |
| if (/^(Type \d+|Method \d+|T\d+|Core Definition|Key Relationships|Basic Formulas|Percentage Change|Reverse Percentage|Successive Percentage Change|Population & Depreciation|Comparison Between Two Quantities|Expenditure & Consumption|Percentage Difference)/i.test(line)) { |
| line = '### ' + line; |
| } |
| } |
| |
| outLines.push(line); |
| } |
| } |
| |
| md = outLines.join('\n'); |
| console.log(md.substring(0, 2000)); |
| |
| } catch(e) { |
| console.error(e); |
| } finally { |
| await client.close(); |
| } |
| } |
| main(); |
|
|