summaryrefslogtreecommitdiff
path: root/animism-align/frontend/views/align/align.util.js
diff options
context:
space:
mode:
Diffstat (limited to 'animism-align/frontend/views/align/align.util.js')
-rw-r--r--animism-align/frontend/views/align/align.util.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/animism-align/frontend/views/align/align.util.js b/animism-align/frontend/views/align/align.util.js
index 32cbc35..ce72aef 100644
--- a/animism-align/frontend/views/align/align.util.js
+++ b/animism-align/frontend/views/align/align.util.js
@@ -26,3 +26,27 @@ export const timeToPosition = (ts, { start_ts, zoom, duration }) => {
}
return (ts - timeMin) / timeWidth * height
}
+
+export const getFirstPunctuationMarkIndex = text => {
+ return Math.min(
+ text.indexOf('. '),
+ text.indexOf('? '),
+ text.indexOf('! '),
+ text.indexOf('." '),
+ text.indexOf('?" '),
+ text.indexOf('!" '),
+ text.indexOf('.” '),
+ text.indexOf('?” '),
+ text.indexOf('!” '),
+ ) + 1
+}
+
+export const cutFirstSentence = text => {
+ const textToCrop = text.trim().replace("\n", " ").split("\n")[0]
+ let cropIndex = getFirstPunctuationMarkIndex(textToCrop)
+ if (!cropIndex) cropIndex = textToCrop.length
+ const croppedText = textToCrop.substr(0, cropIndex).trim()
+ const updatedText = text.trim().replace(croppedText, '').trim()
+ actions.site.updateText(updatedText)
+ return croppedText
+}