Utils.js 789 B

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