Skip to content

Commit

Permalink
Adding tinymask to fix some custom mask issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-hur Santos Ott committed May 23, 2017
1 parent 249c042 commit e604d61
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 38 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ var money = MaskService.toMask('money', '123', {


# Changelog

## 1.5.1
* Adding `tinymask` to fix some custom mask issues.

## 1.5.0
* Adding new and powerfull `custom` engine mask \m/.

Expand Down
39 changes: 3 additions & 36 deletions lib/masks/custom.mask.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import TinyMask from 'tinymask';
import BaseMask from './_base.mask';

const DEFAULT_TRANSLATION = {
Expand Down Expand Up @@ -30,42 +31,8 @@ export default class CustomMask extends BaseMask {
let { mask } = settings;
let translation = this.mergeSettings(DEFAULT_TRANSLATION, settings.translation);

var result = '';

const maskSize = mask.length;
const valueSize = value.length;

var maskResolved = 0;
var valueResolved = 0;

while (maskResolved < maskSize && valueResolved < valueSize) {
const valueChar = value[valueResolved];
const maskChar = mask[maskResolved];

if (valueChar === maskChar) {
result += valueChar;
maskResolved++;
valueResolved++;
continue;
}

const handler = translation[maskChar];

if (!handler) {
result += maskChar;
maskResolved++;
continue;
}

var masked = handler(valueChar);
if (invalidValues.indexOf(masked) < 0) {
result += masked
maskResolved++
}
valueResolved++
}

return result;
var masked = new TinyMask(mask, { translation }).mask(value);
return masked;
}

getRawValue(maskedValue, settings) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-masked-text",
"version": "1.5.0",
"version": "1.5.1",
"description": "Text and TextInput with mask for React Native applications",
"main": "index.js",
"scripts": {
Expand All @@ -23,7 +23,8 @@
},
"homepage": "https://github.com/benhurott/react-native-masked-text#readme",
"dependencies": {
"moment": "^2.18.1"
"moment": "^2.18.1",
"tinymask": "^1.0.2"
},
"devDependencies": {
"babel-preset-react-native": "^1.9.1",
Expand Down

0 comments on commit e604d61

Please sign in to comment.