Socket
Socket
Sign inDemoInstall

angular-dynamic-number

Package Overview
Dependencies
0
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.4.1 to 2.5.1

2

bower.json
{
"name": "angular-dynamic-number",
"version": "2.4.1",
"version": "2.5.1",
"homepage": "https://github.com/uhlryk/angular-dynamic-number",

@@ -5,0 +5,0 @@ "authors": [

{
"name": "angular-dynamic-number",
"version": "2.4.1",
"version": "2.5.1",
"description": "Highly customizable angular directive for numbers",

@@ -5,0 +5,0 @@ "keywords": [

/*jslint node: true */
(function (root, factory) {
(function(root, factory) {
"use strict";

@@ -8,3 +8,4 @@

} else if (typeof module !== 'undefined' && typeof module.exports === 'object') {
} else if (typeof module !== 'undefined' && typeof module.exports ===
'object') {
module.exports = factory(require('angular'));

@@ -20,9 +21,10 @@

function convModelToView(modelValue, viewSeparator, prepend, append){
if(modelValue === undefined || modelValue === null || modelValue === "") {
function convModelToView(modelValue, viewSeparator, prepend, append) {
if (modelValue === undefined || modelValue === null || modelValue ===
"") {
return "";
}
var newViewValue = '';
if(viewSeparator === ',') {
newViewValue = String(modelValue).replace(".",",");
if (viewSeparator === ',') {
newViewValue = String(modelValue).replace(".", ",");
} else {

@@ -33,19 +35,21 @@ newViewValue = String(modelValue);

}
function convViewToModel(viewValue, viewSeparator, thousandSeparator) {
if(viewSeparator === ',') {
return String(viewValue).replace(/['\.\s]/g,"").replace(",",".");
} else if(viewSeparator === '.') {
return String(viewValue).replace(/[',\s]/g,"");
if (viewSeparator === ',') {
return String(viewValue).replace(/['\.\s]/g, "").replace(",", ".");
} else if (viewSeparator === '.') {
return String(viewValue).replace(/[',\s]/g, "");
}
}
function addPrependAppend(value, prepend, append) {
var newViewValue = value;
if(append) {
if (append) {
newViewValue = newViewValue + append;
}
if(prepend) {
if(/^\-.+/.test(newViewValue)) {
if (prepend) {
if (/^\-.+/.test(newViewValue)) {
newViewValue = newViewValue.replace('-', '-' + prepend);
} else if(/^\-/.test(newViewValue)) {
} else if (/^\-/.test(newViewValue)) {
newViewValue = newViewValue;

@@ -58,6 +62,7 @@ } else {

}
function initIntegerPart(attrs_num_int, def_num_int){
if(attrs_num_int >= 0){
var _num_int = parseInt(attrs_num_int,10);
if(isNaN(_num_int) === false && isFinite(_num_int) && _num_int >= 0){
function initIntegerPart(attrs_num_int, def_num_int) {
if (attrs_num_int >= 0) {
var _num_int = parseInt(attrs_num_int, 10);
if (isNaN(_num_int) === false && isFinite(_num_int) && _num_int >= 0) {
return _num_int;

@@ -68,6 +73,8 @@ }

}
function initFractionPart(attrs_num_fract, def_num_fract){
if(attrs_num_fract >= 0){
var _num_fract = parseInt(attrs_num_fract,10);
if(isNaN(_num_fract) === false && isFinite(_num_fract) && _num_fract >= 0){
function initFractionPart(attrs_num_fract, def_num_fract) {
if (attrs_num_fract >= 0) {
var _num_fract = parseInt(attrs_num_fract, 10);
if (isNaN(_num_fract) === false && isFinite(_num_fract) && _num_fract >=
0) {
return _num_fract;

@@ -78,6 +85,7 @@ }

}
function initSeparator(attrs_num_sep, def_num_sep){
if(attrs_num_sep === ','){
function initSeparator(attrs_num_sep, def_num_sep) {
if (attrs_num_sep === ',') {
return ',';
} else if(attrs_num_sep === '.'){
} else if (attrs_num_sep === '.') {
return '.';

@@ -87,6 +95,7 @@ }

}
function initIsPositive(attrs_num_pos, def_num_pos){
if(attrs_num_pos === 'false' || attrs_num_pos === false) {
function initIsPositive(attrs_num_pos, def_num_pos) {
if (attrs_num_pos === 'false' || attrs_num_pos === false) {
return false;
} else if(attrs_num_pos === 'true' || attrs_num_pos === true) {
} else if (attrs_num_pos === 'true' || attrs_num_pos === true) {
return true;

@@ -96,6 +105,7 @@ }

}
function initIsNegative(attrs_num_neg, def_num_neg){
if(attrs_num_neg === 'false' || attrs_num_neg === false) {
function initIsNegative(attrs_num_neg, def_num_neg) {
if (attrs_num_neg === 'false' || attrs_num_neg === false) {
return false;
} else if(attrs_num_neg === 'true' || attrs_num_neg === true) {
} else if (attrs_num_neg === 'true' || attrs_num_neg === true) {
return true;

@@ -105,8 +115,9 @@ }

}
function initRound(attrs_round, def_round){
if(attrs_round === 'floor') {
function initRound(attrs_round, def_round) {
if (attrs_round === 'floor') {
return Math.floor;
} else if(attrs_round === 'ceil') {
} else if (attrs_round === 'ceil') {
return Math.ceil;
} else if(attrs_round === 'round') {
} else if (attrs_round === 'round') {
return Math.round;

@@ -116,6 +127,7 @@ }

}
function initIsFixed(attrs_fixed, def_fixed){
if(attrs_fixed === 'false' || attrs_fixed === false) {
function initIsFixed(attrs_fixed, def_fixed) {
if (attrs_fixed === 'false' || attrs_fixed === false) {
return false;
} else if(attrs_fixed === 'true' || attrs_fixed === true) {
} else if (attrs_fixed === 'true' || attrs_fixed === true) {
return true;

@@ -125,6 +137,7 @@ }

}
function initIsThousand(attrs_thousand, def_thousand){
if(attrs_thousand === 'false' || attrs_thousand === false) {
function initIsThousand(attrs_thousand, def_thousand) {
if (attrs_thousand === 'false' || attrs_thousand === false) {
return false;
} else if(attrs_thousand === 'true' || attrs_thousand === true) {
} else if (attrs_thousand === 'true' || attrs_thousand === true) {
return true;

@@ -134,8 +147,10 @@ }

}
function initThousandSeparator(attrs_thousand, fractionSeparator, def_thousand) {
if(!attrs_thousand) {
function initThousandSeparator(attrs_thousand, fractionSeparator,
def_thousand) {
if (!attrs_thousand) {
return def_thousand;
}
var regexp;
if(fractionSeparator === '.') {
if (fractionSeparator === '.') {
regexp = new RegExp('^[\',\\s]$');

@@ -145,3 +160,3 @@ } else {

}
if(regexp.test(attrs_thousand)) {
if (regexp.test(attrs_thousand)) {
return attrs_thousand;

@@ -152,5 +167,6 @@ } else {

}
function initNumAppendPrepend(attrs_num_char){
function initNumAppendPrepend(attrs_num_char) {
var regexp = new RegExp('[^\\d,\\.\\s\\-]{1}');
if(regexp.test(attrs_num_char)) {
if (regexp.test(attrs_num_char)) {
return attrs_num_char;

@@ -163,47 +179,54 @@ }

function buildRegexp(integerPart, fractionPart, fractionSeparator, isPositiveNumber, isNegativeNumber){
function buildRegexp(integerPart, fractionPart, fractionSeparator,
isPositiveNumber, isNegativeNumber) {
var negativeRegex = '-?';
if(isPositiveNumber === false && isNegativeNumber === true) {
if (isPositiveNumber === false && isNegativeNumber === true) {
negativeRegex = '-';
} else if(isPositiveNumber === true && isNegativeNumber === false){
} else if (isPositiveNumber === true && isNegativeNumber === false) {
negativeRegex = '';
}
var intRegex = '[0-9]{0,'+(integerPart)+'}';
if(integerPart === 0){
var intRegex = '[0-9]{0,' + (integerPart) + '}';
if (integerPart === 0) {
intRegex = '0';
}
var fractRegex = '(\\'+fractionSeparator+'([0-9]){0,'+fractionPart+'})';
if(fractionPart === 0) {
var fractRegex = '(\\' + fractionSeparator + '([0-9]){0,' +
fractionPart + '})';
if (fractionPart === 0) {
fractRegex = '';
}
return new RegExp('^'+negativeRegex+intRegex+fractRegex+'?$');
return new RegExp('^' + negativeRegex + intRegex + fractRegex + '?$');
}
function removeLeadingZero(value){
function removeLeadingZero(value) {
return String(value)
.replace(/^(-?)(0+)$/g, "$10")//change 00000 to '0' and -00000 to '-0'
.replace(/^0(\d+)/g, "$1")//change 000001 to '1'
.replace(/^-0(\d+)/g, "-$1")//change -013212 to -0
.replace(new RegExp('^-([\\.,\\s])', 'g'), "-0$1")//change -. to -0.
.replace(new RegExp('^[\\.,\\s]','g'), "0$&");//change . to 0.
.replace(/^(-?)(0+)$/g, "$10") //change 00000 to '0' and -00000 to '-0'
.replace(/^0(\d+)/g, "$1") //change 000001 to '1'
.replace(/^-0(\d+)/g, "-$1") //change -013212 to -0
.replace(new RegExp('^-([\\.,\\s])', 'g'), "-0$1") //change -. to -0.
.replace(new RegExp('^[\\.,\\s]', 'g'), "0$&"); //change . to 0.
}
function removePrependAppendChars(value, prepend, append) {
var newValue = value;
if(prepend) {
newValue = newValue.replace(new RegExp('[\\'+prepend+']','g'),'');
if (prepend) {
newValue = newValue.replace(new RegExp('[\\' + prepend + ']', 'g'),
'');
}
if(append) {
newValue = newValue.replace(new RegExp('[\\'+append+']','g'),'');
if (append) {
newValue = newValue.replace(new RegExp('[\\' + append + ']', 'g'), '');
}
return newValue;
}
function removeThousandSeparators(value, thousandSeparator){
if(thousandSeparator === '.') {
function removeThousandSeparators(value, thousandSeparator) {
if (thousandSeparator === '.') {
return String(value).replace(/\./g, "");
} else if(thousandSeparator === ','){
} else if (thousandSeparator === ',') {
return String(value).replace(/,/g, "");
} else {
return String(value).replace(new RegExp('[\'\\s]','g'), "");
return String(value).replace(new RegExp('[\'\\s]', 'g'), "");
}
}
function addThousandSeparator(value, fractionSeparator, thousandSeparator){
function addThousandSeparator(value, fractionSeparator, thousandSeparator) {
value = String(value).split(fractionSeparator);

@@ -216,9 +239,10 @@ value[0] = value[0].replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator);

var newValue = value;
if(parameters.isFixed) {
if (parameters.isFixed) {
var fractionPart = newValue.split(parameters.fractionSeparator)[1];
var fractionLength = (fractionPart && fractionPart.length) ? fractionPart.length : 0;
if(fractionLength === 0) {
var fractionLength = (fractionPart && fractionPart.length) ?
fractionPart.length : 0;
if (fractionLength === 0) {
newValue += parameters.fractionSeparator;
}
for(var i=fractionLength; i < parameters.fractionPart; i++ ) {
for (var i = fractionLength; i < parameters.fractionPart; i++) {
newValue += "0";

@@ -230,5 +254,6 @@ }

function changeViewValue(ngModelController, value, parameters, state, disable){
function changeViewValue(ngModelController, value, parameters, state,
disable) {
if(disable) {
if (disable) {
state.enable = false;

@@ -238,7 +263,8 @@ }

var valueWithFixedZeros = addFixedZeros(valueString, parameters);
var valueWithPrependAppend = addPrependAppend(valueWithFixedZeros, parameters.prepend, parameters.append);
var valueWithPrependAppend = addPrependAppend(valueWithFixedZeros,
parameters.prepend, parameters.append);
// https://github.com/angular/angular.js/issues/13068
// ngModelController.$viewValue = value;
var version = angular.version;
if(version.major === 1 && version.minor === 2) {
if (version.major === 1 && version.minor === 2) {
ngModelController.$viewValue = valueWithPrependAppend;

@@ -250,2 +276,3 @@ } else {

}
function filterModelValue(

@@ -261,21 +288,25 @@ value,

append
){
if(value === '' || value === undefined || value === null) {
) {
if (value === '' || value === undefined || value === null) {
return '';
}
value = Number(value);
if(!isNaN(value) && isFinite(value)) {
if (!isNaN(value) && isFinite(value)) {
var powerOfTen = Math.pow(10, fractionPart);
if(numFixed) {
value = convModelToView((roundFunction(value*powerOfTen)/powerOfTen).toFixed(fractionPart), fractionSeparator, prepend, append);
if (numFixed) {
value = convModelToView((roundFunction(value * powerOfTen) /
powerOfTen).toFixed(fractionPart), fractionSeparator, prepend,
append);
} else {
value = convModelToView(String(roundFunction(value*powerOfTen)/powerOfTen), fractionSeparator, prepend, append);
value = convModelToView(String(roundFunction(value * powerOfTen) /
powerOfTen), fractionSeparator, prepend, append);
}
value = addPrependAppend(value, prepend, append);
if(isThousandSeparator){
value = addThousandSeparator(value, fractionSeparator, thousandSeparator);
if (isThousandSeparator) {
value = addThousandSeparator(value, fractionSeparator,
thousandSeparator);
}
return value;
}
if(numFixed) {
if (numFixed) {
return (0).toFixed(fractionPart);

@@ -290,12 +321,12 @@ } else {

*/
function getCaretPosition (oField) {
function getCaretPosition(oField) {
var iCaretPos = 0;
if (document.selection) {
oField.focus ();
var oSel = document.selection.createRange ();
oSel.moveStart ('character', -oField.value.length);
oField.focus();
var oSel = document.selection.createRange();
oSel.moveStart('character', -oField.value.length);
iCaretPos = oSel.text.length;
}
else if (oField.selectionStart || oField.selectionStart == '0')
iCaretPos = oField.selectionDirection == 'backward' ? oField.selectionStart : oField.selectionEnd;
} else if (oField.selectionStart || oField.selectionStart == '0')
iCaretPos = oField.selectionDirection == 'backward' ? oField.selectionStart :
oField.selectionEnd;
return (iCaretPos);

@@ -322,11 +353,12 @@ }

}
function countThousandSeparatorToPosition(value,separator, position){
function countThousandSeparatorToPosition(value, separator, position) {
var countPosition = 0;
var countDots = 0;
for(var i =0; i < value.length;i++){
if(value[i] !== separator){
countPosition ++;
if(countPosition >= position)break;
for (var i = 0; i < value.length; i++) {
if (value[i] !== separator) {
countPosition++;
if (countPosition >= position) break;
} else {
countDots ++;
countDots++;
}

@@ -373,3 +405,3 @@ }

};
if(key) {
if (key) {
properties[key] = value;

@@ -380,26 +412,43 @@ }

function removeDoubledDecimalSeparators (value,parameters) {
return value.replace(new RegExp("[\\" + parameters.fractionSeparator + "]+","g"), parameters.fractionSeparator);
function removeDoubledDecimalSeparators(value, parameters) {
return value.replace(new RegExp("[\\" + parameters.fractionSeparator +
"]+", "g"), parameters.fractionSeparator);
}
function initAllProperties(properties, element, attrs, ngModelController, dynamicNumberStrategy){
function initAllProperties(properties, element, attrs, ngModelController,
dynamicNumberStrategy) {
var strategy = {};
if(properties.awnum) {
if (properties.awnum) {
strategy = dynamicNumberStrategy.getStrategy(properties.awnum);
}
var integerPart = initIntegerPart(properties.numInt !== undefined ? properties.numInt : strategy.numInt, 6);
var fractionPart = initFractionPart(properties.numFract !== undefined ? properties.numFract : strategy.numFract, 2);
var fractionSeparator = initSeparator(properties.numSep !== undefined ? properties.numSep : strategy.numSep, '.');
var isPositiveNumber = initIsPositive(properties.numPos !== undefined ? properties.numPos : strategy.numPos, true);
var isNegativeNumber = initIsNegative(properties.numNeg !== undefined ? properties.numNeg : strategy.numNeg, true);
var roundFunction = initRound(properties.numRound !== undefined ? properties.numRound : strategy.numRound, Math.round);
var isThousandSeparator = initIsThousand(properties.numThousand !== undefined ? properties.numThousand : strategy.numThousand, false);
var thousandSeparator = initThousandSeparator(properties.numThousandSep !== undefined ? properties.numThousandSep : strategy.numThousandSep, fractionSeparator, fractionSeparator==='.'?',':'.');
var prepend = initNumAppendPrepend(properties.numPrepend !== undefined ? properties.numPrepend : strategy.numPrepend);
var append = initNumAppendPrepend(properties.numAppend !== undefined ? properties.numAppend : strategy.numAppend);
var isFixed = initIsFixed(properties.numFixed !== undefined ? properties.numFixed : strategy.numFixed, false);
if(isPositiveNumber === false && isNegativeNumber === false) {
throw new Error('Number is set to not be positive and not be negative. Change num_pos attr or/and num_neg attr to true');
var integerPart = initIntegerPart(properties.numInt !== undefined ?
properties.numInt : strategy.numInt, 6);
var fractionPart = initFractionPart(properties.numFract !== undefined ?
properties.numFract : strategy.numFract, 2);
var fractionSeparator = initSeparator(properties.numSep !== undefined ?
properties.numSep : strategy.numSep, '.');
var isPositiveNumber = initIsPositive(properties.numPos !== undefined ?
properties.numPos : strategy.numPos, true);
var isNegativeNumber = initIsNegative(properties.numNeg !== undefined ?
properties.numNeg : strategy.numNeg, true);
var roundFunction = initRound(properties.numRound !== undefined ?
properties.numRound : strategy.numRound, Math.round);
var isThousandSeparator = initIsThousand(properties.numThousand !==
undefined ? properties.numThousand : strategy.numThousand, false);
var thousandSeparator = initThousandSeparator(properties.numThousandSep !==
undefined ? properties.numThousandSep : strategy.numThousandSep,
fractionSeparator, fractionSeparator === '.' ? ',' : '.');
var prepend = initNumAppendPrepend(properties.numPrepend !== undefined ?
properties.numPrepend : strategy.numPrepend);
var append = initNumAppendPrepend(properties.numAppend !== undefined ?
properties.numAppend : strategy.numAppend);
var isFixed = initIsFixed(properties.numFixed !== undefined ?
properties.numFixed : strategy.numFixed, false);
if (isPositiveNumber === false && isNegativeNumber === false) {
throw new Error(
'Number is set to not be positive and not be negative. Change num_pos attr or/and num_neg attr to true'
);
}
var viewRegexTest = buildRegexp(integerPart, fractionPart, fractionSeparator, isPositiveNumber, isNegativeNumber);
var viewRegexTest = buildRegexp(integerPart, fractionPart,
fractionSeparator, isPositiveNumber, isNegativeNumber);
return {

@@ -443,7 +492,8 @@ element: element,

if(wasPasted) {
if (wasPasted) {
wasPasted = false;
// Remove all characters which are not number-relevant
var regex = new RegExp('[^' + ((isNegativeNumber) ? '-': '') + fractionSeparator + thousandSeparator + '0-9]+', 'g');
var regex = new RegExp('[^' + ((isNegativeNumber) ? '-' : '') +
fractionSeparator + thousandSeparator + '0-9]+', 'g');
parsedValue = parsedValue.replace(regex, '');

@@ -456,3 +506,4 @@

// Replace separator if at fraction position
regex = new RegExp('[' + fractionSeparator + thousandSeparator + ']([0-9]{' + fractionPart + '})$');
regex = new RegExp('[' + fractionSeparator + thousandSeparator +
']([0-9]{' + fractionPart + '})$');
parsedValue = parsedValue.replace(regex, fractionSeparator + '$1');

@@ -462,3 +513,3 @@ }

parsedValue = removeDoubledDecimalSeparators(parsedValue, parameters);
if(new RegExp('^[\.,'+thousandSeparator+']{2,}').test(parsedValue)) {
if (new RegExp('^[\.,' + thousandSeparator + ']{2,}').test(parsedValue)) {
changeViewValue(ngModelController, '', parameters, state);

@@ -468,7 +519,8 @@ return null;

var cursorPosition = getCaretPosition(element[0]);
if(prepend) {
if (prepend) {
cursorPosition--;
}
var valBeforeCursor = parsedValue.slice(0,cursorPosition);
valBeforeCursor = removeThousandSeparators(valBeforeCursor, thousandSeparator);
var valBeforeCursor = parsedValue.slice(0, cursorPosition);
valBeforeCursor = removeThousandSeparators(valBeforeCursor,
thousandSeparator);
parsedValue = removeThousandSeparators(parsedValue, thousandSeparator);

@@ -478,5 +530,7 @@ valBeforeCursor = removeLeadingZero(valBeforeCursor);

parsedValue = removeLeadingZero(parsedValue);
if(parsedValue === "0" + fractionSeparator && beforeRemovingLeadingZero === fractionSeparator && isPositiveNumber) {
if(fractionPart) {
changeViewValue(ngModelController, '' + fractionSeparator, parameters, state, true);
if (parsedValue === "0" + fractionSeparator &&
beforeRemovingLeadingZero === fractionSeparator && isPositiveNumber) {
if (fractionPart) {
changeViewValue(ngModelController, '' + fractionSeparator,
parameters, state, true);
setCaretPosition(element[0], 2);

@@ -489,12 +543,12 @@ return null;

}
if(parsedValue === '' && String(value).charAt(0)=== '0'){
if (parsedValue === '' && String(value).charAt(0) === '0') {
changeViewValue(ngModelController, '', parameters);
return null;
}
if(parsedValue === undefined || parsedValue === ''){
if (parsedValue === undefined || parsedValue === '') {
changeViewValue(ngModelController, '', parameters);
return null;
}
if(parsedValue === '-'){
if(isPositiveNumber && !isNegativeNumber) {
if (parsedValue === '-') {
if (isPositiveNumber && !isNegativeNumber) {
changeViewValue(ngModelController, '', parameters, state);

@@ -512,10 +566,12 @@ } else {

*/
if(viewRegexTest.test(parsedValue) === false){
var modelValue = convModelToView(ngModelController.$modelValue, fractionSeparator, parameters);
if (viewRegexTest.test(parsedValue) === false) {
var modelValue = convModelToView(ngModelController.$modelValue,
fractionSeparator, parameters);
if(isThousandSeparator){
modelValue = addThousandSeparator(modelValue, fractionSeparator, thousandSeparator);
if (isThousandSeparator) {
modelValue = addThousandSeparator(modelValue, fractionSeparator,
thousandSeparator);
}
changeViewValue(ngModelController, modelValue, parameters, state);
setCaretPosition(element[0],cursorPosition-1);
setCaretPosition(element[0], cursorPosition - 1);
return ngModelController.$modelValue;

@@ -530,12 +586,14 @@ }

var currentPosition = valBeforeCursor.length;
if(isThousandSeparator){
parsedValue = addThousandSeparator(parsedValue, fractionSeparator, thousandSeparator);
dots = countThousandSeparatorToPosition(parsedValue,thousandSeparator,currentPosition);
if (isThousandSeparator) {
parsedValue = addThousandSeparator(parsedValue, fractionSeparator,
thousandSeparator);
dots = countThousandSeparatorToPosition(parsedValue,
thousandSeparator, currentPosition);
}
if(prepend) {
if (prepend) {
dots++;
if(new RegExp('^(\\-\\d)$').test(parsedValue)) {
dots+=2;
if (new RegExp('^(\\-\\d)$').test(parsedValue)) {
dots += 2;
}
if(new RegExp('^(\\d)$').test(parsedValue)) {
if (new RegExp('^(\\d)$').test(parsedValue)) {
dots++;

@@ -546,3 +604,4 @@ }

setCaretPosition(element[0], currentPosition + dots);
return convViewToModel(parsedValue, fractionSeparator, thousandSeparator);
return convViewToModel(parsedValue, fractionSeparator,
thousandSeparator);
}

@@ -557,3 +616,4 @@ }

}
function onPropertyWatch(ngModelController, initObject){
function onPropertyWatch(ngModelController, initObject) {
var value = filterModelValue(

@@ -575,3 +635,3 @@ ngModelController.$modelValue,

return {
restrict:'A',
restrict: 'A',
require: '?ngModel',

@@ -593,8 +653,12 @@ scope: {

link: function(scope, element, attrs, ngModelController) {
if(!element[0] || element[0].tagName !== 'INPUT' || (element[0].type !== 'text' && element[0].type !== 'tel')) {
console.warn ('Directive angular-dynamic-number works only for \'input\' tag with type = \'text\' or type = \'tel\'');
if (!element[0] || element[0].tagName !== 'INPUT' || (element[0].type !==
'text' && element[0].type !== 'tel')) {
console.warn(
'Directive angular-dynamic-number works only for \'input\' tag with type = \'text\' or type = \'tel\''
);
return;
}
if(!ngModelController) {
console.warn ('Directive angular-dynamic-number need ngModel attribute');
if (!ngModelController) {
console.warn(
'Directive angular-dynamic-number need ngModel attribute');
return;

@@ -614,78 +678,98 @@ }

scope.$watch('numInt', function(newProperty, oldProperty ){
if(oldProperty === newProperty) {
scope.$watch('numInt', function(newProperty, oldProperty) {
if (oldProperty === newProperty) {
return;
}
initObject = initAllProperties(createPropertyObject(scope, 'numInt', newProperty), element, attrs, ngModelController, dynamicNumberStrategy);
initObject = initAllProperties(createPropertyObject(scope,
'numInt', newProperty), element, attrs,
ngModelController, dynamicNumberStrategy);
onPropertyWatch(ngModelController, initObject);
});
scope.$watch('numFract', function(newProperty, oldProperty ){
if(oldProperty === newProperty) {
scope.$watch('numFract', function(newProperty, oldProperty) {
if (oldProperty === newProperty) {
return;
}
initObject = initAllProperties(createPropertyObject(scope, 'numFract', newProperty), element, attrs, ngModelController, dynamicNumberStrategy);
initObject = initAllProperties(createPropertyObject(scope,
'numFract', newProperty), element, attrs,
ngModelController, dynamicNumberStrategy);
onPropertyWatch(ngModelController, initObject);
});
scope.$watch('numSep', function(newProperty, oldProperty ){
if(oldProperty === newProperty) {
scope.$watch('numSep', function(newProperty, oldProperty) {
if (oldProperty === newProperty) {
return;
}
initObject = initAllProperties(createPropertyObject(scope, 'numSep', newProperty), element, attrs, ngModelController, dynamicNumberStrategy);
initObject = initAllProperties(createPropertyObject(scope,
'numSep', newProperty), element, attrs,
ngModelController, dynamicNumberStrategy);
onPropertyWatch(ngModelController, initObject);
});
scope.$watch('numPos', function(newProperty, oldProperty ){
if(oldProperty === newProperty) {
scope.$watch('numPos', function(newProperty, oldProperty) {
if (oldProperty === newProperty) {
return;
}
initObject = initAllProperties(createPropertyObject(scope, 'numPos', newProperty), element, attrs, ngModelController, dynamicNumberStrategy);
initObject = initAllProperties(createPropertyObject(scope,
'numPos', newProperty), element, attrs,
ngModelController, dynamicNumberStrategy);
onPropertyWatch(ngModelController, initObject);
});
scope.$watch('numNeg', function(newProperty, oldProperty ){
if(oldProperty === newProperty) {
scope.$watch('numNeg', function(newProperty, oldProperty) {
if (oldProperty === newProperty) {
return;
}
initObject = initAllProperties(createPropertyObject(scope, 'numNeg', newProperty), element, attrs, ngModelController, dynamicNumberStrategy);
initObject = initAllProperties(createPropertyObject(scope,
'numNeg', newProperty), element, attrs,
ngModelController, dynamicNumberStrategy);
onPropertyWatch(ngModelController, initObject);
});
scope.$watch('numThousand', function(newProperty, oldProperty ){
if(oldProperty === newProperty) {
scope.$watch('numThousand', function(newProperty, oldProperty) {
if (oldProperty === newProperty) {
return;
}
initObject = initAllProperties(createPropertyObject(scope, 'numThousand', newProperty), element, attrs, ngModelController, dynamicNumberStrategy);
initObject = initAllProperties(createPropertyObject(scope,
'numThousand', newProperty), element, attrs,
ngModelController, dynamicNumberStrategy);
onPropertyWatch(ngModelController, initObject);
});
scope.$watch('numThousandSep', function(newProperty, oldProperty ){
if(oldProperty === newProperty) {
scope.$watch('numThousandSep', function(newProperty, oldProperty) {
if (oldProperty === newProperty) {
return;
}
initObject = initAllProperties(createPropertyObject(scope, 'numThousandSep', newProperty), element, attrs, ngModelController, dynamicNumberStrategy);
initObject = initAllProperties(createPropertyObject(scope,
'numThousandSep', newProperty), element, attrs,
ngModelController, dynamicNumberStrategy);
onPropertyWatch(ngModelController, initObject);
});
scope.$watch('numAppend', function(newProperty, oldProperty ){
if(oldProperty === newProperty) {
scope.$watch('numAppend', function(newProperty, oldProperty) {
if (oldProperty === newProperty) {
return;
}
initObject = initAllProperties(createPropertyObject(scope, 'numAppend', newProperty), element, attrs, ngModelController, dynamicNumberStrategy);
initObject = initAllProperties(createPropertyObject(scope,
'numAppend', newProperty), element, attrs,
ngModelController, dynamicNumberStrategy);
onPropertyWatch(ngModelController, initObject);
});
scope.$watch('numPrepend', function(newProperty, oldProperty ){
if(oldProperty === newProperty) {
scope.$watch('numPrepend', function(newProperty, oldProperty) {
if (oldProperty === newProperty) {
return;
}
initObject = initAllProperties(createPropertyObject(scope, 'numPrepend', newProperty), element, attrs, ngModelController, dynamicNumberStrategy);
initObject = initAllProperties(createPropertyObject(scope,
'numPrepend', newProperty), element, attrs,
ngModelController, dynamicNumberStrategy);
onPropertyWatch(ngModelController, initObject);
});
scope.$watch('numFixed', function(newProperty, oldProperty ){
if(oldProperty === newProperty) {
scope.$watch('numFixed', function(newProperty, oldProperty) {
if (oldProperty === newProperty) {
return;
}
initObject = initAllProperties(createPropertyObject(scope, 'numFixed', newProperty), element, attrs, ngModelController, dynamicNumberStrategy);
initObject = initAllProperties(createPropertyObject(scope,
'numFixed', newProperty), element, attrs,
ngModelController, dynamicNumberStrategy);
onPropertyWatch(ngModelController, initObject);

@@ -697,6 +781,7 @@ });

};
ngModelController.$parsers.unshift(function(value){
if(state.enable) {
state.count ++;
return prepareResponse(directiveParser(value, initObject, state));
ngModelController.$parsers.unshift(function(value) {
if (state.enable) {
state.count++;
return prepareResponse(directiveParser(value, initObject,
state));
} else {

@@ -710,3 +795,3 @@ state.enable = true;

*/
ngModelController.$formatters.push(function(value){
ngModelController.$formatters.push(function(value) {
return filterModelValue(

@@ -730,24 +815,39 @@ value,

angular.module(moduleName,[])
angular.module(moduleName, [])
.provider('dynamicNumberStrategy', function() {
var strategies = {};
this.addStrategy = function(name, strategy){
strategies[name]=strategy;
this.addStrategy = addStrategy;
this.getStrategy = getStrategy;
this.getStrategies = getStrategies;
var strategyProvider = {
addStrategy: addStrategy,
getStrategy: getStrategy,
getStrategies: getStrategies
};
this.getStrategy = function(name) {
this.$get = function() {
return strategyProvider;
};
function addStrategy(name, strategy) {
strategies[name] = strategy;
}
function getStrategy(name) {
return strategies[name];
};
this.$get = function(){
return {
getStrategy: function(name) {
return strategies[name];
}
};
};
}
function getStrategies() {
return strategies;
}
})
.filter('awnum', ['dynamicNumberStrategy', function(dynamicNumberStrategy) {
return function(value, numFract, numSep, numRound, numFixed, numThousand, numThousandSep, numPrepend, numAppend) {
.filter('awnum', ['dynamicNumberStrategy', function(
dynamicNumberStrategy) {
return function(value, numFract, numSep, numRound, numFixed,
numThousand, numThousandSep, numPrepend, numAppend) {
var strategy = {};
var fractionPart;
if(angular.isString(numFract)) {
if (angular.isString(numFract)) {
strategy = dynamicNumberStrategy.getStrategy(numFract);

@@ -757,11 +857,21 @@ numFract = strategy.numFract;

var fractionPart = initFractionPart(numFract, 2);
var fractionSeparator = initSeparator(numSep !== undefined ? numSep : strategy.numSep, '.');
var roundFunction = initRound(numRound !== undefined ? numRound : strategy.numRound, Math.round);
var isFixed = initIsFixed(numFixed !== undefined ? numFixed : strategy.numFixed, false);
var isThousandSeparator = initIsThousand(numThousand !== undefined ? numThousand : strategy.numThousand, false);
var thousandSeparator = initThousandSeparator(numThousandSep !== undefined ? numThousandSep : strategy.numThousandSep, fractionSeparator, fractionSeparator==='.'?',':'.');
var prepend = initNumAppendPrepend(numPrepend !== undefined ? numPrepend : strategy.numPrepend);
var append = initNumAppendPrepend(numAppend !== undefined ? numAppend : strategy.numAppend);
var filteredValue = filterModelValue(value, fractionPart, fractionSeparator, roundFunction, isFixed, isThousandSeparator, thousandSeparator, prepend, append);
if(filteredValue === '') {
var fractionSeparator = initSeparator(numSep !== undefined ?
numSep : strategy.numSep, '.');
var roundFunction = initRound(numRound !== undefined ?
numRound : strategy.numRound, Math.round);
var isFixed = initIsFixed(numFixed !== undefined ? numFixed :
strategy.numFixed, false);
var isThousandSeparator = initIsThousand(numThousand !==
undefined ? numThousand : strategy.numThousand, false);
var thousandSeparator = initThousandSeparator(numThousandSep !==
undefined ? numThousandSep : strategy.numThousandSep,
fractionSeparator, fractionSeparator === '.' ? ',' : '.');
var prepend = initNumAppendPrepend(numPrepend !== undefined ?
numPrepend : strategy.numPrepend);
var append = initNumAppendPrepend(numAppend !== undefined ?
numAppend : strategy.numAppend);
var filteredValue = filterModelValue(value, fractionPart,
fractionSeparator, roundFunction, isFixed,
isThousandSeparator, thousandSeparator, prepend, append);
if (filteredValue === '') {
return '0';

@@ -772,5 +882,5 @@ }

}])
.directive('awnum', ['dynamicNumberStrategy',dynamicNumberDirective]);
.directive('awnum', ['dynamicNumberStrategy', dynamicNumberDirective]);
return moduleName;
}));

@@ -1,1 +0,1 @@

!function(n,e){"use strict";if("function"==typeof define&&define.amd)define(["angular"],e);else{if("undefined"==typeof module||"object"!=typeof module.exports)return e(n.angular);module.exports=e(require("angular"))}}(window,function(n){"use strict";function e(n,e,t,r){if(void 0===n||null===n||""===n)return"";var u="";return u=","===e?String(n).replace(".",","):String(n)}function t(n,e,t){return","===e?String(n).replace(/['\.\s]/g,"").replace(",","."):"."===e?String(n).replace(/[',\s]/g,""):void 0}function r(n,e,t){var r=n;return t&&(r+=t),e&&(r=/^\-.+/.test(r)?r.replace("-","-"+e):/^\-/.test(r)?r:e+r),r}function u(n,e){if(n>=0){var t=parseInt(n,10);if(isNaN(t)===!1&&isFinite(t)&&t>=0)return t}return e}function a(n,e){if(n>=0){var t=parseInt(n,10);if(isNaN(t)===!1&&isFinite(t)&&t>=0)return t}return e}function i(n,e){return","===n?",":"."===n?".":e}function o(n,e){return"false"!==n&&n!==!1&&("true"===n||n===!0||e)}function c(n,e){return"false"!==n&&n!==!1&&("true"===n||n===!0||e)}function d(n,e){return"floor"===n?Math.floor:"ceil"===n?Math.ceil:"round"===n?Math.round:e}function p(n,e){return"false"!==n&&n!==!1&&("true"===n||n===!0||e)}function m(n,e){return"false"!==n&&n!==!1&&("true"===n||n===!0||e)}function s(n,e,t){if(!n)return t;var r;return r="."===e?new RegExp("^[',\\s]$"):new RegExp("^['\\.\\s]$"),r.test(n)?n:t}function f(n){var e=new RegExp("[^\\d,\\.\\s\\-]{1}");return e.test(n)?n:null}function l(n,e,t,r,u){var a="-?";r===!1&&u===!0?a="-":r===!0&&u===!1&&(a="");var i="[0-9]{0,"+n+"}";0===n&&(i="0");var o="(\\"+t+"([0-9]){0,"+e+"})";return 0===e&&(o=""),new RegExp("^"+a+i+o+"?$")}function g(n){return String(n).replace(/^(-?)(0+)$/g,"$10").replace(/^0(\d+)/g,"$1").replace(/^-0(\d+)/g,"-$1").replace(new RegExp("^-([\\.,\\s])","g"),"-0$1").replace(new RegExp("^[\\.,\\s]","g"),"0$&")}function v(n,e,t){var r=n;return e&&(r=r.replace(new RegExp("[\\"+e+"]","g"),"")),t&&(r=r.replace(new RegExp("[\\"+t+"]","g"),"")),r}function S(n,e){return"."===e?String(n).replace(/\./g,""):","===e?String(n).replace(/,/g,""):String(n).replace(new RegExp("['\\s]","g"),"")}function h(n,e,t){return n=String(n).split(e),n[0]=n[0].replace(/\B(?=(\d{3})+(?!\d))/g,t),n.join(e)}function w(n,e){var t=n;if(e.isFixed){var r=t.split(e.fractionSeparator)[1],u=r&&r.length?r.length:0;0===u&&(t+=e.fractionSeparator);for(var a=u;a<e.fractionPart;a++)t+="0"}return t}function x(e,t,u,a,i){i&&(a.enable=!1);var o=String(t),c=w(o,u),d=r(c,u.prepend,u.append),p=n.version;1===p.major&&2===p.minor?e.$viewValue=d:e.$setViewValue(d),e.$render()}function $(n,t,u,a,i,o,c,d,p){if(""===n||void 0===n||null===n)return"";if(n=Number(n),!isNaN(n)&&isFinite(n)){var m=Math.pow(10,t);return n=i?e((a(n*m)/m).toFixed(t),u,d,p):e(String(a(n*m)/m),u,d,p),n=r(n,d,p),o&&(n=h(n,u,c)),n}return i?(0).toFixed(t):"0"}function F(n){var e=0;if(document.selection){n.focus();var t=document.selection.createRange();t.moveStart("character",-n.value.length),e=t.text.length}else(n.selectionStart||"0"==n.selectionStart)&&(e="backward"==n.selectionDirection?n.selectionStart:n.selectionEnd);return e}function N(n,e){if(null!==n)if(n.createTextRange){var t=n.createTextRange();t.move("character",e),t.select()}else n.selectionStart?(n.focus(),n.setSelectionRange(e,e)):n.focus()}function P(n,e,t){for(var r=0,u=0,a=0;a<n.length;a++)if(n[a]!==e){if(r++,r>=t)break}else u++;return u}function R(n,e){var t=n,r=t.split(e.fractionSeparator),u=r[0],a=r[1];return a&&a.length>e.fractionPart&&(a=a.slice(0,e.fractionPart),t=[u,a].join(e.fractionSeparator)),t}function T(n){return null===n?null:Number(n)}function b(n,e,t){var r={awnum:n.awnum,numInt:n.numInt,numFract:n.numFract,numSep:n.numSep,numPos:n.numPos,numNeg:n.numNeg,numRound:n.numRound,numThousand:n.numThousand,numThousandSep:n.numThousandSep,numPrepend:n.numPrepend,numAppend:n.numAppend,numFixed:n.numFixed};return e&&(r[e]=t),r}function y(n,e){return n.replace(new RegExp("[\\"+e.fractionSeparator+"]+","g"),e.fractionSeparator)}function E(n,e,t,r,g){var v={};n.awnum&&(v=g.getStrategy(n.awnum));var S=u(void 0!==n.numInt?n.numInt:v.numInt,6),h=a(void 0!==n.numFract?n.numFract:v.numFract,2),w=i(void 0!==n.numSep?n.numSep:v.numSep,"."),x=o(void 0!==n.numPos?n.numPos:v.numPos,!0),$=c(void 0!==n.numNeg?n.numNeg:v.numNeg,!0),F=d(void 0!==n.numRound?n.numRound:v.numRound,Math.round),N=m(void 0!==n.numThousand?n.numThousand:v.numThousand,!1),P=s(void 0!==n.numThousandSep?n.numThousandSep:v.numThousandSep,w,"."===w?",":"."),R=f(void 0!==n.numPrepend?n.numPrepend:v.numPrepend),T=f(void 0!==n.numAppend?n.numAppend:v.numAppend),b=p(void 0!==n.numFixed?n.numFixed:v.numFixed,!1);if(x===!1&&$===!1)throw new Error("Number is set to not be positive and not be negative. Change num_pos attr or/and num_neg attr to true");var y=l(S,h,w,x,$);return{element:e,attrs:t,ngModelController:r,viewRegexTest:y,integerPart:S,fractionPart:h,fractionSeparator:w,isPositiveNumber:x,isNegativeNumber:$,roundFunction:F,isThousandSeparator:N,thousandSeparator:P,prepend:R,append:T,isFixed:b}}function A(n,r,u){var a=r.element,i=(r.attrs,r.ngModelController),o=r.viewRegexTest,c=(r.integerPart,r.fractionPart),d=r.fractionSeparator,p=r.isPositiveNumber,m=r.isNegativeNumber,s=(r.roundFunction,r.isThousandSeparator),f=r.thousandSeparator,l=r.prepend,w=r.append,$=(r.isFixed,String(n));if(j){j=!1;var T=new RegExp("[^"+(m?"-":"")+d+f+"0-9]+","g");$=$.replace(T,""),T=new RegExp("^["+d+f+"]"),$=$.replace(T,""),T=new RegExp("["+d+f+"]([0-9]{"+c+"})$"),$=$.replace(T,d+"$1")}if($=v($,l,w),$=y($,r),new RegExp("^[.,"+f+"]{2,}").test($))return x(i,"",r,u),null;var b=F(a[0]);l&&b--;var E=$.slice(0,b);E=S(E,f),$=S($,f),E=g(E);var A=$;if($=g($),$==="0"+d&&A===d&&p)return c?(x(i,""+d,r,u,!0),N(a[0],2),null):(x(i,"",r,u),null);if(""===$&&"0"===String(n).charAt(0))return x(i,"",r),null;if(void 0===$||""===$)return x(i,"",r),null;if("-"===$)return p&&!m?x(i,"",r,u):x(i,"-",r,u),null;if($=R($,r),o.test($)===!1){var I=e(i.$modelValue,d,r);return s&&(I=h(I,d,f)),x(i,I,r,u),N(a[0],b-1),i.$modelValue}var M=0,V=E.length;return s&&($=h($,d,f),M=P($,f,V)),l&&(M++,new RegExp("^(\\-\\d)$").test($)&&(M+=2),new RegExp("^(\\d)$").test($)&&M++),x(i,$,r,u),N(a[0],V+M),t($,d,f)}function I(n,e){n.$setViewValue(""),n.$render(),n.$setViewValue(e),n.$render()}function M(n,e){var t=$(n.$modelValue,e.fractionPart,e.fractionSeparator,e.roundFunction,e.isFixed,e.isThousandSeparator,e.thousandSeparator,e.prepend,e.append);I(n,t)}function V(n){return{restrict:"A",require:"?ngModel",scope:{awnum:"@",numInt:"@",numFract:"@",numSep:"@",numPos:"@",numNeg:"@",numRound:"@",numThousand:"@",numThousandSep:"@",numPrepend:"@",numAppend:"@",numFixed:"@"},link:function(e,t,r,u){if(!t[0]||"INPUT"!==t[0].tagName||"text"!==t[0].type&&"tel"!==t[0].type)return void console.warn("Directive angular-dynamic-number works only for 'input' tag with type = 'text' or type = 'tel'");if(!u)return void console.warn("Directive angular-dynamic-number need ngModel attribute");var a=E(b(e),t,r,u,n);t.on("paste",function(){j=!0}),e.$watch("numInt",function(i,o){o!==i&&(a=E(b(e,"numInt",i),t,r,u,n),M(u,a))}),e.$watch("numFract",function(i,o){o!==i&&(a=E(b(e,"numFract",i),t,r,u,n),M(u,a))}),e.$watch("numSep",function(i,o){o!==i&&(a=E(b(e,"numSep",i),t,r,u,n),M(u,a))}),e.$watch("numPos",function(i,o){o!==i&&(a=E(b(e,"numPos",i),t,r,u,n),M(u,a))}),e.$watch("numNeg",function(i,o){o!==i&&(a=E(b(e,"numNeg",i),t,r,u,n),M(u,a))}),e.$watch("numThousand",function(i,o){o!==i&&(a=E(b(e,"numThousand",i),t,r,u,n),M(u,a))}),e.$watch("numThousandSep",function(i,o){o!==i&&(a=E(b(e,"numThousandSep",i),t,r,u,n),M(u,a))}),e.$watch("numAppend",function(i,o){o!==i&&(a=E(b(e,"numAppend",i),t,r,u,n),M(u,a))}),e.$watch("numPrepend",function(i,o){o!==i&&(a=E(b(e,"numPrepend",i),t,r,u,n),M(u,a))}),e.$watch("numFixed",function(i,o){o!==i&&(a=E(b(e,"numFixed",i),t,r,u,n),M(u,a))});var i={enable:!0,count:0};u.$parsers.unshift(function(n){return i.enable?(i.count++,T(A(n,a,i))):(i.enable=!0,n)}),u.$formatters.push(function(n){return $(n,a.fractionPart,a.fractionSeparator,a.roundFunction,a.isFixed,a.isThousandSeparator,a.thousandSeparator,a.prepend,a.append)})}}}var j=!1,k="dynamicNumber";return n.module(k,[]).provider("dynamicNumberStrategy",function(){var n={};this.addStrategy=function(e,t){n[e]=t},this.getStrategy=function(e){return n[e]},this.$get=function(){return{getStrategy:function(e){return n[e]}}}}).filter("awnum",["dynamicNumberStrategy",function(e){return function(t,r,u,o,c,l,g,v,S){var h,w={};n.isString(r)&&(w=e.getStrategy(r),r=w.numFract);var h=a(r,2),x=i(void 0!==u?u:w.numSep,"."),F=d(void 0!==o?o:w.numRound,Math.round),N=p(void 0!==c?c:w.numFixed,!1),P=m(void 0!==l?l:w.numThousand,!1),R=s(void 0!==g?g:w.numThousandSep,x,"."===x?",":"."),T=f(void 0!==v?v:w.numPrepend),b=f(void 0!==S?S:w.numAppend),y=$(t,h,x,F,N,P,R,T,b);return""===y?"0":y}}]).directive("awnum",["dynamicNumberStrategy",V]),k});
!function(n,e){"use strict";if("function"==typeof define&&define.amd)define(["angular"],e);else{if("undefined"==typeof module||"object"!=typeof module.exports)return e(n.angular);module.exports=e(require("angular"))}}(window,function(n){"use strict";function e(n,e,t,r){if(void 0===n||null===n||""===n)return"";var u="";return u=","===e?String(n).replace(".",","):String(n)}function t(n,e,t){return","===e?String(n).replace(/['\.\s]/g,"").replace(",","."):"."===e?String(n).replace(/[',\s]/g,""):void 0}function r(n,e,t){var r=n;return t&&(r+=t),e&&(r=/^\-.+/.test(r)?r.replace("-","-"+e):/^\-/.test(r)?r:e+r),r}function u(n,e){if(n>=0){var t=parseInt(n,10);if(isNaN(t)===!1&&isFinite(t)&&t>=0)return t}return e}function a(n,e){if(n>=0){var t=parseInt(n,10);if(isNaN(t)===!1&&isFinite(t)&&t>=0)return t}return e}function i(n,e){return","===n?",":"."===n?".":e}function o(n,e){return"false"!==n&&n!==!1&&("true"===n||n===!0||e)}function c(n,e){return"false"!==n&&n!==!1&&("true"===n||n===!0||e)}function d(n,e){return"floor"===n?Math.floor:"ceil"===n?Math.ceil:"round"===n?Math.round:e}function p(n,e){return"false"!==n&&n!==!1&&("true"===n||n===!0||e)}function m(n,e){return"false"!==n&&n!==!1&&("true"===n||n===!0||e)}function s(n,e,t){if(!n)return t;var r;return r="."===e?new RegExp("^[',\\s]$"):new RegExp("^['\\.\\s]$"),r.test(n)?n:t}function f(n){var e=new RegExp("[^\\d,\\.\\s\\-]{1}");return e.test(n)?n:null}function l(n,e,t,r,u){var a="-?";r===!1&&u===!0?a="-":r===!0&&u===!1&&(a="");var i="[0-9]{0,"+n+"}";0===n&&(i="0");var o="(\\"+t+"([0-9]){0,"+e+"})";return 0===e&&(o=""),new RegExp("^"+a+i+o+"?$")}function g(n){return String(n).replace(/^(-?)(0+)$/g,"$10").replace(/^0(\d+)/g,"$1").replace(/^-0(\d+)/g,"-$1").replace(new RegExp("^-([\\.,\\s])","g"),"-0$1").replace(new RegExp("^[\\.,\\s]","g"),"0$&")}function v(n,e,t){var r=n;return e&&(r=r.replace(new RegExp("[\\"+e+"]","g"),"")),t&&(r=r.replace(new RegExp("[\\"+t+"]","g"),"")),r}function S(n,e){return"."===e?String(n).replace(/\./g,""):","===e?String(n).replace(/,/g,""):String(n).replace(new RegExp("['\\s]","g"),"")}function h(n,e,t){return n=String(n).split(e),n[0]=n[0].replace(/\B(?=(\d{3})+(?!\d))/g,t),n.join(e)}function w(n,e){var t=n;if(e.isFixed){var r=t.split(e.fractionSeparator)[1],u=r&&r.length?r.length:0;0===u&&(t+=e.fractionSeparator);for(var a=u;a<e.fractionPart;a++)t+="0"}return t}function x(e,t,u,a,i){i&&(a.enable=!1);var o=String(t),c=w(o,u),d=r(c,u.prepend,u.append),p=n.version;1===p.major&&2===p.minor?e.$viewValue=d:e.$setViewValue(d),e.$render()}function $(n,t,u,a,i,o,c,d,p){if(""===n||void 0===n||null===n)return"";if(n=Number(n),!isNaN(n)&&isFinite(n)){var m=Math.pow(10,t);return n=i?e((a(n*m)/m).toFixed(t),u,d,p):e(String(a(n*m)/m),u,d,p),n=r(n,d,p),o&&(n=h(n,u,c)),n}return i?(0).toFixed(t):"0"}function F(n){var e=0;if(document.selection){n.focus();var t=document.selection.createRange();t.moveStart("character",-n.value.length),e=t.text.length}else(n.selectionStart||"0"==n.selectionStart)&&(e="backward"==n.selectionDirection?n.selectionStart:n.selectionEnd);return e}function N(n,e){if(null!==n)if(n.createTextRange){var t=n.createTextRange();t.move("character",e),t.select()}else n.selectionStart?(n.focus(),n.setSelectionRange(e,e)):n.focus()}function P(n,e,t){for(var r=0,u=0,a=0;a<n.length;a++)if(n[a]!==e){if(r++,r>=t)break}else u++;return u}function R(n,e){var t=n,r=t.split(e.fractionSeparator),u=r[0],a=r[1];return a&&a.length>e.fractionPart&&(a=a.slice(0,e.fractionPart),t=[u,a].join(e.fractionSeparator)),t}function T(n){return null===n?null:Number(n)}function b(n,e,t){var r={awnum:n.awnum,numInt:n.numInt,numFract:n.numFract,numSep:n.numSep,numPos:n.numPos,numNeg:n.numNeg,numRound:n.numRound,numThousand:n.numThousand,numThousandSep:n.numThousandSep,numPrepend:n.numPrepend,numAppend:n.numAppend,numFixed:n.numFixed};return e&&(r[e]=t),r}function y(n,e){return n.replace(new RegExp("[\\"+e.fractionSeparator+"]+","g"),e.fractionSeparator)}function E(n,e,t,r,g){var v={};n.awnum&&(v=g.getStrategy(n.awnum));var S=u(void 0!==n.numInt?n.numInt:v.numInt,6),h=a(void 0!==n.numFract?n.numFract:v.numFract,2),w=i(void 0!==n.numSep?n.numSep:v.numSep,"."),x=o(void 0!==n.numPos?n.numPos:v.numPos,!0),$=c(void 0!==n.numNeg?n.numNeg:v.numNeg,!0),F=d(void 0!==n.numRound?n.numRound:v.numRound,Math.round),N=m(void 0!==n.numThousand?n.numThousand:v.numThousand,!1),P=s(void 0!==n.numThousandSep?n.numThousandSep:v.numThousandSep,w,"."===w?",":"."),R=f(void 0!==n.numPrepend?n.numPrepend:v.numPrepend),T=f(void 0!==n.numAppend?n.numAppend:v.numAppend),b=p(void 0!==n.numFixed?n.numFixed:v.numFixed,!1);if(x===!1&&$===!1)throw new Error("Number is set to not be positive and not be negative. Change num_pos attr or/and num_neg attr to true");var y=l(S,h,w,x,$);return{element:e,attrs:t,ngModelController:r,viewRegexTest:y,integerPart:S,fractionPart:h,fractionSeparator:w,isPositiveNumber:x,isNegativeNumber:$,roundFunction:F,isThousandSeparator:N,thousandSeparator:P,prepend:R,append:T,isFixed:b}}function A(n,r,u){var a=r.element,i=(r.attrs,r.ngModelController),o=r.viewRegexTest,c=(r.integerPart,r.fractionPart),d=r.fractionSeparator,p=r.isPositiveNumber,m=r.isNegativeNumber,s=(r.roundFunction,r.isThousandSeparator),f=r.thousandSeparator,l=r.prepend,w=r.append,$=(r.isFixed,String(n));if(j){j=!1;var T=new RegExp("[^"+(m?"-":"")+d+f+"0-9]+","g");$=$.replace(T,""),T=new RegExp("^["+d+f+"]"),$=$.replace(T,""),T=new RegExp("["+d+f+"]([0-9]{"+c+"})$"),$=$.replace(T,d+"$1")}if($=v($,l,w),$=y($,r),new RegExp("^[.,"+f+"]{2,}").test($))return x(i,"",r,u),null;var b=F(a[0]);l&&b--;var E=$.slice(0,b);E=S(E,f),$=S($,f),E=g(E);var A=$;if($=g($),$==="0"+d&&A===d&&p)return c?(x(i,""+d,r,u,!0),N(a[0],2),null):(x(i,"",r,u),null);if(""===$&&"0"===String(n).charAt(0))return x(i,"",r),null;if(void 0===$||""===$)return x(i,"",r),null;if("-"===$)return p&&!m?x(i,"",r,u):x(i,"-",r,u),null;if($=R($,r),o.test($)===!1){var I=e(i.$modelValue,d,r);return s&&(I=h(I,d,f)),x(i,I,r,u),N(a[0],b-1),i.$modelValue}var M=0,V=E.length;return s&&($=h($,d,f),M=P($,f,V)),l&&(M++,new RegExp("^(\\-\\d)$").test($)&&(M+=2),new RegExp("^(\\d)$").test($)&&M++),x(i,$,r,u),N(a[0],V+M),t($,d,f)}function I(n,e){n.$setViewValue(""),n.$render(),n.$setViewValue(e),n.$render()}function M(n,e){var t=$(n.$modelValue,e.fractionPart,e.fractionSeparator,e.roundFunction,e.isFixed,e.isThousandSeparator,e.thousandSeparator,e.prepend,e.append);I(n,t)}function V(n){return{restrict:"A",require:"?ngModel",scope:{awnum:"@",numInt:"@",numFract:"@",numSep:"@",numPos:"@",numNeg:"@",numRound:"@",numThousand:"@",numThousandSep:"@",numPrepend:"@",numAppend:"@",numFixed:"@"},link:function(e,t,r,u){if(!t[0]||"INPUT"!==t[0].tagName||"text"!==t[0].type&&"tel"!==t[0].type)return void console.warn("Directive angular-dynamic-number works only for 'input' tag with type = 'text' or type = 'tel'");if(!u)return void console.warn("Directive angular-dynamic-number need ngModel attribute");var a=E(b(e),t,r,u,n);t.on("paste",function(){j=!0}),e.$watch("numInt",function(i,o){o!==i&&(a=E(b(e,"numInt",i),t,r,u,n),M(u,a))}),e.$watch("numFract",function(i,o){o!==i&&(a=E(b(e,"numFract",i),t,r,u,n),M(u,a))}),e.$watch("numSep",function(i,o){o!==i&&(a=E(b(e,"numSep",i),t,r,u,n),M(u,a))}),e.$watch("numPos",function(i,o){o!==i&&(a=E(b(e,"numPos",i),t,r,u,n),M(u,a))}),e.$watch("numNeg",function(i,o){o!==i&&(a=E(b(e,"numNeg",i),t,r,u,n),M(u,a))}),e.$watch("numThousand",function(i,o){o!==i&&(a=E(b(e,"numThousand",i),t,r,u,n),M(u,a))}),e.$watch("numThousandSep",function(i,o){o!==i&&(a=E(b(e,"numThousandSep",i),t,r,u,n),M(u,a))}),e.$watch("numAppend",function(i,o){o!==i&&(a=E(b(e,"numAppend",i),t,r,u,n),M(u,a))}),e.$watch("numPrepend",function(i,o){o!==i&&(a=E(b(e,"numPrepend",i),t,r,u,n),M(u,a))}),e.$watch("numFixed",function(i,o){o!==i&&(a=E(b(e,"numFixed",i),t,r,u,n),M(u,a))});var i={enable:!0,count:0};u.$parsers.unshift(function(n){return i.enable?(i.count++,T(A(n,a,i))):(i.enable=!0,n)}),u.$formatters.push(function(n){return $(n,a.fractionPart,a.fractionSeparator,a.roundFunction,a.isFixed,a.isThousandSeparator,a.thousandSeparator,a.prepend,a.append)})}}}var j=!1,k="dynamicNumber";return n.module(k,[]).provider("dynamicNumberStrategy",function(){function n(n,e){r[n]=e}function e(n){return r[n]}function t(){return r}var r={};this.addStrategy=n,this.getStrategy=e,this.getStrategies=t;var u={addStrategy:n,getStrategy:e,getStrategies:t};this.$get=function(){return u}}).filter("awnum",["dynamicNumberStrategy",function(e){return function(t,r,u,o,c,l,g,v,S){var h,w={};n.isString(r)&&(w=e.getStrategy(r),r=w.numFract);var h=a(r,2),x=i(void 0!==u?u:w.numSep,"."),F=d(void 0!==o?o:w.numRound,Math.round),N=p(void 0!==c?c:w.numFixed,!1),P=m(void 0!==l?l:w.numThousand,!1),R=s(void 0!==g?g:w.numThousandSep,x,"."===x?",":"."),T=f(void 0!==v?v:w.numPrepend),b=f(void 0!==S?S:w.numAppend),y=$(t,h,x,F,N,P,R,T,b);return""===y?"0":y}}]).directive("awnum",["dynamicNumberStrategy",V]),k});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc