import { Choices , ChoicesArray , ChoicesMap } from './types' ; export function choicesIsArray ( choices ) { return Array . isArray ( choices ) ; } export function choicesIsMap ( choices ) { return choices instanceof Map ; } export function getChoiceKeysFromChoices ( choices ) { if ( choicesIsArray ( choices ) ) { return choices . map ( o => String ( o ) ) ; } if ( choicesIsMap ( choices ) ) { return [ ... choices . keys ( ) ] . map ( o => String ( o ) ) ; } return Object . keys ( choices ) ; } export function getChoiceTextByKey ( choices , key ) { if ( choicesIsArray ( choices ) ) { return key ; } if ( choicesIsMap ( choices ) ) { return choices . get ( key ) ?? key ; } const choice = choices [ key ] ; if ( choice ) { return choice ; } return key ; } export function ensureCorrectChoiceKeys ( actionPrefix , path , choiceKeys ) { const containSlashExample = choiceKeys . find ( o => o . includes ( '/' ) ) ; if ( containSlashExample ) { throw new Error ( `Choices can not contain '/'. Found '${ containSlashExample }' in action '${ actionPrefix }' at path '${ path }'.` ) ; } }