Skip to content

Commit e57b657

Browse files
committed
fix: static characters can also be optional
1 parent 1ce86ca commit e57b657

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/masker.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,21 @@ export function formatter(value, config) {
148148

149149
valueIndex++
150150
} else {
151-
accumulator += maskChar
152151
if (looselyStringMatch(char, maskChar)) {
153152
// user typed the same char as static mask char
153+
output.masked += accumulator + maskChar
154154
valueIndex++
155-
output.masked += accumulator
156155
accumulator = ''
156+
157+
if (meta.optional) {
158+
output.unmasked += maskChar
159+
}
160+
} else if (!meta.optional) {
161+
accumulator += maskChar
157162
}
158163

159164
escaped = false
160-
maskIndex++
165+
maskIndex += meta.optional ? 2 : 1
161166
}
162167
}
163168

0 commit comments

Comments
 (0)