UNPKG

lyrics-structure

Version:

Parser for lyrics with structured sections, names, and indications

54 lines (53 loc) 1.84 kB
"use strict"; /** * Splits text into natural sections based on text structure. * Works with plain text without requiring markdown or special formatting. * Empty lines are treated as natural separators between parts. * * @param text - The input text to be split into sections * @param maxLinesPerSlide - Maximum number of lines to include in a single slide (default: 6) * @returns An array of content sections */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getSlideParts = void 0; const lyrics_1 = require("./lyrics"); const isLineTooLong = (line) => line.length > 60; const processContent = (content) => { const slides = []; let currentSlide = []; content.split('\n').forEach((line) => { const trimmedLine = line.trim(); if (!trimmedLine) { if (currentSlide.length > 0) { slides.push(currentSlide.join('\n')); currentSlide = []; } return; } if (currentSlide.length >= 4 || (currentSlide.length >= 2 && currentSlide.filter(isLineTooLong).length >= 2)) { slides.push(currentSlide.join('\n')); currentSlide = []; } currentSlide.push(trimmedLine); }); if (currentSlide.length > 0) { slides.push(currentSlide.join('\n')); } return slides; }; const getSlideParts = (text) => { if (!text) return []; // Remove text between parentheses const textWithoutParentheses = text.replace(/\([^)]*\)/g, ''); const partsText = (0, lyrics_1.getLyricsParts)(textWithoutParentheses).map((part) => part.content); const result = []; partsText.forEach((part) => { if (part) { result.push(...processContent(part)); } }); return result; }; exports.getSlideParts = getSlideParts;