UNPKG

@talend/react-components

Version:
39 lines (37 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.allIndexOf = allIndexOf; exports.removeDuplicates = removeDuplicates; /** * This function allow to return all the indexof string of a given string * @param str string to search in * @param toSearch value to search */ function allIndexOf(str, toSearch) { const indices = []; for (let pos = str.indexOf(toSearch); pos !== -1; pos = str.indexOf(toSearch, pos + 1)) { indices.push(pos); } return indices; } /** * This function allow to remove 'duplicates' indexes ( when same character is typed for example * : label : "aaaaa" for searched string "aa") * * @param indexes list of indexes * @param search searchCriteria */ function removeDuplicates(indexes, search) { const array = []; indexes.forEach(matchingIndex => { if (array.length === 0) { array.push(matchingIndex); } else if (matchingIndex >= array[array.length - 1] + search.length) { array.push(matchingIndex); } }); return array; } //# sourceMappingURL=utils.js.map