angular-input-masks
Version:
Personalized input masks for AngularJS
963 lines (752 loc) • 26.7 kB
JavaScript
/**
* angular-input-masks
* Personalized input masks for AngularJS
* @version v4.2.1
* @link http://github.com/assisrafael/angular-input-masks
* @license MIT
*/
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
;
module.exports = angular.module('ui.utils.masks', [
require('./global/global-masks'),
require('./fr/fr-masks')
]).name;
},{"./fr/fr-masks":2,"./global/global-masks":6}],2:[function(require,module,exports){
;
var m = angular.module('ui.utils.masks.fr', [])
.directive('uiFrPhoneNumberMask', require('./phone/fr-phone'));
module.exports = m.name;
},{"./phone/fr-phone":3}],3:[function(require,module,exports){
;
var StringMask = require('string-mask');
var maskFactory = require('../../helpers/mask-factory');
var phoneMaskFR = new StringMask('00 00 00 00 00');
module.exports = maskFactory({
clearValue: function(rawValue) {
return rawValue.toString().replace(/[^0-9]/g, '').slice(0, 10);
},
format: function(cleanValue) {
var formattedValue;
formattedValue = phoneMaskFR.apply(cleanValue) || '';
return formattedValue.trim().replace(/[^0-9]$/, '');
},
validations: {
frPhoneNumber: function(value) {
var valueLength = value && value.toString().length;
return valueLength === 10;
}
}
});
},{"../../helpers/mask-factory":12,"string-mask":undefined}],4:[function(require,module,exports){
;
var StringMask = require('string-mask');
var maskFactory = require('../../helpers/mask-factory');
var ccSize = 16;
var ccMask = new StringMask('0000 0000 0000 0000');
module.exports = maskFactory({
clearValue: function(rawValue) {
return rawValue.toString().replace(/[^0-9]/g, '').slice(0, ccSize);
},
format: function(cleanValue) {
var formatedValue;
formatedValue = ccMask.apply(cleanValue) || '';
return formatedValue.trim().replace(/[^0-9]$/, '');
},
validations: {
creditCard: function(value) {
var valueLength = value && value.toString().length;
return valueLength === ccSize;
}
}
});
},{"../../helpers/mask-factory":12,"string-mask":undefined}],5:[function(require,module,exports){
;
var formatDate = require('date-fns/format');
var parseDate = require('date-fns/parse');
var isValidDate = require('date-fns/isValid');
var StringMask = require('string-mask');
function isISODateString(date) {
return /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}([-+][0-9]{2}:[0-9]{2}|Z)$/
.test(date.toString());
}
var dateFormatMapByLocale = {
'pt-br': 'DD/MM/YYYY',
'es-ar': 'DD/MM/YYYY',
'es-mx': 'DD/MM/YYYY',
'es' : 'DD/MM/YYYY',
'en-us': 'MM/DD/YYYY',
'en' : 'MM/DD/YYYY',
'fr-fr': 'DD/MM/YYYY',
'fr' : 'DD/MM/YYYY',
'ru' : 'DD.MM.YYYY'
};
function DateMaskDirective($locale) {
var dateFormat = dateFormatMapByLocale[$locale.id] || 'YYYY-MM-DD';
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
attrs.parse = attrs.parse || 'true';
dateFormat = attrs.uiDateMask || dateFormat;
var dateMask = new StringMask(dateFormat.replace(/[YMD]/g,'0'));
function formatter(value) {
if (ctrl.$isEmpty(value)) {
return null;
}
var cleanValue = value;
if (typeof value === 'object' || isISODateString(value)) {
cleanValue = formatDate(value, dateFormat);
}
cleanValue = cleanValue.replace(/[^0-9]/g, '');
var formatedValue = dateMask.apply(cleanValue) || '';
return formatedValue.trim().replace(/[^0-9]$/, '');
}
ctrl.$formatters.push(formatter);
ctrl.$parsers.push(function parser(value) {
if (ctrl.$isEmpty(value)) {
return value;
}
var formatedValue = formatter(value);
if (ctrl.$viewValue !== formatedValue) {
ctrl.$setViewValue(formatedValue);
ctrl.$render();
}
return attrs.parse === 'false'
? formatedValue
: parseDate(formatedValue, dateFormat, new Date());
});
ctrl.$validators.date = function validator(modelValue, viewValue) {
if (ctrl.$isEmpty(modelValue)) {
return true;
}
return isValidDate(parseDate(viewValue, dateFormat, new Date())) && viewValue.length === dateFormat.length;
};
}
};
}
DateMaskDirective.$inject = ['$locale'];
module.exports = DateMaskDirective;
},{"date-fns/format":undefined,"date-fns/isValid":undefined,"date-fns/parse":undefined,"string-mask":undefined}],6:[function(require,module,exports){
;
var m = angular.module('ui.utils.masks.global', [])
.directive('uiCreditCardMask', require('./credit-card/credit-card'))
.directive('uiDateMask', require('./date/date'))
.directive('uiMoneyMask', require('./money/money'))
.directive('uiNumberMask', require('./number/number'))
.directive('uiPercentageMask', require('./percentage/percentage'))
.directive('uiScientificNotationMask', require('./scientific-notation/scientific-notation'))
.directive('uiTimeMask', require('./time/time'));
module.exports = m.name;
},{"./credit-card/credit-card":4,"./date/date":5,"./money/money":7,"./number/number":8,"./percentage/percentage":9,"./scientific-notation/scientific-notation":10,"./time/time":11}],7:[function(require,module,exports){
;
var StringMask = require('string-mask');
var validators = require('../../helpers/validators');
var PreFormatters = require('../../helpers/pre-formatters');
function MoneyMaskDirective($locale, $parse) {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
var decimalDelimiter = $locale.NUMBER_FORMATS.DECIMAL_SEP,
thousandsDelimiter = $locale.NUMBER_FORMATS.GROUP_SEP,
currencySym = $locale.NUMBER_FORMATS.CURRENCY_SYM,
symbolSeparation = ' ',
decimals = $parse(attrs.uiMoneyMask)(scope),
backspacePressed = false;
element.bind('keydown keypress', function(event) {
backspacePressed = event.which === 8;
});
function maskFactory(decimals) {
var decimalsPattern = decimals > 0 ? decimalDelimiter + new Array(decimals + 1).join('0') : '';
var maskPattern = '#' + thousandsDelimiter + '##0' + decimalsPattern;
if (angular.isDefined(attrs.uiCurrencyAfter)) {
maskPattern += symbolSeparation;
} else {
maskPattern = symbolSeparation + maskPattern;
}
return new StringMask(maskPattern, {reverse: true});
}
if (angular.isDefined(attrs.uiDecimalDelimiter)) {
decimalDelimiter = attrs.uiDecimalDelimiter;
}
if (angular.isDefined(attrs.uiThousandsDelimiter)) {
thousandsDelimiter = attrs.uiThousandsDelimiter;
}
if (angular.isDefined(attrs.uiHideGroupSep)) {
thousandsDelimiter = '';
}
if (angular.isDefined(attrs.uiHideSpace)) {
symbolSeparation = '';
}
if (angular.isDefined(attrs.currencySymbol)) {
currencySym = attrs.currencySymbol;
if (attrs.currencySymbol.length === 0) {
symbolSeparation = '';
}
}
if (isNaN(decimals)) {
decimals = 2;
}
decimals = parseInt(decimals);
var moneyMask = maskFactory(decimals);
function formatter(value) {
if (ctrl.$isEmpty(value)) {
return '';
}
if (angular.isDefined(attrs.uiIntegerModel)) {
value /= Math.pow(10, decimals);
}
var prefix = (angular.isDefined(attrs.uiNegativeNumber) && value < 0) ? '-' : '';
var valueToFormat = PreFormatters.prepareNumberToFormatter(value, decimals);
if (angular.isDefined(attrs.uiCurrencyAfter)) {
return prefix + moneyMask.apply(valueToFormat) + currencySym;
}
return prefix + currencySym + moneyMask.apply(valueToFormat);
}
function parser(value) {
if (ctrl.$isEmpty(value)) {
return null;
}
var actualNumber = value.replace(/[^\d]+/g,''), formatedValue;
actualNumber = actualNumber.replace(/^[0]+([1-9])/,'$1');
actualNumber = actualNumber || '0';
if (backspacePressed && angular.isDefined(attrs.uiCurrencyAfter) && actualNumber !== 0) {
actualNumber = actualNumber.substring(0, actualNumber.length - 1);
backspacePressed = false;
}
if (angular.isDefined(attrs.uiCurrencyAfter)) {
formatedValue = moneyMask.apply(actualNumber) + currencySym;
} else {
formatedValue = currencySym + moneyMask.apply(actualNumber);
}
if (angular.isDefined(attrs.uiNegativeNumber)) {
var isNegative = (value[0] === '-'),
needsToInvertSign = (value.slice(-1) === '-');
//only apply the minus sign if it is negative or(exclusive)
//needs to be negative and the number is different from zero
if (needsToInvertSign ^ isNegative && !!actualNumber) {
actualNumber *= -1;
formatedValue = '-' + formatedValue;
}
}
if (value !== formatedValue) {
ctrl.$setViewValue(formatedValue);
ctrl.$render();
}
var retValue = parseInt(formatedValue.replace(/[^\d\-]+/g,''));
if (!isNaN(retValue)) {
if (!angular.isDefined(attrs.uiIntegerModel)) {
retValue /= Math.pow(10, decimals);
}
return retValue;
}
return null;
}
ctrl.$formatters.push(formatter);
ctrl.$parsers.push(parser);
if (attrs.uiMoneyMask) {
scope.$watch(attrs.uiMoneyMask, function(_decimals) {
decimals = isNaN(_decimals) ? 2 : _decimals;
decimals = parseInt(decimals);
moneyMask = maskFactory(decimals);
parser(ctrl.$viewValue);
});
}
if (attrs.currency) {
scope.$watch(attrs.currency, function(_currency) {
currencySym = _currency;
moneyMask = maskFactory(decimals);
parser(ctrl.$viewValue);
});
}
if (attrs.min) {
var minVal;
ctrl.$validators.min = function(modelValue) {
return validators.minNumber(ctrl, modelValue, minVal);
};
scope.$watch(attrs.min, function(value) {
minVal = value;
ctrl.$validate();
});
}
if (attrs.max) {
var maxVal;
ctrl.$validators.max = function(modelValue) {
return validators.maxNumber(ctrl, modelValue, maxVal);
};
scope.$watch(attrs.max, function(value) {
maxVal = value;
ctrl.$validate();
});
}
}
};
}
MoneyMaskDirective.$inject = ['$locale', '$parse'];
module.exports = MoneyMaskDirective;
},{"../../helpers/pre-formatters":14,"../../helpers/validators":15,"string-mask":undefined}],8:[function(require,module,exports){
;
var validators = require('../../helpers/validators');
var NumberMasks = require('../../helpers/number-mask-builder');
var PreFormatters = require('../../helpers/pre-formatters');
function NumberMaskDirective($locale, $parse) {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
var decimalDelimiter = $locale.NUMBER_FORMATS.DECIMAL_SEP,
thousandsDelimiter = $locale.NUMBER_FORMATS.GROUP_SEP,
decimals = $parse(attrs.uiNumberMask)(scope);
if (angular.isDefined(attrs.uiHideGroupSep)) {
thousandsDelimiter = '';
}
if (isNaN(decimals)) {
decimals = 2;
}
var viewMask = NumberMasks.viewMask(decimals, decimalDelimiter, thousandsDelimiter),
modelMask = NumberMasks.modelMask(decimals);
function parser(value) {
if (ctrl.$isEmpty(value)) {
return null;
}
var valueToFormat = PreFormatters.clearDelimitersAndLeadingZeros(value) || '0';
var formatedValue = viewMask.apply(valueToFormat);
var actualNumber = parseFloat(modelMask.apply(valueToFormat));
if (angular.isDefined(attrs.uiNegativeNumber)) {
var isNegative = (value[0] === '-'),
needsToInvertSign = (value.slice(-1) === '-');
//only apply the minus sign if it is negative or(exclusive) or the first character
//needs to be negative and the number is different from zero
if ((needsToInvertSign ^ isNegative) || value === '-') {
actualNumber *= -1;
formatedValue = '-' + ((actualNumber !== 0) ? formatedValue : '');
}
}
if (ctrl.$viewValue !== formatedValue) {
ctrl.$setViewValue(formatedValue);
ctrl.$render();
}
return actualNumber;
}
function formatter(value) {
if (ctrl.$isEmpty(value)) {
return value;
}
var prefix = (angular.isDefined(attrs.uiNegativeNumber) && value < 0) ? '-' : '';
var valueToFormat = PreFormatters.prepareNumberToFormatter(value, decimals);
return prefix + viewMask.apply(valueToFormat);
}
function clearViewValueIfMinusSign() {
if (ctrl.$viewValue === '-') {
ctrl.$setViewValue('');
ctrl.$render();
}
}
element.on('blur', clearViewValueIfMinusSign);
ctrl.$formatters.push(formatter);
ctrl.$parsers.push(parser);
if (attrs.uiNumberMask) {
scope.$watch(attrs.uiNumberMask, function(_decimals) {
decimals = isNaN(_decimals) ? 2 : _decimals;
viewMask = NumberMasks.viewMask(decimals, decimalDelimiter, thousandsDelimiter);
modelMask = NumberMasks.modelMask(decimals);
parser(ctrl.$viewValue);
});
}
if (attrs.min) {
var minVal;
ctrl.$validators.min = function(modelValue) {
return validators.minNumber(ctrl, modelValue, minVal);
};
scope.$watch(attrs.min, function(value) {
minVal = value;
ctrl.$validate();
});
}
if (attrs.max) {
var maxVal;
ctrl.$validators.max = function(modelValue) {
return validators.maxNumber(ctrl, modelValue, maxVal);
};
scope.$watch(attrs.max, function(value) {
maxVal = value;
ctrl.$validate();
});
}
}
};
}
NumberMaskDirective.$inject = ['$locale', '$parse'];
module.exports = NumberMaskDirective;
},{"../../helpers/number-mask-builder":13,"../../helpers/pre-formatters":14,"../../helpers/validators":15}],9:[function(require,module,exports){
;
var validators = require('../../helpers/validators');
var NumberMasks = require('../../helpers/number-mask-builder');
var PreFormatters = require('../../helpers/pre-formatters');
function preparePercentageToFormatter(value, decimals, modelMultiplier) {
return PreFormatters.clearDelimitersAndLeadingZeros((parseFloat(value)*modelMultiplier).toFixed(decimals));
}
function PercentageMaskDirective($locale) {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
var decimalDelimiter = $locale.NUMBER_FORMATS.DECIMAL_SEP;
var backspacePressed = false;
element.bind('keydown keypress', function(event) {
backspacePressed = event.which === 8;
});
var thousandsDelimiter = $locale.NUMBER_FORMATS.GROUP_SEP;
if (angular.isDefined(attrs.uiHideGroupSep)) {
thousandsDelimiter = '';
}
var percentageSymbol = ' %';
if (angular.isDefined(attrs.uiHidePercentageSign)) {
percentageSymbol = '';
} else if (angular.isDefined(attrs.uiHideSpace)) {
percentageSymbol = '%';
}
var decimals = parseInt(attrs.uiPercentageMask);
if (isNaN(decimals)) {
decimals = 2;
}
var modelValue = {
multiplier : 100,
decimalMask: 2
};
if (angular.isDefined(attrs.uiPercentageValue)) {
modelValue.multiplier = 1;
modelValue.decimalMask = 0;
}
var numberDecimals = decimals + modelValue.decimalMask;
var viewMask = NumberMasks.viewMask(decimals, decimalDelimiter, thousandsDelimiter),
modelMask = NumberMasks.modelMask(numberDecimals);
function formatter(value) {
if (ctrl.$isEmpty(value)) {
return value;
}
var prefix = (angular.isDefined(attrs.uiNegativeNumber) && value < 0) ? '-' : '';
var valueToFormat = preparePercentageToFormatter(value, decimals, modelValue.multiplier);
var formatedValue = prefix + viewMask.apply(valueToFormat) + percentageSymbol;
return formatedValue;
}
function parser(value) {
if (ctrl.$isEmpty(value)) {
return null;
}
var valueToFormat = PreFormatters.clearDelimitersAndLeadingZeros(value) || '0';
if (percentageSymbol !== '' && value.length > 1 && value.indexOf('%') === -1) {
valueToFormat = valueToFormat.slice(0, valueToFormat.length - 1);
}
if (backspacePressed && value.length === 1 && value !== '%') {
valueToFormat = '0';
}
var formatedValue = viewMask.apply(valueToFormat) + percentageSymbol;
var actualNumber = parseFloat(modelMask.apply(valueToFormat));
if (angular.isDefined(attrs.uiNegativeNumber)) {
var isNegative = (value[0] === '-'),
needsToInvertSign = (value.slice(-1) === '-');
//only apply the minus sign if it is negative or(exclusive) or the first character
//needs to be negative and the number is different from zero
if ((needsToInvertSign ^ isNegative) || value === '-') {
actualNumber *= -1;
formatedValue = '-' + ((actualNumber !== 0) ? formatedValue : '');
}
}
if (ctrl.$viewValue !== formatedValue) {
ctrl.$setViewValue(formatedValue);
ctrl.$render();
}
return actualNumber;
}
ctrl.$formatters.push(formatter);
ctrl.$parsers.push(parser);
if (attrs.uiPercentageMask) {
scope.$watch(attrs.uiPercentageMask, function(_decimals) {
decimals = isNaN(_decimals) ? 2 : _decimals;
numberDecimals = decimals + modelValue.decimalMask;
viewMask = NumberMasks.viewMask(decimals, decimalDelimiter, thousandsDelimiter);
modelMask = NumberMasks.modelMask(numberDecimals);
parser(formatter(ctrl.$modelValue));
});
}
if (attrs.min) {
var minVal;
ctrl.$validators.min = function(modelValue) {
return validators.minNumber(ctrl, modelValue, minVal);
};
scope.$watch(attrs.min, function(value) {
minVal = value;
ctrl.$validate();
});
}
if (attrs.max) {
var maxVal;
ctrl.$validators.max = function(modelValue) {
return validators.maxNumber(ctrl, modelValue, maxVal);
};
scope.$watch(attrs.max, function(value) {
maxVal = value;
ctrl.$validate();
});
}
}
};
}
PercentageMaskDirective.$inject = ['$locale'];
module.exports = PercentageMaskDirective;
},{"../../helpers/number-mask-builder":13,"../../helpers/pre-formatters":14,"../../helpers/validators":15}],10:[function(require,module,exports){
;
var StringMask = require('string-mask');
function ScientificNotationMaskDirective($locale, $parse) {
var decimalDelimiter = $locale.NUMBER_FORMATS.DECIMAL_SEP,
defaultPrecision = 2;
function significandMaskBuilder(decimals) {
var mask = '0';
if (decimals > 0) {
mask += decimalDelimiter;
for (var i = 0; i < decimals; i++) {
mask += '0';
}
}
return new StringMask(mask, {
reverse: true
});
}
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
var decimals = $parse(attrs.uiScientificNotationMask)(scope);
if (isNaN(decimals)) {
decimals = defaultPrecision;
}
var significandMask = significandMaskBuilder(decimals);
function splitNumber(value) {
var stringValue = value.toString(),
splittedNumber = stringValue.match(/(-?[0-9]*)[\.]?([0-9]*)?[Ee]?([\+-]?[0-9]*)?/);
return {
integerPartOfSignificand: splittedNumber[1],
decimalPartOfSignificand: splittedNumber[2],
exponent: splittedNumber[3] | 0
};
}
function formatter(value) {
if (ctrl.$isEmpty(value)) {
return value;
}
if (typeof value === 'number') {
value = value.toExponential(decimals);
} else {
value = value.toString().replace(decimalDelimiter, '.');
}
var formattedValue, exponent;
var splittedNumber = splitNumber(value);
var integerPartOfSignificand = splittedNumber.integerPartOfSignificand || 0;
var numberToFormat = integerPartOfSignificand.toString();
if (angular.isDefined(splittedNumber.decimalPartOfSignificand)) {
numberToFormat += splittedNumber.decimalPartOfSignificand;
}
var needsNormalization =
(integerPartOfSignificand >= 1 || integerPartOfSignificand <= -1) &&
(
(angular.isDefined(splittedNumber.decimalPartOfSignificand) &&
splittedNumber.decimalPartOfSignificand.length > decimals) ||
(decimals === 0 && numberToFormat.length >= 2)
);
if (needsNormalization) {
exponent = numberToFormat.slice(decimals + 1, numberToFormat.length);
numberToFormat = numberToFormat.slice(0, decimals + 1);
}
formattedValue = significandMask.apply(numberToFormat);
if (splittedNumber.exponent !== 0) {
exponent = splittedNumber.exponent;
}
if (angular.isDefined(exponent)) {
formattedValue += 'e' + exponent;
}
var prefix = (angular.isDefined(attrs.uiNegativeNumber) && value[0] === '-') ? '-' : '';
return prefix + formattedValue;
}
function parser(value) {
if (ctrl.$isEmpty(value)) {
return value;
}
var isExponentNegative = /e-/.test(value);
var cleanValue = value.replace('e-', 'e');
var viewValue = formatter(cleanValue);
var needsToInvertSign = (value.slice(-1) === '-');
if (needsToInvertSign ^ isExponentNegative) {
viewValue = viewValue.replace(/(e[-]?)/, 'e-');
}
if (needsToInvertSign && isExponentNegative) {
viewValue = viewValue[0] !== '-' ? ('-' + viewValue) : viewValue.replace(/^(-)/,'');
}
var modelValue = parseFloat(viewValue.replace(decimalDelimiter, '.'));
if (ctrl.$viewValue !== viewValue) {
ctrl.$setViewValue(viewValue);
ctrl.$render();
}
return modelValue;
}
ctrl.$formatters.push(formatter);
ctrl.$parsers.push(parser);
ctrl.$validators.max = function validator(value) {
return ctrl.$isEmpty(value) || value < Number.MAX_VALUE;
};
}
};
}
ScientificNotationMaskDirective.$inject = ['$locale', '$parse'];
module.exports = ScientificNotationMaskDirective;
},{"string-mask":undefined}],11:[function(require,module,exports){
;
var StringMask = require('string-mask');
module.exports = function TimeMaskDirective() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
var timeFormat = '00:00:00';
if (angular.isDefined(attrs.uiTimeMask) && attrs.uiTimeMask === 'short') {
timeFormat = '00:00';
}
var formattedValueLength = timeFormat.length;
var unformattedValueLength = timeFormat.replace(':', '').length;
var timeMask = new StringMask(timeFormat);
function formatter(value) {
if (ctrl.$isEmpty(value)) {
return value;
}
var cleanValue = value.replace(/[^0-9]/g, '').slice(0, unformattedValueLength) || '';
return (timeMask.apply(cleanValue) || '').replace(/[^0-9]$/, '');
}
ctrl.$formatters.push(formatter);
ctrl.$parsers.push(function parser(value) {
if (ctrl.$isEmpty(value)) {
return value;
}
var viewValue = formatter(value);
var modelValue = viewValue;
if (ctrl.$viewValue !== viewValue) {
ctrl.$setViewValue(viewValue);
ctrl.$render();
}
return modelValue;
});
ctrl.$validators.time = function(modelValue) {
if (ctrl.$isEmpty(modelValue)) {
return true;
}
var splittedValue = modelValue.toString().split(/:/).filter(function(v) {
return !!v;
});
var hours = parseInt(splittedValue[0]),
minutes = parseInt(splittedValue[1]),
seconds = parseInt(splittedValue[2] || 0);
return modelValue.toString().length === formattedValueLength &&
hours < 24 && minutes < 60 && seconds < 60;
};
}
};
};
},{"string-mask":undefined}],12:[function(require,module,exports){
;
module.exports = function maskFactory(maskDefinition) {
return function MaskDirective() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
ctrl.$formatters.push(function formatter(value) {
if (ctrl.$isEmpty(value)) {
return value;
}
var cleanValue = maskDefinition.clearValue(value.toString());
return maskDefinition.format(cleanValue);
});
ctrl.$parsers.push(function parser(value) {
if (ctrl.$isEmpty(value)) {
return value;
}
var cleanValue = maskDefinition.clearValue(value.toString());
var formattedValue = maskDefinition.format(cleanValue);
if (ctrl.$viewValue !== formattedValue) {
ctrl.$setViewValue(formattedValue);
ctrl.$render();
}
if (angular.isUndefined(maskDefinition.getModelValue)) {
return cleanValue;
}
var actualModelType = typeof ctrl.$modelValue;
return maskDefinition.getModelValue(formattedValue, actualModelType);
});
angular.forEach(maskDefinition.validations, function(validatorFn, validationErrorKey) {
ctrl.$validators[validationErrorKey] = function validator(modelValue, viewValue) {
return ctrl.$isEmpty(modelValue) || validatorFn(modelValue, viewValue);
};
});
}
};
};
};
},{}],13:[function(require,module,exports){
;
var StringMask = require('string-mask');
function viewMask(decimals, decimalDelimiter, thousandsDelimiter) {
var mask = '#' + thousandsDelimiter + '##0';
if (decimals > 0) {
mask += decimalDelimiter;
for (var i = 0; i < decimals; i++) {
mask += '0';
}
}
return new StringMask(mask, {
reverse: true
});
}
function modelMask(decimals) {
var mask = '###0';
if (decimals > 0) {
mask += '.';
for (var i = 0; i < decimals; i++) {
mask += '0';
}
}
return new StringMask(mask, {
reverse: true
});
}
module.exports = {
viewMask: viewMask,
modelMask: modelMask
};
},{"string-mask":undefined}],14:[function(require,module,exports){
;
function clearDelimitersAndLeadingZeros(value) {
if (value === '0') {
return '0';
}
var cleanValue = value.toString().replace(/^-/,'').replace(/^0*/, '');
return cleanValue.replace(/[^0-9]/g, '');
}
function prepareNumberToFormatter(value, decimals) {
return clearDelimitersAndLeadingZeros((parseFloat(value)).toFixed(decimals));
}
module.exports = {
clearDelimitersAndLeadingZeros: clearDelimitersAndLeadingZeros,
prepareNumberToFormatter: prepareNumberToFormatter
};
},{}],15:[function(require,module,exports){
;
module.exports = {
maxNumber: function(ctrl, value, limit) {
var max = parseFloat(limit, 10);
return ctrl.$isEmpty(value) || isNaN(max) || value <= max;
},
minNumber: function(ctrl, value, limit) {
var min = parseFloat(limit, 10);
return ctrl.$isEmpty(value) || isNaN(min) || value >= min;
}
};
},{}]},{},[1]);