Socket
Socket
Sign inDemoInstall

angular-dynamic-number

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-dynamic-number - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

2

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

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

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

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

@@ -24,3 +24,5 @@ # Angular Dynamic Number [![Build Status](https://travis-ci.org/uhlryk/angular-dynamic-number.svg)](https://travis-ci.org/uhlryk/angular-dynamic-number)

- model value is correct javascript number, but view value may be correct number for localities
- dynamic thousand separator (if decimal separator is comma then thousand separator is dot)
- filter with comma/dot separator and congurable number of fraction digits
- filter with thousand separator
Edit contractors create new entry for contractor (old entries are for archive or for generate old invoices with old contractor data)

@@ -90,5 +92,9 @@ Delete contractors set entries as archive.

**num-thousand**:
If true then number has thousand separator.
## Filter options
{{ expression | awnum:numFrac:numSep:numRound:numFixed}}
{{ expression | awnum:numFrac:numSep:numRound:numFixed:numThousand}}

@@ -111,3 +117,6 @@ **numFrac**

**numThousand**
If true then number has thousand separator.
## Example:

@@ -114,0 +123,0 @@ Negative number with max value 9999.99 and comma as separator

@@ -12,5 +12,5 @@ /*jslint node: true */

if(viewSeparator === ',') {
return String(viewValue).replace(",",".");
return String(viewValue).replace(/\./g,"").replace(",",".");
} else {
return viewValue;
return String(viewValue).replace(/,/g,"");
}

