@alleyinteractive/changelog-extractor 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -27246,6 +27246,86 @@ function requireCore () {
27246
27246
 
27247
27247
  var coreExports = requireCore();
27248
27248
 
27249
+ /**
27250
+ * Unwrap text that has been wrapped across multiple lines.
27251
+ * This fixes changelog text that has been hard-wrapped for readability
27252
+ * but should flow as continuous text.
27253
+ *
27254
+ * @param {string} text - The text content to unwrap
27255
+ * @returns {string} The unwrapped text
27256
+ */
27257
+ function unwrapText(text) {
27258
+ const lines = text.split('\n');
27259
+ const unwrappedLines = [];
27260
+
27261
+ for (let i = 0; i < lines.length; i++) {
27262
+ let currentLine = lines[i];
27263
+
27264
+ // Skip empty lines - preserve them as-is
27265
+ if (currentLine.trim() === '') {
27266
+ unwrappedLines.push(currentLine);
27267
+ continue
27268
+ }
27269
+
27270
+ // Collect continuation lines
27271
+ let j = i + 1;
27272
+ while (j < lines.length) {
27273
+ const nextLine = lines[j];
27274
+
27275
+ // Stop if next line is empty
27276
+ if (nextLine.trim() === '') {
27277
+ break
27278
+ }
27279
+
27280
+ const trimmedCurrent = currentLine.trim();
27281
+ const trimmedNext = nextLine.trim();
27282
+
27283
+ // Don't unwrap if current line looks like it ends a sentence/item
27284
+ const endsWithPunctuation = /[.!?:;]$/.test(trimmedCurrent);
27285
+ const endsWithCode = /`$/.test(trimmedCurrent);
27286
+ const endsWithBullet = /[-*+]\s*$/.test(trimmedCurrent);
27287
+
27288
+ // Don't unwrap if next line starts a new bullet point, section, or sentence
27289
+ const startsWithBullet = /^[-*+]\s/.test(trimmedNext);
27290
+ const startsWithNumber = /^\d+\.\s/.test(trimmedNext);
27291
+ const startsWithMarkdown = /^[#>]/.test(trimmedNext);
27292
+
27293
+ // More nuanced check for new sentences
27294
+ const prevEndsWithContinuation =
27295
+ /[,&]$/.test(trimmedCurrent) ||
27296
+ /\b(and|or|but|with|for|to|from|in|on|at|by)$/.test(trimmedCurrent);
27297
+ const startsWithCapitalNewSentence =
27298
+ /^[A-Z]/.test(trimmedNext) &&
27299
+ !prevEndsWithContinuation &&
27300
+ endsWithPunctuation;
27301
+
27302
+ // Determine if we should unwrap this line with the next
27303
+ const shouldUnwrap =
27304
+ !endsWithPunctuation &&
27305
+ !endsWithCode &&
27306
+ !endsWithBullet &&
27307
+ !startsWithBullet &&
27308
+ !startsWithNumber &&
27309
+ !startsWithCapitalNewSentence &&
27310
+ !startsWithMarkdown;
27311
+
27312
+ if (shouldUnwrap) {
27313
+ // Join the lines, preserving the original indentation of the first line
27314
+ // but removing indentation from continuation lines
27315
+ currentLine = currentLine + ' ' + trimmedNext;
27316
+ j++; // Move to next line
27317
+ } else {
27318
+ break // Stop unwrapping
27319
+ }
27320
+ }
27321
+
27322
+ unwrappedLines.push(currentLine);
27323
+ i = j - 1; // Skip the lines we've consumed (j-1 because for loop will increment)
27324
+ }
27325
+
27326
+ return unwrappedLines.join('\n')
27327
+ }
27328
+
27249
27329
  /**
27250
27330
  * Parse a Keep a Changelog formatted changelog file.
27251
27331
  *
@@ -27346,7 +27426,9 @@ function parseChangelog(changelogContent, version = null) {
27346
27426
 
27347
27427
  const content = currentSectionContent.join('\n');
27348
27428
  if (content.trim()) {
27349
- currentVersion.sections[currentSection] = content;
27429
+ // Unwrap any text that has been hard-wrapped across lines
27430
+ const unwrappedContent = unwrapText(content);
27431
+ currentVersion.sections[currentSection] = unwrappedContent;
27350
27432
  }
27351
27433
  }
27352
27434
  }
@@ -27368,7 +27450,9 @@ function parseChangelog(changelogContent, version = null) {
27368
27450
 
27369
27451
  const content = trimmedContent.join('\n');
27370
27452
  if (content.trim()) {
27371
- currentVersion.sections['general'] = content;
27453
+ // Unwrap any text that has been hard-wrapped across lines
27454
+ const unwrappedContent = unwrapText(content);
27455
+ currentVersion.sections['general'] = unwrappedContent;
27372
27456
  }
27373
27457
  generalContent = [];
27374
27458
  }