prettier-plugin-organize-imports
Version:
Make prettier organize your imports using the TypeScript language service API.
14 lines (12 loc) • 420 B
JavaScript
/**
* Apply the given set of text changes to the input.
*
* @param {string} input
* @param {readonly import('typescript').TextChange[]} changes
*/
module.exports.applyTextChanges = (input, changes) =>
changes.reduceRight((text, change) => {
const head = text.slice(0, change.span.start);
const tail = text.slice(change.span.start + change.span.length);
return `${head}${change.newText}${tail}`;
}, input);