Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
#11 Do nothing if no mask specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Lyashuk committed Dec 23, 2016
1 parent e65703f commit edefbd6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

function handler(_ref) {
var target = _ref.target;
var previousValue = target.dataset.previousValue;
var _target$dataset = target.dataset;
var previousValue = _target$dataset.previousValue;
var mask = _target$dataset.mask;

if (!mask) return;

if (typeof previousValue === 'string' && previousValue.length < target.value.length) {
target.value = (0, _format2.default)(target.value, target.dataset.mask);
target.value = (0, _format2.default)(target.value, mask);
}

target.dataset.previousValue = target.value;
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import format from './format.js';
* @param {HTMLInputElement} target
*/
function handler ({target}) {
let {previousValue} = target.dataset;
let {previousValue, mask} = target.dataset;

// do nothing if mask is not specified
if(!mask) return;

if (typeof previousValue === 'string' && previousValue.length < target.value.length) {
target.value = format(target.value, target.dataset.mask);
target.value = format(target.value, mask);
}

target.dataset.previousValue = target.value;
Expand Down

0 comments on commit edefbd6

Please sign in to comment.