UNPKG

react-text-highlighting

Version:
17 lines (14 loc) 386 B
'use strict'; module.exports = { getRangesFromString: function getRangesFromString(string, text) { var regex = new RegExp(string, 'gi'); var result; var indices = []; while (result = regex.exec(text)) { indices.push(result.index); } return indices.map(function (indice) { return { start: indice, end: indice + string.length - 1 }; }); } };