@@ -78,2 +78,10 @@ }

}
function initIsThousand(attrs_thousand, def_thousand){
if(attrs_thousand === 'false') {
return false;
} else if(attrs_thousand === 'true') {
return true;
}
return def_thousand;
}
function buildRegexp(integerPart, fractionPart, fractionSeparator, isPositiveNumber, isNegativeNumber){

@@ -99,2 +107,12 @@ var negativeRegex = '-?';

}
function removeThousandSeparators(value, thousandSeparator){
if(thousandSeparator === '.') {
return value.replace(/\./g, "");
} else {
return value.replace(/,/g, "");
}
}
function addThousandSeparator(value, thousandSeparator){
return value.replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator);
}
function changeViewValue(ngModelController, value){

@@ -106,3 +124,3 @@ // https://github.com/angular/angular.js/issues/13068

}
function filterModelValue(value, fractionPart, fractionSeparator, roundFunction, numFixed){
function filterModelValue(value, fractionPart, fractionSeparator, roundFunction, numFixed, isThousandSeparator){
value = Number(value);

@@ -112,6 +130,10 @@ if(!isNaN(value) && isFinite(value)) {

if(numFixed) {
return convModelToView((roundFunction(value*powerOfTen)/powerOfTen).toFixed(fractionPart), fractionSeparator);
value = convModelToView((roundFunction(value*powerOfTen)/powerOfTen).toFixed(fractionPart), fractionSeparator);
} else {
return convModelToView(String(roundFunction(value*powerOfTen)/powerOfTen), fractionSeparator);
value = convModelToView(String(roundFunction(value*powerOfTen)/powerOfTen), fractionSeparator);
}
if(isThousandSeparator){
value = addThousandSeparator(value, fractionSeparator==='.'?',':'.');
}
return value;
}

@@ -134,3 +156,4 @@ if(numFixed) {

numNeg: "@",
numRound: "@"
numRound: "@",
numThousand: "@"
},

@@ -144,2 +167,4 @@ link: function(scope, element, attrs, ngModelController) {

var roundFunction = initRound(scope.numRound, Math.round);
var isThousandSeparator = initIsThousand(scope.numThousand, false);
if(isPositiveNumber === false && isNegativeNumber === false) {

@@ -151,3 +176,5 @@ 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 parsedValue = value;
parsedValue = removeThousandSeparators(parsedValue, fractionSeparator==='.'?',':'.');
parsedValue = removeLeadingZero(parsedValue);
if(parsedValue === '' && String(value).charAt(0)=== '0'){

@@ -169,3 +196,7 @@ changeViewValue(ngModelController, 0);

if(viewRegexTest.test(parsedValue) === false){
changeViewValue(ngModelController, convModelToView(ngModelController.$modelValue, fractionSeparator));
var modelValue = convModelToView(ngModelController.$modelValue, fractionSeparator);
if(isThousandSeparator){
modelValue = addThousandSeparator(modelValue, fractionSeparator==='.'?',':'.');
}
changeViewValue(ngModelController, modelValue);
return ngModelController.$modelValue;

@@ -178,2 +209,5 @@ }

else {
if(isThousandSeparator){
parsedValue = addThousandSeparator(parsedValue, fractionSeparator==='.'?',':'.');
}
changeViewValue(ngModelController, parsedValue);

@@ -187,3 +221,3 @@ return convViewToModel(parsedValue, fractionSeparator);

ngModelController.$formatters.push(function(value){
return filterModelValue(value, fractionPart, fractionSeparator, roundFunction);
return filterModelValue(value, fractionPart, fractionSeparator, roundFunction, false, isThousandSeparator);
});

@@ -197,3 +231,3 @@ }

function dynamicNumberFilter(){
return function(value, numFract, numSep, numRound, numFixed) {
return function(value, numFract, numSep, numRound, numFixed, numThousand) {
var fractionPart = initFractionPart(numFract, 2);

@@ -203,3 +237,4 @@ var fractionSeparator = initSeparator(numSep, '.');

var isFixed = initIsFixed(numFixed, false);
return filterModelValue(value, fractionPart, fractionSeparator, roundFunction, isFixed);
var isThousandSeparator = initIsThousand(numThousand, false);
return filterModelValue(value, fractionPart, fractionSeparator, roundFunction, isFixed, isThousandSeparator);
};

@@ -206,0 +241,0 @@ }

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

!function(n,r,t){"use strict";function e(n,r){return","===r?String(n).replace(".",","):n}function u(n,r){return","===r?String(n).replace(",","."):n}function i(n,r){if(n>=0){var t=parseInt(n,10);if(isNaN(t)===!1&&isFinite(t)&&t>=0)return t}return r}function o(n,r){if(n>=0){var t=parseInt(n,10);if(isNaN(t)===!1&&isFinite(t)&&t>=0)return t}return r}function a(n,r){return","===n?",":"."===n?".":r}function c(n,r){return"false"===n?!1:"true"===n?!0:r}function f(n,r){return"false"===n?!1:"true"===n?!0:r}function s(n,r){return"floor"===n?Math.floor:"ceil"===n?Math.ceil:"round"===n?Math.round:r}function m(n,r){return"false"===n?!1:"true"===n?!0:r}function l(n,r,t,e,u){var i="-?";e===!1&&u===!0?i="-":e===!0&&u===!1&&(i="");var o="[0-9]{0,"+n+"}";0===n&&(o="0");var a="(\\"+t+"([0-9]){0,"+r+"})";return 0===r&&(a=""),new RegExp("^"+i+o+a+"?$")}function d(n){return String(n).replace(/^0+/g,"").replace(/^-00+/g,"-0").replace(/-0+\[\.,]/,"-0$&").replace(/^[\.,]/g,"0$&")}function p(n,r){n.$setViewValue(r),n.$render()}function g(n,r,t,u,i){if(n=Number(n),!isNaN(n)&&isFinite(n)){var o=Math.pow(10,r);return i?e((u(n*o)/o).toFixed(r),t):e(String(u(n*o)/o),t)}return i?0..toFixed(r):"0"}function v(){return{restrict:"A",require:"?ngModel",scope:{numInt:"@",numFract:"@",numSep:"@",numPos:"@",numNeg:"@",numRound:"@"},link:function(n,r,m,v){var h=i(n.numInt,6),w=o(n.numFract,2),N=a(n.numSep,"."),$=c(n.numPos,!0),F=f(n.numNeg,!0),M=s(n.numRound,Math.round);if($===!1&&F===!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 S=l(h,w,N,$,F);v.$parsers.unshift(function(n){var r=n;return r=d(r),""===r&&"0"===String(n).charAt(0)?(p(v,0),0):r===t||""===r?0:"-"===r?(p(v,r),0):S.test(r)===!1?(p(v,e(v.$modelValue,N)),v.$modelValue):(p(v,r),u(r,N))}),v.$formatters.push(function(n){return g(n,w,N,M)})}}}function h(){return function(n,r,t,e,u){var i=o(r,2),c=a(t,"."),f=s(e,Math.round),l=m(u,!1);return g(n,i,c,f,l)}}r.module("dynamicNumber",[]).directive("awnum",v).filter("awnum",h)}(window,window.angular);
!function(n,r,e){"use strict";function t(n,r){return","===r?String(n).replace(".",","):n}function u(n,r){return","===r?String(n).replace(/\./g,"").replace(",","."):String(n).replace(/,/g,"")}function i(n,r){if(n>=0){var e=parseInt(n,10);if(isNaN(e)===!1&&isFinite(e)&&e>=0)return e}return r}function a(n,r){if(n>=0){var e=parseInt(n,10);if(isNaN(e)===!1&&isFinite(e)&&e>=0)return e}return r}function o(n,r){return","===n?",":"."===n?".":r}function c(n,r){return"false"===n?!1:"true"===n?!0:r}function f(n,r){return"false"===n?!1:"true"===n?!0:r}function s(n,r){return"floor"===n?Math.floor:"ceil"===n?Math.ceil:"round"===n?Math.round:r}function l(n,r){return"false"===n?!1:"true"===n?!0:r}function m(n,r){return"false"===n?!1:"true"===n?!0:r}function d(n,r,e,t,u){var i="-?";t===!1&&u===!0?i="-":t===!0&&u===!1&&(i="");var a="[0-9]{0,"+n+"}";0===n&&(a="0");var o="(\\"+e+"([0-9]){0,"+r+"})";return 0===r&&(o=""),new RegExp("^"+i+a+o+"?$")}function g(n){return String(n).replace(/^0+/g,"").replace(/^-00+/g,"-0").replace(/-0+\[\.,]/,"-0$&").replace(/^[\.,]/g,"0$&")}function p(n,r){return"."===r?n.replace(/\./g,""):n.replace(/,/g,"")}function v(n,r){return n.replace(/\B(?=(\d{3})+(?!\d))/g,r)}function h(n,r){n.$setViewValue(r),n.$render()}function w(n,r,e,u,i,a){if(n=Number(n),!isNaN(n)&&isFinite(n)){var o=Math.pow(10,r);return n=i?t((u(n*o)/o).toFixed(r),e):t(String(u(n*o)/o),e),a&&(n=v(n,"."===e?",":".")),n}return i?0..toFixed(r):"0"}function N(){return{restrict:"A",require:"?ngModel",scope:{numInt:"@",numFract:"@",numSep:"@",numPos:"@",numNeg:"@",numRound:"@",numThousand:"@"},link:function(n,r,l,N){var $=i(n.numInt,6),S=a(n.numFract,2),F=o(n.numSep,"."),M=c(n.numPos,!0),b=f(n.numNeg,!0),I=s(n.numRound,Math.round),V=m(n.numThousand,!1);if(M===!1&&b===!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 x=d($,S,F,M,b);N.$parsers.unshift(function(n){var r=n;if(r=p(r,"."===F?",":"."),r=g(r),""===r&&"0"===String(n).charAt(0))return h(N,0),0;if(r===e||""===r)return 0;if("-"===r)return h(N,r),0;if(x.test(r)===!1){var i=t(N.$modelValue,F);return V&&(i=v(i,"."===F?",":".")),h(N,i),N.$modelValue}return V&&(r=v(r,"."===F?",":".")),h(N,r),u(r,F)}),N.$formatters.push(function(n){return w(n,S,F,I,!1,V)})}}}function $(){return function(n,r,e,t,u,i){var c=a(r,2),f=o(e,"."),d=s(t,Math.round),g=l(u,!1),p=m(i,!1);return w(n,c,f,d,g,p)}}r.module("dynamicNumber",[]).directive("awnum",N).filter("awnum",$)}(window,window.angular);
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc