angular-dynamic-number
Advanced tools
Comparing version 1.12.1 to 1.12.2
{ | ||
"name": "angular-dynamic-number", | ||
"version": "1.12.1", | ||
"version": "1.12.2", | ||
"homepage": "https://github.com/uhlryk/angular-dynamic-number", | ||
@@ -5,0 +5,0 @@ "authors": [ |
{ | ||
"name": "angular-dynamic-number", | ||
"version": "1.12.1", | ||
"version": "1.12.2", | ||
"description": "Highly customizable angular directive for numbers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -276,3 +276,2 @@ /*jslint node: true */ | ||
awnum: scope.awnum, | ||
numFixed: scope.numFixed, | ||
numInt: scope.numInt, | ||
@@ -301,3 +300,2 @@ numFract: scope.numFract, | ||
var integerPart = initIntegerPart(properties.numInt !== undefined ? properties.numInt : strategy.numInt, 6); | ||
var isFixed = initIsFixed(properties.numFixed !== undefined ? properties.numFixed : strategy.numFixed, false); | ||
var fractionPart = initFractionPart(properties.numFract !== undefined ? properties.numFract : strategy.numFract, 2); | ||
@@ -321,3 +319,2 @@ var fractionSeparator = initSeparator(properties.numSep !== undefined ? properties.numSep : strategy.numSep, '.'); | ||
viewRegexTest: viewRegexTest, | ||
isFixed: isFixed, | ||
integerPart: integerPart, | ||
@@ -457,3 +454,3 @@ fractionPart: fractionPart, | ||
initObject.roundFunction, | ||
initObject.isFixed, | ||
false, | ||
initObject.isThousandSeparator, | ||
@@ -473,3 +470,2 @@ initObject.thousandSeparator, | ||
awnum: "@", | ||
numFixed: "@", | ||
numInt: "@", | ||
@@ -507,10 +503,2 @@ numFract: "@", | ||
scope.$watch('numFixed', function(newProperty, oldProperty ){ | ||
if(oldProperty === newProperty) { | ||
return; | ||
} | ||
initObject = initAllProperties(createPropertyObject(scope, 'numFixed', newProperty), element, attrs, ngModelController, dynamicNumberStrategy); | ||
onPropertyWatch(ngModelController, initObject); | ||
}); | ||
scope.$watch('numInt', function(newProperty, oldProperty ){ | ||
@@ -600,3 +588,3 @@ if(oldProperty === newProperty) { | ||
initObject.roundFunction, | ||
initObject.isFixed, | ||
false, | ||
initObject.isThousandSeparator, | ||
@@ -603,0 +591,0 @@ initObject.thousandSeparator, |
@@ -1,1 +0,1 @@ | ||
!function(n,e,t){"use strict";function r(n,e,r,u){if(n===t||null===n||""===n)return 0;var i="";return i=","===e?String(n).replace(".",","):String(n),a(i,r,u)}function u(n,e,t){return","===e?String(n).replace(/['\.\s]/g,"").replace(",","."):"."===e?String(n).replace(/[',\s]/g,""):void 0}function a(n,e,t){var r=n;return t&&(r+=t),e&&(r=/^\-.+/.test(r)?r.replace("-","-"+e):/^\-/.test(r)?r:e+r),r}function i(n,e){if(n>=0){var t=parseInt(n,10);if(isNaN(t)===!1&&isFinite(t)&&t>=0)return t}return e}function o(n,e){if(n>=0){var t=parseInt(n,10);if(isNaN(t)===!1&&isFinite(t)&&t>=0)return t}return e}function c(n,e){return","===n?",":"."===n?".":e}function m(n,e){return"false"===n||n===!1?!1:"true"===n||n===!0?!0:e}function p(n,e){return"false"===n||n===!1?!1:"true"===n||n===!0?!0:e}function s(n,e){return"floor"===n?Math.floor:"ceil"===n?Math.ceil:"round"===n?Math.round:e}function d(n,e){return"false"===n||n===!1?!1:"true"===n||n===!0?!0:e}function f(n,e){return"false"===n||n===!1?!1:"true"===n||n===!0?!0:e}function g(n,e,t){if(!n)return t;var r;return r="."===e?new RegExp("^[',\\s]$"):new RegExp("^['\\.\\s]$"),r.test(n)?n:t}function l(n){var e=new RegExp("[^\\d,\\.\\s\\-]{1}");return e.test(n)?n:null}function h(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 S(n){return String(n).replace(/^0+/g,"").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 w(n,e){return"."===e?String(n).replace(/\./g,""):","===e?String(n).replace(/,/g,""):String(n).replace(new RegExp("['\\s]","g"),"")}function x(n,e,t){return n=String(n).split(e),n[0]=n[0].replace(/\B(?=(\d{3})+(?!\d))/g,t),n.join(e)}function $(n,e,t,r){n.$setViewValue(a(e,t,r)),n.$render()}function F(n,e,u,a,i,o,c,m,p){if(""===n||n===t||null===n)return"";if(n=Number(n),!isNaN(n)&&isFinite(n)){var s=Math.pow(10,e);return n=i?r((a(n*s)/s).toFixed(e),u,m,p):r(String(a(n*s)/s),u,m,p),o&&(n=x(n,u,c)),n}return i?0..toFixed(e):"0"}function R(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 T(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 N(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 P(n,e,t){var r={awnum:n.awnum,numFixed:n.numFixed,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};return e&&(r[e]=t),r}function y(n,e,r,u,a){var S={};n.awnum&&(S=a.getStrategy(n.awnum));var v=i(n.numInt!==t?n.numInt:S.numInt,6),w=d(n.numFixed!==t?n.numFixed:S.numFixed,!1),x=o(n.numFract!==t?n.numFract:S.numFract,2),$=c(n.numSep!==t?n.numSep:S.numSep,"."),F=m(n.numPos!==t?n.numPos:S.numPos,!0),R=p(n.numNeg!==t?n.numNeg:S.numNeg,!0),T=s(n.numRound!==t?n.numRound:S.numRound,Math.round),N=f(n.numThousand!==t?n.numThousand:S.numThousand,!1),P=g(n.numThousandSep!==t?n.numThousandSep:S.numThousandSep,$,"."===$?",":"."),y=l(n.numPrepend!==t?n.numPrepend:S.numPrepend),E=l(n.numAppend!==t?n.numAppend:S.numAppend);if(F===!1&&R===!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 b=h(v,x,$,F,R);return{element:e,attrs:r,ngModelController:u,viewRegexTest:b,isFixed:w,integerPart:v,fractionPart:x,fractionSeparator:$,isPositiveNumber:F,isNegativeNumber:R,roundFunction:T,isThousandSeparator:N,thousandSeparator:P,prepend:y,append:E}}function E(n,e){var a=e.element,i=(e.attrs,e.ngModelController),o=e.viewRegexTest,c=(e.integerPart,e.fractionPart),m=e.fractionSeparator,p=e.isPositiveNumber,s=e.isNegativeNumber,d=(e.roundFunction,e.isThousandSeparator),f=e.thousandSeparator,g=e.prepend,l=e.append,h=String(n);if(M){M=!1;var F=new RegExp("[^"+(s?"-":"")+m+f+"0-9]+","g");h=h.replace(F,""),F=new RegExp("^["+m+f+"]"),h=h.replace(F,""),F=new RegExp("["+m+f+"]([0-9]{"+c+"})$"),h=h.replace(F,m+"$1")}if(h=v(h,g,l),new RegExp("^[.,"+f+"]{2,}").test(h))return $(i,0,g,l),0;var P=R(a[0]);g&&P--;var y=h.slice(0,P);if(y=w(y,f),h=w(h,f),y=S(y),h=S(h),""===h&&"0"===String(n).charAt(0))return $(i,0,g,l),0;if(h===t||""===h)return 0;if("-"===h)return p&&!s?$(i,"",g,l):$(i,"-",g,l),0;if(o.test(h)===!1){var E=r(i.$modelValue,m,g,l);return d&&(E=x(E,m,f)),$(i,E,g,l),T(a[0],P-1),i.$modelValue}var b=0,A=y.length;return d&&(h=x(h,m,f),b=N(h,f,A)),g&&(b++,new RegExp("^(\\-\\d)$").test(h)&&(b+=2),new RegExp("^(\\d)$").test(h)&&b++),$(i,h,g,l),T(a[0],A+b),setTimeout(function(){T(a[0],A+b)},1),u(h,m,f)}function b(n,e){n.$setViewValue(""),n.$render(),n.$setViewValue(e),n.$render()}function A(n,e){var t=F(n.$modelValue,e.fractionPart,e.fractionSeparator,e.roundFunction,e.isFixed,e.isThousandSeparator,e.thousandSeparator,e.prepend,e.append);b(n,t)}function I(n){return{restrict:"A",require:"?ngModel",scope:{awnum:"@",numFixed:"@",numInt:"@",numFract:"@",numSep:"@",numPos:"@",numNeg:"@",numRound:"@",numThousand:"@",numThousandSep:"@",numPrepend:"@",numAppend:"@"},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=y(P(e),t,r,u,n);t.on("paste",function(){M=!0}),e.$watch("numFixed",function(i,o){o!==i&&(a=y(P(e,"numFixed",i),t,r,u,n),A(u,a))}),e.$watch("numInt",function(i,o){o!==i&&(a=y(P(e,"numInt",i),t,r,u,n),A(u,a))}),e.$watch("numFract",function(i,o){o!==i&&(a=y(P(e,"numFract",i),t,r,u,n),A(u,a))}),e.$watch("numSep",function(i,o){o!==i&&(a=y(P(e,"numSep",i),t,r,u,n),A(u,a))}),e.$watch("numPos",function(i,o){o!==i&&(a=y(P(e,"numPos",i),t,r,u,n),A(u,a))}),e.$watch("numNeg",function(i,o){o!==i&&(a=y(P(e,"numNeg",i),t,r,u,n),A(u,a))}),e.$watch("numThousand",function(i,o){o!==i&&(a=y(P(e,"numThousand",i),t,r,u,n),A(u,a))}),e.$watch("numThousandSep",function(i,o){o!==i&&(a=y(P(e,"numThousandSep",i),t,r,u,n),A(u,a))}),e.$watch("numAppend",function(i,o){o!==i&&(a=y(P(e,"numAppend",i),t,r,u,n),A(u,a))}),e.$watch("numPrepend",function(i,o){o!==i&&(a=y(P(e,"numPrepend",i),t,r,u,n),A(u,a))}),u.$parsers.unshift(function(n){return E(n,a)}),u.$formatters.push(function(n){return F(n,a.fractionPart,a.fractionSeparator,a.roundFunction,a.isFixed,a.isThousandSeparator,a.thousandSeparator,a.prepend,a.append)})}}}var M=!1;e.module("dynamicNumber",[]).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",function(n){return function(r,u,a,i,m,p,h,S,v){var w,x={};e.isString(u)&&(x=n.getStrategy(u),u=x.numFract);var w=o(u,2),$=c(a!==t?a:x.numSep,"."),R=s(i!==t?i:x.numRound,Math.round),T=d(m!==t?m:x.numFixed,!1),N=f(p!==t?p:x.numThousand,!1),P=g(h!==t?h:x.numThousandSep,$,"."===$?",":"."),y=l(S!==t?S:x.numPrepend),E=l(v!==t?v:x.numAppend),b=F(r,w,$,R,T,N,P,y,E);return""===b?"0":b}}).directive("awnum",["dynamicNumberStrategy",I])}(window,window.angular); | ||
!function(n,e,t){"use strict";function r(n,e,r,u){if(n===t||null===n||""===n)return 0;var o="";return o=","===e?String(n).replace(".",","):String(n),a(o,r,u)}function u(n,e,t){return","===e?String(n).replace(/['\.\s]/g,"").replace(",","."):"."===e?String(n).replace(/[',\s]/g,""):void 0}function a(n,e,t){var r=n;return t&&(r+=t),e&&(r=/^\-.+/.test(r)?r.replace("-","-"+e):/^\-/.test(r)?r:e+r),r}function o(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){if(n>=0){var t=parseInt(n,10);if(isNaN(t)===!1&&isFinite(t)&&t>=0)return t}return e}function c(n,e){return","===n?",":"."===n?".":e}function m(n,e){return"false"===n||n===!1?!1:"true"===n||n===!0?!0:e}function p(n,e){return"false"===n||n===!1?!1:"true"===n||n===!0?!0:e}function s(n,e){return"floor"===n?Math.floor:"ceil"===n?Math.ceil:"round"===n?Math.round:e}function d(n,e){return"false"===n||n===!1?!1:"true"===n||n===!0?!0:e}function f(n,e){return"false"===n||n===!1?!1:"true"===n||n===!0?!0:e}function g(n,e,t){if(!n)return t;var r;return r="."===e?new RegExp("^[',\\s]$"):new RegExp("^['\\.\\s]$"),r.test(n)?n:t}function l(n){var e=new RegExp("[^\\d,\\.\\s\\-]{1}");return e.test(n)?n:null}function h(n,e,t,r,u){var a="-?";r===!1&&u===!0?a="-":r===!0&&u===!1&&(a="");var o="[0-9]{0,"+n+"}";0===n&&(o="0");var i="(\\"+t+"([0-9]){0,"+e+"})";return 0===e&&(i=""),new RegExp("^"+a+o+i+"?$")}function S(n){return String(n).replace(/^0+/g,"").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 w(n,e){return"."===e?String(n).replace(/\./g,""):","===e?String(n).replace(/,/g,""):String(n).replace(new RegExp("['\\s]","g"),"")}function $(n,e,t){return n=String(n).split(e),n[0]=n[0].replace(/\B(?=(\d{3})+(?!\d))/g,t),n.join(e)}function R(n,e,t,r){n.$setViewValue(a(e,t,r)),n.$render()}function T(n,e,u,a,o,i,c,m,p){if(""===n||n===t||null===n)return"";if(n=Number(n),!isNaN(n)&&isFinite(n)){var s=Math.pow(10,e);return n=o?r((a(n*s)/s).toFixed(e),u,m,p):r(String(a(n*s)/s),u,m,p),i&&(n=$(n,u,c)),n}return o?0..toFixed(e):"0"}function N(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 P(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 x(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 F(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};return e&&(r[e]=t),r}function y(n,e,r,u,a){var d={};n.awnum&&(d=a.getStrategy(n.awnum));var S=o(n.numInt!==t?n.numInt:d.numInt,6),v=i(n.numFract!==t?n.numFract:d.numFract,2),w=c(n.numSep!==t?n.numSep:d.numSep,"."),$=m(n.numPos!==t?n.numPos:d.numPos,!0),R=p(n.numNeg!==t?n.numNeg:d.numNeg,!0),T=s(n.numRound!==t?n.numRound:d.numRound,Math.round),N=f(n.numThousand!==t?n.numThousand:d.numThousand,!1),P=g(n.numThousandSep!==t?n.numThousandSep:d.numThousandSep,w,"."===w?",":"."),x=l(n.numPrepend!==t?n.numPrepend:d.numPrepend),F=l(n.numAppend!==t?n.numAppend:d.numAppend);if($===!1&&R===!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=h(S,v,w,$,R);return{element:e,attrs:r,ngModelController:u,viewRegexTest:y,integerPart:S,fractionPart:v,fractionSeparator:w,isPositiveNumber:$,isNegativeNumber:R,roundFunction:T,isThousandSeparator:N,thousandSeparator:P,prepend:x,append:F}}function E(n,e){var a=e.element,o=(e.attrs,e.ngModelController),i=e.viewRegexTest,c=(e.integerPart,e.fractionPart),m=e.fractionSeparator,p=e.isPositiveNumber,s=e.isNegativeNumber,d=(e.roundFunction,e.isThousandSeparator),f=e.thousandSeparator,g=e.prepend,l=e.append,h=String(n);if(M){M=!1;var T=new RegExp("[^"+(s?"-":"")+m+f+"0-9]+","g");h=h.replace(T,""),T=new RegExp("^["+m+f+"]"),h=h.replace(T,""),T=new RegExp("["+m+f+"]([0-9]{"+c+"})$"),h=h.replace(T,m+"$1")}if(h=v(h,g,l),new RegExp("^[.,"+f+"]{2,}").test(h))return R(o,0,g,l),0;var F=N(a[0]);g&&F--;var y=h.slice(0,F);if(y=w(y,f),h=w(h,f),y=S(y),h=S(h),""===h&&"0"===String(n).charAt(0))return R(o,0,g,l),0;if(h===t||""===h)return 0;if("-"===h)return p&&!s?R(o,"",g,l):R(o,"-",g,l),0;if(i.test(h)===!1){var E=r(o.$modelValue,m,g,l);return d&&(E=$(E,m,f)),R(o,E,g,l),P(a[0],F-1),o.$modelValue}var b=0,A=y.length;return d&&(h=$(h,m,f),b=x(h,f,A)),g&&(b++,new RegExp("^(\\-\\d)$").test(h)&&(b+=2),new RegExp("^(\\d)$").test(h)&&b++),R(o,h,g,l),P(a[0],A+b),setTimeout(function(){P(a[0],A+b)},1),u(h,m,f)}function b(n,e){n.$setViewValue(""),n.$render(),n.$setViewValue(e),n.$render()}function A(n,e){var t=T(n.$modelValue,e.fractionPart,e.fractionSeparator,e.roundFunction,!1,e.isThousandSeparator,e.thousandSeparator,e.prepend,e.append);b(n,t)}function I(n){return{restrict:"A",require:"?ngModel",scope:{awnum:"@",numInt:"@",numFract:"@",numSep:"@",numPos:"@",numNeg:"@",numRound:"@",numThousand:"@",numThousandSep:"@",numPrepend:"@",numAppend:"@"},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=y(F(e),t,r,u,n);t.on("paste",function(){M=!0}),e.$watch("numInt",function(o,i){i!==o&&(a=y(F(e,"numInt",o),t,r,u,n),A(u,a))}),e.$watch("numFract",function(o,i){i!==o&&(a=y(F(e,"numFract",o),t,r,u,n),A(u,a))}),e.$watch("numSep",function(o,i){i!==o&&(a=y(F(e,"numSep",o),t,r,u,n),A(u,a))}),e.$watch("numPos",function(o,i){i!==o&&(a=y(F(e,"numPos",o),t,r,u,n),A(u,a))}),e.$watch("numNeg",function(o,i){i!==o&&(a=y(F(e,"numNeg",o),t,r,u,n),A(u,a))}),e.$watch("numThousand",function(o,i){i!==o&&(a=y(F(e,"numThousand",o),t,r,u,n),A(u,a))}),e.$watch("numThousandSep",function(o,i){i!==o&&(a=y(F(e,"numThousandSep",o),t,r,u,n),A(u,a))}),e.$watch("numAppend",function(o,i){i!==o&&(a=y(F(e,"numAppend",o),t,r,u,n),A(u,a))}),e.$watch("numPrepend",function(o,i){i!==o&&(a=y(F(e,"numPrepend",o),t,r,u,n),A(u,a))}),u.$parsers.unshift(function(n){return E(n,a)}),u.$formatters.push(function(n){return T(n,a.fractionPart,a.fractionSeparator,a.roundFunction,!1,a.isThousandSeparator,a.thousandSeparator,a.prepend,a.append)})}}}var M=!1;e.module("dynamicNumber",[]).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",function(n){return function(r,u,a,o,m,p,h,S,v){var w,$={};e.isString(u)&&($=n.getStrategy(u),u=$.numFract);var w=i(u,2),R=c(a!==t?a:$.numSep,"."),N=s(o!==t?o:$.numRound,Math.round),P=d(m!==t?m:$.numFixed,!1),x=f(p!==t?p:$.numThousand,!1),F=g(h!==t?h:$.numThousandSep,R,"."===R?",":"."),y=l(S!==t?S:$.numPrepend),E=l(v!==t?v:$.numAppend),b=T(r,w,R,N,P,x,F,y,E);return""===b?"0":b}}).directive("awnum",["dynamicNumberStrategy",I])}(window,window.angular); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84128
642