schlechtenburg/packages/rich-text/lib/remove.ts
2024-10-08 09:15:26 +02:00

22 lines
698 B
TypeScript

/**
* Internal dependencies
*/
import { insert } from './insert';
import { create } from './create';
import { RichTextValue } from './types';
/**
* Remove content from a Rich Text value between the given `startIndex` and
* `endIndex`. Indices are retrieved from the selection if none are provided.
*
* @param {RichTextValue} value Value to modify.
* @param {number} [startIndex] Start index.
* @param {number} [endIndex] End index.
*
* @return {RichTextValue} A new value with the content removed.
*/
export function remove( value: RichTextValue, startIndex: number, endIndex: number ): RichTextValue {
return insert( value, create(), startIndex, endIndex );
}