check-bullet-other.js 895 B

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