@@ -28,6 +28,7 @@ type DefaultOptions = {
2828 | 'datetime-local'
2929 | 'time-local'
3030 | 'iso' ;
31+ delimiter ?: '.' | ',' ;
3132 empty ?: 'null' | 'undefined' ;
3233} ;
3334
@@ -72,7 +73,7 @@ export function numberProxy<
7273> (
7374 form : Writable < T > ,
7475 path : Path ,
75- options : Pick < DefaultOptions , 'empty' > = { }
76+ options : Pick < DefaultOptions , 'empty' | 'delimiter' > = { }
7677) {
7778 return _stringProxy ( form , path , 'number' , {
7879 ...defaultOptions ,
@@ -132,25 +133,29 @@ function _stringProxy<
132133 type : Type ,
133134 options : DefaultOptions
134135) : Writable < string > {
135- function toValue ( val : unknown ) {
136- if ( ! val && options . empty !== undefined )
136+ function toValue ( value : unknown ) {
137+ if ( ! value && options . empty !== undefined )
137138 return options . empty === 'null' ? null : undefined ;
138139
139- if ( typeof val === 'number' ) {
140- val = val . toString ( ) ;
140+ if ( typeof value === 'number' ) {
141+ value = value . toString ( ) ;
141142 }
142143
143- if ( typeof val !== 'string' ) {
144+ if ( typeof value !== 'string' ) {
144145 throw new SuperFormError ( 'stringProxy received a non-string value.' ) ;
145146 }
146147
147- if ( type == 'string' ) return val ;
148- else if ( type == 'boolean' ) return ! ! val ;
149- else if ( type == 'date' ) return new Date ( val ) ;
148+ if ( type == 'string' ) return value ;
149+ else if ( type == 'boolean' ) return ! ! value ;
150+ else if ( type == 'date' ) return new Date ( value ) ;
151+
152+ const numberToConvert = options . delimiter
153+ ? ( value as string ) . replace ( options . delimiter , '.' )
154+ : value ;
150155
151156 let num : number ;
152- if ( type == 'number' ) num = parseFloat ( val ) ;
153- else num = parseInt ( val , 10 ) ;
157+ if ( type == 'number' ) num = parseFloat ( numberToConvert ) ;
158+ else num = parseInt ( numberToConvert , 10 ) ;
154159
155160 if ( options . empty !== undefined && ( isNaN ( num ) || num == 0 ) )
156161 return options . empty == 'null' ? null : undefined ;
0 commit comments