strind
Partition strings based on character indices.
Install
yarn add strind
Usage
import strind from 'strind';
const result = strind('abcd', [[1, 1], [2, 6]]);
console.log(result);
Callback
An optional callback function can be passed as the third argument.
The function is called with the substring chars
and boolean matches
if the substring matches the array indices.
import strind from 'strind';
const result = strind('abcd', [[1, 1], [2, 6]], ({ chars, matches }) => {
return {
text: chars,
isHighlighted: matches
};
});
console.log(result);
License
MIT