@@ -13,17 +13,14 @@ export const MASK_FLAGS = ['C', '&', 'a', 'A', '?', 'L', '9', '0', '#'];
1313} )
1414export class MaskParsingService {
1515 private _cursor ;
16- public get cursor ( ) {
17- return this . _cursor ;
18- }
1916
2017 public parseMask ( inputVal : string , maskOptions : any ) : string {
2118 let outputVal = '' ;
2219 let value = '' ;
2320 const mask : string = maskOptions . format ;
2421 const literals : Map < number , string > = this . getMaskLiterals ( mask ) ;
2522 const literalKeys : number [ ] = Array . from ( literals . keys ( ) ) ;
26- const nonLiteralIndeces : number [ ] = this . getNonLiteralIndices ( mask , literalKeys ) ;
23+ const nonLiteralIndices : number [ ] = this . getNonLiteralIndices ( mask , literalKeys ) ;
2724 const literalValues : string [ ] = Array . from ( literals . values ( ) ) ;
2825
2926 if ( inputVal != null ) {
@@ -46,21 +43,21 @@ export class MaskParsingService {
4643
4744 for ( let i = 0 ; i < nonLiteralValues . length ; i ++ ) {
4845 const char = nonLiteralValues [ i ] ;
49- const isCharValid = this . validateCharOnPosition ( char , nonLiteralIndeces [ i ] , mask ) ;
46+ const isCharValid = this . validateCharOnPosition ( char , nonLiteralIndices [ i ] , mask ) ;
5047
5148 if ( ! isCharValid && char !== maskOptions . promptChar ) {
5249 nonLiteralValues [ i ] = maskOptions . promptChar ;
5350 }
5451 }
5552
56- if ( nonLiteralValues . length > nonLiteralIndeces . length ) {
57- nonLiteralValues . splice ( nonLiteralIndeces . length ) ;
53+ if ( nonLiteralValues . length > nonLiteralIndices . length ) {
54+ nonLiteralValues . splice ( nonLiteralIndices . length ) ;
5855 }
5956
6057 let pos = 0 ;
6158 for ( const nonLiteralValue of nonLiteralValues ) {
6259 const char = nonLiteralValue ;
63- outputVal = this . replaceCharAt ( outputVal , nonLiteralIndeces [ pos ++ ] , char ) ;
60+ outputVal = this . replaceCharAt ( outputVal , nonLiteralIndices [ pos ++ ] , char ) ;
6461 }
6562
6663 return outputVal ;
@@ -84,7 +81,7 @@ export class MaskParsingService {
8481 }
8582
8683 public parseMaskValue ( value : string , inputText : string , maskOptions : any ,
87- cursor : number , rawData : string , selection : number , hasDeleteAction : boolean ) : string {
84+ cursor : number , rawData : string , selection : number , hasDeleteAction : boolean ) : { value : string , cursor : number } {
8885 const mask : string = maskOptions . format ;
8986 const literals : Map < number , string > = this . getMaskLiterals ( mask ) ;
9087 const literalKeys : number [ ] = Array . from ( literals . keys ( ) ) ;
@@ -94,7 +91,7 @@ export class MaskParsingService {
9491 if ( hasDeleteAction ) {
9592 if ( inputText === '' ) {
9693 this . _cursor = 0 ;
97- return this . parseMask ( inputText , maskOptions ) ;
94+ return { value : this . parseMask ( inputText , maskOptions ) , cursor : this . _cursor } ;
9895 }
9996 let i = 0 ;
10097 this . _cursor = ++ cursor ;
@@ -106,7 +103,7 @@ export class MaskParsingService {
106103 this . _cursor = cursor ;
107104 for ( const char of rawData ) {
108105 if ( this . _cursor > mask . length ) {
109- return value ;
106+ return { value : value , cursor : this . _cursor } ;
110107 }
111108
112109 if ( nonLiteralIndices . indexOf ( this . _cursor ) !== - 1 ) {
@@ -142,7 +139,7 @@ export class MaskParsingService {
142139 }
143140 }
144141
145- return value ;
142+ return { value : value , cursor : this . _cursor } ;
146143 }
147144
148145 private updateValue ( nonLiteralIndices : number [ ] , value : string , cursor : number , maskOptions : any , mask : string ) {
@@ -156,7 +153,7 @@ export class MaskParsingService {
156153 const letterOrDigitRegEx = '[\\d\\u00C0-\\u1FFF\\u2C00-\\uD7FFa-zA-Z]' ;
157154 const letterDigitOrSpaceRegEx = '[\\d\\u00C0-\\u1FFF\\u2C00-\\uD7FFa-zA-Z\\u0020]' ;
158155 const letterRegEx = '[\\u00C0-\\u1FFF\\u2C00-\\uD7FFa-zA-Z]' ;
159- const letteSpaceRegEx = '[\\u00C0-\\u1FFF\\u2C00-\\uD7FFa-zA-Z\\u0020]' ;
156+ const letterSpaceRegEx = '[\\u00C0-\\u1FFF\\u2C00-\\uD7FFa-zA-Z\\u0020]' ;
160157 const digitRegEx = '[\\d]' ;
161158 const digitSpaceRegEx = '[\\d\\u0020]' ;
162159 const digitSpecialRegEx = '[\\d-\\+]' ;
@@ -178,7 +175,7 @@ export class MaskParsingService {
178175 isValid = regex . test ( inputChar ) ;
179176 break ;
180177 case '?' :
181- regex = new RegExp ( letteSpaceRegEx ) ;
178+ regex = new RegExp ( letterSpaceRegEx ) ;
182179 isValid = regex . test ( inputChar ) ;
183180 break ;
184181 case 'L' :
@@ -227,15 +224,15 @@ export class MaskParsingService {
227224 return literals ;
228225 }
229226 private getNonLiteralIndices ( mask : string , literalKeys : number [ ] ) : number [ ] {
230- const nonLiteralsIndeces : number [ ] = new Array ( ) ;
227+ const nonLiteralsIndices : number [ ] = new Array ( ) ;
231228
232229 for ( let i = 0 ; i < mask . length ; i ++ ) {
233230 if ( literalKeys . indexOf ( i ) === - 1 ) {
234- nonLiteralsIndeces . push ( i ) ;
231+ nonLiteralsIndices . push ( i ) ;
235232 }
236233 }
237234
238- return nonLiteralsIndeces ;
235+ return nonLiteralsIndices ;
239236 }
240237 private getNonLiteralValues ( value : string , literalValues : string [ ] ) : string [ ] {
241238 const nonLiteralValues : string [ ] = new Array ( ) ;
0 commit comments