Advertisement
EntropyStarRover

marc parser

May 27th, 2025
649
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    
  2.     const lines = e.target.result.split('\n').map(line => line.trim()).filter(line => line !== '');
  3.     const output = [];
  4.  
  5.     const regex = /^(.+?) ?: (.+?) \/ (.+?)\. - (.+?) ?: (.+?), (\d{4})\. - (.+)$/;
  6.  
  7. lines.forEach((line, index) => {
  8.       const match = line.match(regex);
  9.  
  10.       if (match) {
  11.         const [
  12.           _,
  13.           title,             // 0-24 h
  14.           subtitle,          // Поеми
  15.           author,            // Недялко Славов
  16.           place,             // Пловдив
  17.           publisher,         // Страница
  18.           year,              // 2003
  19.           pages              // 95 с.
  20.         ] = match.map(m => m.trim());
  21.  
  22.         output.push(
  23.           `Record ${index + 1}:\n` +
  24.           `245 $a: ${title}\n` +
  25.           `245 $b: ${subtitle}\n` +
  26.           `245 $c: ${author}\n` +
  27.           `260 $a: ${place}\n` +
  28.           `260 $b: ${publisher}\n` +
  29.           `260 $c: ${year}\n` +
  30.           `300 $a: ${pages}\n`
  31.         );
  32.       } else {
  33.         output.push(`Record ${index + 1}: Failed to parse: "${line}"\n`);
  34.       }
  35.     });
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement