Utils.js 743 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. */
  8. /**
  9. * Returns true if the op is an insert
  10. *
  11. * @param {Op} op
  12. * @returns {op is InsertOp}
  13. */
  14. function isInsert(op) {
  15. return 'i' in op && op.i != null
  16. }
  17. /**
  18. * Returns true if the op is an insert
  19. *
  20. * @param {Op} op
  21. * @returns {op is DeleteOp}
  22. */
  23. function isDelete(op) {
  24. return 'd' in op && op.d != null
  25. }
  26. /**
  27. * Returns true if the op is a comment
  28. *
  29. * @param {Op} op
  30. * @returns {op is CommentOp}
  31. */
  32. function isComment(op) {
  33. return 'c' in op && op.c != null
  34. }
  35. module.exports = { isInsert, isDelete, isComment }