import { Answers , DistinctQuestion } from 'inquirer' ; import * as colors from './colors' ; export const compose = ( ... fns ) : QuestionFormatter => { return question => fns . reduceRight ( ( formatters , fn ) => fn ( formatters ) , question ) ; } ; export type QuestionFormatter < T extends Answers = Answers > = ( question : DistinctQuestion < T > ) => DistinctQuestion < T > ; param { string } tag returns { QuestionFormatter } example export const tagPrefix = ( tag ) : QuestionFormatter => { return question => { return { ... question , prefix : `[${ tag }]${ question . prefix || '' }` } ; } ; } ; param { DistinctQuestion } question returns { QuestionFormatter } example export const newLineSuffix = question => { let suffix = question . suffix || '\n' ; if ( ! suffix . startsWith ( '\n' ) ) { suffix = '\n' + suffix ; } if ( ! suffix . endsWith ( '\n' ) ) { suffix = suffix + '\n' ; } return { ... question , suffix } ; } ; export const required = tagPrefix ( colors . required ( 'Required' ) ) ; export const android = tagPrefix ( colors . android ( 'Android' ) ) ; export const ios = tagPrefix ( colors . ios ( 'iOS' ) ) ;