File tree 1 file changed +26
-0
lines changed
packages/angular_devkit/schematics_cli/bin
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 {
79
79
const validator = definition . validator ;
80
80
if ( validator ) {
81
81
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
+ } ;
82
108
}
83
109
84
110
switch ( definition . type ) {
You can’t perform that action at this time.
0 commit comments