codexparser 0.1.74 → 0.1.75

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/CodexParser.js +10 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codexparser",
3
- "version": "0.1.74",
3
+ "version": "0.1.75",
4
4
  "description": "This is a Javascript Bible parser and text scanner. It will search through texts and collate all scripture references into an array and parse them into objects, and it will parse passages into objects by book, chapter, verse, and testament. ",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1134,9 +1134,7 @@ class CodexParser {
1134
1134
  const { originalText, abbr, original } = passage
1135
1135
  const newReference = useAbbreviations ? abbr : original
1136
1136
 
1137
- // Create regex to match originalText with optional parentheses
1138
- const escapedOriginalText = originalText.replace(/([:.])/g, "\\$1").replace(/\s+/g, "\\s*")
1139
- const regex = new RegExp(`(\\()?\\s*${escapedOriginalText}\\s*(\\))?`, "g")
1137
+ const regex = new RegExp(`${originalText}`, "g")
1140
1138
 
1141
1139
  // Find all matches
1142
1140
  const matches = [...result.matchAll(regex)]
@@ -1146,9 +1144,15 @@ class CodexParser {
1146
1144
  const match = matches[j]
1147
1145
  const startIndex = match.index
1148
1146
  const endIndex = startIndex + match[0].length
1149
- // Preserve parentheses if present in the match
1150
- const hasParens = match[1] === "(" && match[2] === ")"
1151
- const replacement = hasParens ? `(${newReference})` : newReference
1147
+ const leadingSpace = match[1] || "" // Capture leading spaces
1148
+ const hasOpeningParen = match[2] === "("
1149
+ const hasClosingParen = match[3] === ")"
1150
+ const trailingSpace = match[4] || " " // Capture trailing spaces
1151
+ // Preserve parentheses if present
1152
+ const replacement =
1153
+ hasOpeningParen && hasClosingParen
1154
+ ? `${leadingSpace}(${newReference})${trailingSpace}`
1155
+ : `${leadingSpace}${newReference}${trailingSpace}`
1152
1156
  result = result.slice(0, startIndex) + replacement + result.slice(endIndex)
1153
1157
  }
1154
1158
  }