Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed directive array mask #181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
.idea/
4 changes: 3 additions & 1 deletion src/dynamic-mask.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import isNextMask from "./is-next-mask";

export default function dynamicMask (maskit, masks, tokens) {
masks = masks.sort((a, b) => a.length - b.length)
return function (value, mask, masked = true) {
Expand All @@ -6,7 +8,7 @@ export default function dynamicMask (maskit, masks, tokens) {
var currentMask = masks[i]
i++
var nextMask = masks[i]
if (! (nextMask && maskit(value, nextMask, true, tokens).length > currentMask.length) ) {
if (! (nextMask && isNextMask(value, currentMask, nextMask, tokens, maskit)) ) {
return maskit(value, currentMask, masked, tokens)
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/is-next-mask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function isNextMask (value, currentMask, nextMask, tokens, maskit) {
const tokensArray = Object.keys(tokens)
const onlyTokenNextMask = nextMask?.split('').reduce((acc, el) => {
if (tokensArray.includes(el)) acc += el
return acc
}, '')
const countNextValue = maskit(value, onlyTokenNextMask, false, tokens).length
const countCurrentMask = currentMask?.split('').reduce((acc, el) => {
if (tokensArray.includes(el)) acc++
return acc
}, 0)
return countNextValue > countCurrentMask
}