Utils.js 623 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // @ts-check
  2. /**
  3. * @import { CommentOp, DeleteOp, InsertOp, Op, RetainOp } from './types'
  4. */
  5. /**
  6. * @param {Op} op
  7. * @returns {op is InsertOp}
  8. */
  9. export function isInsert(op) {
  10. return 'i' in op && op.i != null
  11. }
  12. /**
  13. * @param {Op} op
  14. * @returns {op is RetainOp}
  15. */
  16. export function isRetain(op) {
  17. return 'r' in op && op.r != null
  18. }
  19. /**
  20. * @param {Op} op
  21. * @returns {op is DeleteOp}
  22. */
  23. export function isDelete(op) {
  24. return 'd' in op && op.d != null
  25. }
  26. /**
  27. * @param {Op} op
  28. * @returns {op is CommentOp}
  29. */
  30. export function isComment(op) {
  31. return 'c' in op && op.c != null && 't' in op && op.t != null
  32. }