File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
packages/angular_devkit/schematics_cli/bin Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,32 @@ function _createPromptProvider(): schema.PromptProvider {
7979 const validator = definition . validator ;
8080 if ( validator ) {
8181 question . validate = ( input ) => validator ( input ) ;
82+
83+ // Filter allows transformation of the value prior to validation
84+ question . filter = async ( input ) => {
85+ for ( const type of definition . propertyTypes ) {
86+ let value ;
87+ switch ( type ) {
88+ case 'string' :
89+ value = String ( input ) ;
90+ break ;
91+ case 'integer' :
92+ case 'number' :
93+ value = Number ( input ) ;
94+ break ;
95+ default :
96+ value = input ;
97+ break ;
98+ }
99+ // Can be a string if validation fails
100+ const isValid = ( await validator ( value ) ) === true ;
101+ if ( isValid ) {
102+ return value ;
103+ }
104+ }
105+
106+ return input ;
107+ } ;
82108 }
83109
84110 switch ( definition . type ) {
You can’t perform that action at this time.
0 commit comments