kjelsrud.dev/node_modules/mdast-util-to-markdown/lib/util/check-bullet-ordered-other.js

40 lines
1,020 B
JavaScript
Raw Normal View History

2023-07-19 21:31:30 +02:00
/**
* @typedef {import('../types.js').State} State
* @typedef {import('../types.js').Options} Options
*/
import {checkBulletOrdered} from './check-bullet-ordered.js'
/**
* @param {State} state
* @returns {Exclude<Options['bulletOrdered'], null | undefined>}
*/
export function checkBulletOrderedOther(state) {
const bulletOrdered = checkBulletOrdered(state)
const bulletOrderedOther = state.options.bulletOrderedOther
if (!bulletOrderedOther) {
return bulletOrdered === '.' ? ')' : '.'
}
if (bulletOrderedOther !== '.' && bulletOrderedOther !== ')') {
throw new Error(
'Cannot serialize items with `' +
bulletOrderedOther +
'` for `options.bulletOrderedOther`, expected `*`, `+`, or `-`'
)
}
if (bulletOrderedOther === bulletOrdered) {
throw new Error(
'Expected `bulletOrdered` (`' +
bulletOrdered +
'`) and `bulletOrderedOther` (`' +
bulletOrderedOther +
'`) to be different'
)
}
return bulletOrderedOther
}