Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Fixed bug where replace was used only once #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

text = text
.replace(/<[^>]+>/g, "") // Strip tags
.replace(/[,:;()\-]/, " ") // Replace commans, hyphens etc (count them as spaces)
.replace(/[\.!?]/, ".") // Unify terminators
.replace(/^\s+/,"") // Strip leading whitespace
.replace(/[ ]*(\n|\r\n|\r)[ ]*/," ") // Replace new lines with spaces
.replace(/([\.])[\. ]+/,".") // Check for duplicated terminators
.replace(/[ ]*([\.])/,". ") // Pad sentence terminators
.replace(/\s+/," ") // Remove multiple spaces
.replace(/\s+$/,""); // Strip trailing whitespace
.replace(/[,:;()\-]/g, " ") // Replace commans, hyphens etc (count them as spaces)
.replace(/[\.!?]/g, ".") // Unify terminators
.replace(/^\s+/g,"") // Strip leading whitespace
.replace(/[ ]*(\n|\r\n|\r)[ ]*/g," ") // Replace new lines with spaces
.replace(/([\.])[\. ]+/g,".") // Check for duplicated terminators
.replace(/[ ]*([\.])/g,". ") // Pad sentence terminators
.replace(/\s+/g," ") // Remove multiple spaces
.replace(/\s+$/g,"") // Strip trailing whitespace
.replace(/'/g,""); // Strip apostrophe

text += "."; // Add final terminator, just in case it's missing.

Expand Down