Skip to content

Commit

Permalink
Merge pull request #130 from benhurott/1.11.1
Browse files Browse the repository at this point in the history
1.11.1
  • Loading branch information
Ben-hur Santos Ott authored Mar 5, 2019
2 parents a8403bd + b833232 commit 5556de5
Show file tree
Hide file tree
Showing 6 changed files with 9,649 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Unreleased

## [1.11.1] - 2019-03-05

### Fixed

- Remove characters in the middle of the mask (Thanks to [rsouthgate](https://github.com/rsouthgate) for the great contribution!)
- Fixes [#128](https://github.com/benhurott/react-native-masked-text/issues/128) and [#35](https://github.com/benhurott/react-native-masked-text/issues/35)

## [1.11.0] - 2019-02-23

### Added
Expand Down
12 changes: 6 additions & 6 deletions __tests__/mask/custom.mask.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ test('123 with mask 999 results 123 and raw value 123(type Number)', () => {
var mask = new CustomMask()
var options = {
mask: '999',
getRawValue: function(maskedValue, settings) {
getRawValue: function (maskedValue, settings) {
return Number(maskedValue)
}
}
Expand All @@ -137,7 +137,7 @@ test('mask with custom translation and match', () => {
var options = {
mask: '999&AAA',
translation: {
'&': function(val) {
'&': function (val) {
return ['#', '.', ':'].indexOf(val) >= 0 ? val : null
}
}
Expand All @@ -154,13 +154,13 @@ test('mask with custom translation and not match', () => {
var options = {
mask: '999&AAA',
translation: {
'&': function(val) {
return ['#', '.', ':'].indexOf(val) >= 0 ? val : ''
'&': function (val) {
return ['#', '.', ':'].indexOf(val) >= 0 ? val : '#'
}
}
}

var expected = '123ABC'
var expected = '123#ABC'
var received = mask.getValue('123|ABC', options)

expect(received).toBe(expected)
Expand All @@ -171,7 +171,7 @@ test('mask with custom translation and optionals and matching', () => {
var options = {
mask: '999***AAA&',
translation: {
'&': function(val) {
'&': function (val) {
return ['#', '.', ':'].indexOf(val) >= 0 ? val : null
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/lib/masks/custom.mask.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions lib/masks/custom.mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import BaseMask from './_base.mask'

function getDefaultTranslation() {
return {
'9': function(val) {
'9': function (val) {
return val.replace(/[^0-9]+/g, '')
},
A: function(val) {
A: function (val) {
return val.replace(/[^a-zA-Z]+/g, '')
},
S: function(val) {
S: function (val) {
return val.replace(/[^a-zA-Z0-9]+/g, '')
},
'*': function(val) {
'*': function (val) {
return val
}
}
Expand Down Expand Up @@ -50,14 +50,16 @@ function toPattern(value, mask, translation) {

if (translationHandler) {
const resolverValue = translationHandler(valueChar || '')

if (resolverValue !== null) {
result += resolverValue
valueCharIndex += 1
if (resolverValue === '') {
//valueChar replaced so don't add it to result, keep the mask at the same point and continue to next value char
valueCharIndex += 1;
continue;
} else if (resolverValue !== null) {
result += resolverValue;
valueCharIndex += 1;
} else {
result += maskChar
result += maskChar;
}

maskCharIndex += 1
continue
}
Expand Down
Loading

0 comments on commit 5556de5

Please sign in to comment.