INNER CODE UNIT · JavaScript
applyEdits
tradingview/lightweight-charts · website/plugins/docs-markdown/index.js:513
function applyEdits(source, edits) {
const sorted = edits.slice().sort((/** @type {Edit} */ a, /** @type {Edit} */ b) => a.start - b.start || b.end - a.end);
let result = '';
let cursor = 0;
for (const edit of sorted) {
if (edit.start < cursor) {
continue;
}
result += source.slice(cursor, edit.start) + (edit.text ?? '');
cursor = edit.end;
}
return result + source.slice(cursor);
}
/**
* @param {string} content
* @returns {MdastNode}
*/