@@ -13,17 +13,14 @@ export const MASK_FLAGS = ['C', '&', 'a', 'A', '?', 'L', '9', '0', '#'];
13
13
} )
14
14
export class MaskParsingService {
15
15
private _cursor ;
16
- public get cursor ( ) {
17
- return this . _cursor ;
18
- }
19
16
20
17
public parseMask ( inputVal : string , maskOptions : any ) : string {
21
18
let outputVal = '' ;
22
19
let value = '' ;
23
20
const mask : string = maskOptions . format ;
24
21
const literals : Map < number , string > = this . getMaskLiterals ( mask ) ;
25
22
const literalKeys : number [ ] = Array . from ( literals . keys ( ) ) ;
26
- const nonLiteralIndeces : number [ ] = this . getNonLiteralIndices ( mask , literalKeys ) ;
23
+ const nonLiteralIndices : number [ ] = this . getNonLiteralIndices ( mask , literalKeys ) ;
27
24
const literalValues : string [ ] = Array . from ( literals . values ( ) ) ;
28
25
29
26
if ( inputVal != null ) {
@@ -46,21 +43,21 @@ export class MaskParsingService {
46
43
47
44
for ( let i = 0 ; i < nonLiteralValues . length ; i ++ ) {
48
45
const char = nonLiteralValues [ i ] ;
49
- const isCharValid = this . validateCharOnPosition ( char , nonLiteralIndeces [ i ] , mask ) ;
46
+ const isCharValid = this . validateCharOnPosition ( char , nonLiteralIndices [ i ] , mask ) ;
50
47
51
48
if ( ! isCharValid && char !== maskOptions . promptChar ) {
52
49
nonLiteralValues [ i ] = maskOptions . promptChar ;
53
50
}
54
51
}
55
52
56
- if ( nonLiteralValues . length > nonLiteralIndeces . length ) {
57
- nonLiteralValues . splice ( nonLiteralIndeces . length ) ;
53
+ if ( nonLiteralValues . length > nonLiteralIndices . length ) {
54
+ nonLiteralValues . splice ( nonLiteralIndices . length ) ;
58
55
}
59
56
60
57
let pos = 0 ;
61
58
for ( const nonLiteralValue of nonLiteralValues ) {
62
59
const char = nonLiteralValue ;
63
- outputVal = this . replaceCharAt ( outputVal , nonLiteralIndeces [ pos ++ ] , char ) ;
60
+ outputVal = this . replaceCharAt ( outputVal , nonLiteralIndices [ pos ++ ] , char ) ;
64
61
}
65
62
66
63
return outputVal ;
@@ -84,7 +81,7 @@ export class MaskParsingService {
84
81
}
85
82
86
83
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 } {
88
85
const mask : string = maskOptions . format ;
89
86
const literals : Map < number , string > = this . getMaskLiterals ( mask ) ;
90
87
const literalKeys : number [ ] = Array . from ( literals . keys ( ) ) ;
@@ -94,7 +91,7 @@ export class MaskParsingService {
94
91
if ( hasDeleteAction ) {
95
92
if ( inputText === '' ) {
96
93
this . _cursor = 0 ;
97
- return this . parseMask ( inputText , maskOptions ) ;
94
+ return { value : this . parseMask ( inputText , maskOptions ) , cursor : this . _cursor } ;
98
95
}
99
96
let i = 0 ;
100
97
this . _cursor = ++ cursor ;
@@ -106,7 +103,7 @@ export class MaskParsingService {
106
103
this . _cursor = cursor ;
107
104
for ( const char of rawData ) {
108
105
if ( this . _cursor > mask . length ) {
109
- return value ;
106
+ return { value : value , cursor : this . _cursor } ;
110
107
}
111
108
112
109
if ( nonLiteralIndices . indexOf ( this . _cursor ) !== - 1 ) {
@@ -142,7 +139,7 @@ export class MaskParsingService {
142
139
}
143
140
}
144
141
145
- return value ;
142
+ return { value : value , cursor : this . _cursor } ;
146
143
}
147
144
148
145
private updateValue ( nonLiteralIndices : number [ ] , value : string , cursor : number , maskOptions : any , mask : string ) {
@@ -156,7 +153,7 @@ export class MaskParsingService {
156
153
const letterOrDigitRegEx = '[\\d\\u00C0-\\u1FFF\\u2C00-\\uD7FFa-zA-Z]' ;
157
154
const letterDigitOrSpaceRegEx = '[\\d\\u00C0-\\u1FFF\\u2C00-\\uD7FFa-zA-Z\\u0020]' ;
158
155
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]' ;
160
157
const digitRegEx = '[\\d]' ;
161
158
const digitSpaceRegEx = '[\\d\\u0020]' ;
162
159
const digitSpecialRegEx = '[\\d-\\+]' ;
@@ -178,7 +175,7 @@ export class MaskParsingService {
178
175
isValid = regex . test ( inputChar ) ;
179
176
break ;
180
177
case '?' :
181
- regex = new RegExp ( letteSpaceRegEx ) ;
178
+ regex = new RegExp ( letterSpaceRegEx ) ;
182
179
isValid = regex . test ( inputChar ) ;
183
180
break ;
184
181
case 'L' :
@@ -227,15 +224,15 @@ export class MaskParsingService {
227
224
return literals ;
228
225
}
229
226
private getNonLiteralIndices ( mask : string , literalKeys : number [ ] ) : number [ ] {
230
- const nonLiteralsIndeces : number [ ] = new Array ( ) ;
227
+ const nonLiteralsIndices : number [ ] = new Array ( ) ;
231
228
232
229
for ( let i = 0 ; i < mask . length ; i ++ ) {
233
230
if ( literalKeys . indexOf ( i ) === - 1 ) {
234
- nonLiteralsIndeces . push ( i ) ;
231
+ nonLiteralsIndices . push ( i ) ;
235
232
}
236
233
}
237
234
238
- return nonLiteralsIndeces ;
235
+ return nonLiteralsIndices ;
239
236
}
240
237
private getNonLiteralValues ( value : string , literalValues : string [ ] ) : string [ ] {
241
238
const nonLiteralValues : string [ ] = new Array ( ) ;
0 commit comments