From acbdef1cf107f111481246f934667cc897fb38be Mon Sep 17 00:00:00 2001 From: Nihey Takizawa Date: Tue, 11 Jun 2024 20:03:20 -0300 Subject: [PATCH] fix: fix reorganizeWords expecting segments in a different pattern --- package-lock.json | 4 ++-- package.json | 2 +- src/reorganizeWords.js | 22 ++++++++++------------ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index ce5598c..855666b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kassellabs/autoeditor", - "version": "1.4.0", + "version": "1.4.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kassellabs/autoeditor", - "version": "1.4.0", + "version": "1.4.1", "license": "MIT", "dependencies": { "events": "^3.3.0" diff --git a/package.json b/package.json index bc2a161..2f28c95 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kassellabs/autoeditor", - "version": "1.4.0", + "version": "1.4.1", "description": "Autoeditor as an Embeddable component", "main": "dist/editor.js", "scripts": { diff --git a/src/reorganizeWords.js b/src/reorganizeWords.js index 11d22dc..66d975a 100644 --- a/src/reorganizeWords.js +++ b/src/reorganizeWords.js @@ -1,5 +1,3 @@ -const convertTimeStringToSeconds = require('./convertTimeStringToSeconds'); - const WORD_END_CHARACTERS = new Set(['?', '.', '!']); const reorganizeWords = (segments, { @@ -12,8 +10,8 @@ const reorganizeWords = (segments, { const reorganizedSegments = []; let currentSegment = { - startTime: null, - endTime: null, + start: null, + end: null, words: [], }; @@ -21,13 +19,13 @@ const reorganizeWords = (segments, { let currentCharCount = 0; words.forEach((word, index) => { - const wordEnd = convertTimeStringToSeconds(word.endTime); + const wordEnd = word.end; const wordString = word.word.trim(); const wordCharCount = wordString.length; - if (currentSegment.startTime === null) { - currentSegment.startTime = word.startTime; - currentSegment.endTime = word.endTime; + if (currentSegment.start === null) { + currentSegment.start = word.start; + currentSegment.end = word.end; currentSegment.words.push({ ...word, word: removePunctuation ? word.word.trim().replace(/[.?!,]/g, '') : word.word, @@ -35,7 +33,7 @@ const reorganizeWords = (segments, { currentCharCount += wordCharCount; return; // continue } - const segmentStart = convertTimeStringToSeconds(currentSegment.startTime); + const segmentStart = currentSegment.start; const lastWordString = words[index - 1]?.word?.trim() || ''; const isWordEnding = WORD_END_CHARACTERS.has(lastWordString.slice(-1)); @@ -52,14 +50,14 @@ const reorganizeWords = (segments, { ) { reorganizedSegments.push(currentSegment); currentSegment = { - startTime: word.startTime, - endTime: null, + start: word.start, + end: null, words: [], }; currentCharCount = 0; } - currentSegment.endTime = word.endTime; + currentSegment.end = word.end; currentSegment.words.push({ ...word, word: removePunctuation ? word.word.trim().replace(/[.?!,]/g, '') : word.word,