@daviddh/llm-markdown-whatsapp 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -65,13 +65,13 @@ The library takes a markdown string and splits it into an array of smaller chunk
65
65
  ## Quickstart
66
66
 
67
67
  ```bash
68
- npm install @llm-markdown-whatsapp
68
+ npm install @daviddh/llm-markdown-whatsapp
69
69
  ```
70
70
 
71
71
  ### Basic Usage
72
72
 
73
73
  ```typescript
74
- import { splitChatText } from '@llm-markdown-whatsapp';
74
+ import { splitChatText } from '@daviddh/llm-markdown-whatsapp';
75
75
 
76
76
  const llmResponse = 'Thanks for reaching out. I understand your situation and I want to help you resolve it in the best way possible. You can send your product back at no extra cost. Would you prefer a full refund or an exchange for a different model?';
77
77
 
@@ -187,7 +187,7 @@ Splits a markdown text string into an array of chat-ready chunks.
187
187
  - Returns `[]` for `null`, `undefined`, or empty string.
188
188
 
189
189
  ```typescript
190
- import { splitChatText } from '@llm-markdown-whatsapp';
190
+ import { splitChatText } from '@daviddh/llm-markdown-whatsapp';
191
191
 
192
192
  const chunks = splitChatText(llmMarkdownText);
193
193
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daviddh/llm-markdown-whatsapp",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "private": false,
5
5
  "description": "Transforms Markdown into WhatsApp text format",
6
6
  "keywords": [
@@ -55,9 +55,9 @@
55
55
  "format": "prettier --write \"**/*.{js,ts,json}\"",
56
56
  "check": "npm run format && npm run lint && npm run typecheck",
57
57
  "build": "npm run build --workspaces",
58
- "build:core": "npm run build -w @llm-markdown-whatsapp/core",
58
+ "build:core": "npm run build -w @daviddh/llm-markdown-whatsapp/core",
59
59
  "test": "npm run test --workspaces --if-present",
60
- "test:core": "npm run test -w @llm-markdown-whatsapp/core"
60
+ "test:core": "npm run test -w @daviddh/llm-markdown-whatsapp/core"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@eslint/js": "^9.28.0",
@@ -12,7 +12,7 @@ const NOT_FOUND = -1;
12
12
  /** Double newline offset */
13
13
  const DOUBLE_NEWLINE_OFFSET = 2;
14
14
  /** Check if double newline index is valid */
15
- const isValidDoubleNewlineIndex = (index) => index !== NOT_FOUND && index > MIN_CONTENT_BEFORE_BREAK;
15
+ const isValidDoubleNewlineIndex = (index) => index !== NOT_FOUND && index >= MIN_CONTENT_BEFORE_BREAK;
16
16
  /** Check if text after break has markdown header */
17
17
  const hasMarkdownAfterBreak = (afterBreak) => /^(?:\*[^*\n]+\*|_[^_\n]+_)\s*\n/v.test(afterBreak);
18
18
  /** Get first line of text */
@@ -43,12 +43,21 @@ const isResponsePromptWithBullets = (beforeBreak, afterBreakStartsWithBullets) =
43
43
  const shouldNotSplitAtBreak = (beforeBreak, firstLine, afterBreak, afterBreakStartsWithBullets) => isQuestionWithShortIntroBullets(beforeBreak, firstLine, afterBreak) ||
44
44
  isResponsePromptWithBullets(beforeBreak, afterBreakStartsWithBullets) ||
45
45
  hasQuestionWithOptionsPattern(afterBreak);
46
- /** Processes section breaks (double newlines) */
47
- export function processSectionBreaks(remainingText, chunks) {
48
- const doubleNewlineIndex = remainingText.indexOf('\n\n');
49
- if (!isValidDoubleNewlineIndex(doubleNewlineIndex)) {
50
- return { splitFound: false, newRemainingText: remainingText };
46
+ /** Find all double newline indices in text */
47
+ const findDoubleNewlineIndices = (text) => {
48
+ const indices = [];
49
+ let searchFrom = ZERO;
50
+ while (searchFrom < text.length) {
51
+ const index = text.indexOf('\n\n', searchFrom);
52
+ if (index === NOT_FOUND)
53
+ break;
54
+ indices.push(index);
55
+ searchFrom = index + DOUBLE_NEWLINE_OFFSET;
51
56
  }
57
+ return indices;
58
+ };
59
+ /** Try splitting at a specific double newline position */
60
+ const trySplitAtBreak = (remainingText, doubleNewlineIndex, chunks) => {
52
61
  const beforeBreak = remainingText.substring(ZERO, doubleNewlineIndex);
53
62
  const afterBreak = remainingText.substring(doubleNewlineIndex + DOUBLE_NEWLINE_OFFSET);
54
63
  if (hasMarkdownAfterBreak(afterBreak)) {
@@ -63,5 +72,16 @@ export function processSectionBreaks(remainingText, chunks) {
63
72
  return { splitFound: true, newRemainingText: afterBreak };
64
73
  }
65
74
  }
75
+ return null;
76
+ };
77
+ /** Processes section breaks (double newlines) */
78
+ export function processSectionBreaks(remainingText, chunks) {
79
+ const indices = findDoubleNewlineIndices(remainingText);
80
+ const validIndices = indices.filter(isValidDoubleNewlineIndex);
81
+ for (const index of validIndices) {
82
+ const result = trySplitAtBreak(remainingText, index, chunks);
83
+ if (result !== null)
84
+ return result;
85
+ }
66
86
  return { splitFound: false, newRemainingText: remainingText };
67
87
  }
@@ -13,7 +13,7 @@ export declare const COMBINED_LENGTH_THRESHOLD = 110;
13
13
  /** Short question fragment threshold */
14
14
  export declare const SHORT_QUESTION_FRAGMENT_THRESHOLD = 35;
15
15
  /** Minimum content before section break to split */
16
- export declare const MIN_CONTENT_BEFORE_BREAK = 50;
16
+ export declare const MIN_CONTENT_BEFORE_BREAK = 45;
17
17
  /** Short chunk threshold for anti-double-split */
18
18
  export declare const SHORT_CHUNK_THRESHOLD = 50;
19
19
  /** Current text short threshold for anti-double-split */
@@ -13,7 +13,7 @@ export const COMBINED_LENGTH_THRESHOLD = 110;
13
13
  /** Short question fragment threshold */
14
14
  export const SHORT_QUESTION_FRAGMENT_THRESHOLD = 35;
15
15
  /** Minimum content before section break to split */
16
- export const MIN_CONTENT_BEFORE_BREAK = 50;
16
+ export const MIN_CONTENT_BEFORE_BREAK = 45;
17
17
  /** Short chunk threshold for anti-double-split */
18
18
  export const SHORT_CHUNK_THRESHOLD = 50;
19
19
  /** Current text short threshold for anti-double-split */