UNPKG

misc-utils-of-mine-generic

Version:

Miscellaneous utilities for JavaScript/TypeScript that I often use

12 lines (11 loc) 430 B
export function changeText(text: string, toInsert: { pos: number; toAdd?: string; toRemove?: string }[]): string { let s = text.split('') let indexIncr = 0 toInsert.forEach(data => { data.toAdd = data.toAdd || '' data.toRemove = data.toRemove || '' s.splice(data.pos + indexIncr, data.toRemove.length, ...data.toAdd.split('')) indexIncr += data.toAdd.length - data.toRemove.length }) return s.join('') }