diff options
Diffstat (limited to 'animism-align/frontend/views/align/align.util.js')
| -rw-r--r-- | animism-align/frontend/views/align/align.util.js | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/animism-align/frontend/views/align/align.util.js b/animism-align/frontend/views/align/align.util.js index d7b4c39..91af64c 100644 --- a/animism-align/frontend/views/align/align.util.js +++ b/animism-align/frontend/views/align/align.util.js @@ -31,17 +31,22 @@ export const timeToPosition = (ts, { start_ts, zoom, duration }) => { } 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 + const indexes = [ + text.indexOf('. '), + text.indexOf('? '), + text.indexOf('! '), + text.indexOf('." '), + text.indexOf('?" '), + text.indexOf('!" '), + text.indexOf('.” '), + text.indexOf('?” '), + text.indexOf('!” '), + ] + + return indexes.reduce((a, b) => { + if (b < 0) return a + return Math.min(a, b) + }, Infinity) + 1 } export const cutFirstSentence = text => { |
