UNPKG

@bbc/react-transcript-editor

Version:

A React component to make transcribing audio and video easier and faster.

11 lines 984 B
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;/** * Helper function to generate draft.js entities, * see unit test for example data structure * it adds offset and length to recognise word in draftjs */ /** * @param {json} words - List of words * @param {string} wordAttributeName - eg 'punct' or 'text' or etc. * attribute for the word object containing the text. eg word ={ punct:'helo', ... } * or eg word ={ text:'helo', ... } */var generateEntitiesRanges=function(words,wordAttributeName){var position=0;return words.map(function(word){var result={start:word.start,end:word.end,confidence:word.confidence,text:word[wordAttributeName],offset:position,length:word[wordAttributeName].length,key:Math.random().toString(36).substring(6)};// increase position counter - to determine word offset in paragraph return position=position+word[wordAttributeName].length+1,result})},_default=generateEntitiesRanges;exports.default=_default;