check-bullet-other.js 853 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * @import {Options, State} from 'mdast-util-to-markdown'
  3. */
  4. import {checkBullet} from './check-bullet.js'
  5. /**
  6. * @param {State} state
  7. * @returns {Exclude<Options['bullet'], null | undefined>}
  8. */
  9. export function checkBulletOther(state) {
  10. const bullet = checkBullet(state)
  11. const bulletOther = state.options.bulletOther
  12. if (!bulletOther) {
  13. return bullet === '*' ? '-' : '*'
  14. }
  15. if (bulletOther !== '*' && bulletOther !== '+' && bulletOther !== '-') {
  16. throw new Error(
  17. 'Cannot serialize items with `' +
  18. bulletOther +
  19. '` for `options.bulletOther`, expected `*`, `+`, or `-`'
  20. )
  21. }
  22. if (bulletOther === bullet) {
  23. throw new Error(
  24. 'Expected `bullet` (`' +
  25. bullet +
  26. '`) and `bulletOther` (`' +
  27. bulletOther +
  28. '`) to be different'
  29. )
  30. }
  31. return bulletOther
  32. }