react-diff-view
Version:
A git diff component to consume the git unified diff output.
28 lines • 979 B
JavaScript
import { flatMap } from 'lodash';
import { leafOf, replace } from './utils';
function markInPaths(word, name, replacement) {
return (paths) => flatMap(paths, path => {
const leaf = leafOf(path);
if (!leaf.value.includes(word)) {
return [path];
}
const segments = leaf.value.split(word);
return segments.reduce((output, text, i) => {
if (i !== 0) {
output.push(replace(path, { type: 'mark', markType: name, value: replacement }));
}
if (text) {
output.push(replace(path, { ...leaf, value: text }));
}
return output;
}, []);
});
}
export default function markWord(word, name, replacement = word) {
const mark = markInPaths(word, name, replacement);
return ([oldLinesOfPaths, newLinesOfPaths]) => [
oldLinesOfPaths.map(mark),
newLinesOfPaths.map(mark),
];
}
//# sourceMappingURL=markWord.js.map