import { AnyOperation, Change, CommentOperation, DeleteOperation, EditOperation, InsertOperation, Operation, } from '../../../types/change' export const isInsertOperation = (op: Operation): op is InsertOperation => 'i' in op export const isCommentOperation = (op: Operation): op is CommentOperation => 'c' in op export const isDeleteOperation = (op: Operation): op is DeleteOperation => 'd' in op export const isInsertChange = ( change: Change ): change is Change => isInsertOperation(change.op) export const isCommentChange = ( change: Change ): change is Change => isCommentOperation(change.op) export const isDeleteChange = ( change: Change ): change is Change => isDeleteOperation(change.op) export const visibleTextLength = (op: AnyOperation) => { if (isCommentOperation(op)) { return op.c.length } if (isInsertOperation(op)) { return op.i.length } return 0 }