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 1.4.1 to 1.5.0

2

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

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

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

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

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

- keeps cursor position
Edit contractors create new entry for contractor (old entries are for archive or for generate old invoices with old contractor data)
Delete contractors set entries as archive.
Add, list, show invoices
Generate pdf of invoice
- custom strategies

@@ -97,2 +94,37 @@ ## Limitations:

## Custom strategies
There are multiple options for configuration each input. If you don't like write each time same options, there is for you custom strategies.
You can in config file create multiple sets of configs, and use them in input file
To create custom strategy in config use ```dynamicNumberStrategyProvider```. It has methods:
addStrategy(strategyName, {
numInt: number,
numFract: number,
numSep: char [\.|,],
numPos: boolean [true|false],
numNeg: boolean [true|false],
numRound: string ['round' | 'ceil' | 'floor'],
numThousand: boolean [true|false]
})
for example, create price strategy:
app.config(['dynamicNumberStrategyProvider', function(dynamicNumberStrategyProvider){
dynamicNumberStrategyProvider.addStrategy('price', {
numInt: 6,
numFract: 2,
numSep: '.',
numPos: true,
numNeg: true,
numRound: 'round',
numThousand: true
});
}]);
and use it in input:
<input type="text" ng-model="somemodel" awnum="price">
## Filter options

@@ -125,3 +157,3 @@

<input type='text' ng-model='value4' awnum num-sep=','' num-int=4 num-fract=2 num-pos=false>
<input type='text' ng-model='value4' awnum num-sep=',' num-int=4 num-fract=2 num-pos=false>

@@ -128,0 +160,0 @@ Filter for number with max 3 fraction number and comma separator

@@ -189,3 +189,3 @@ /*jslint node: true */

}
function dynamicNumberDirective() {
function dynamicNumberDirective(dynamicNumberStrategy) {
return {

@@ -195,2 +195,3 @@ restrict:'A',

scope: {
awnum: "@",
numInt: "@",

@@ -290,3 +291,30 @@ numFract: "@",

}
angular.module('dynamicNumber',[]).directive('awnum', dynamicNumberDirective).filter('awnum', dynamicNumberFilter);
angular.module('dynamicNumber',[])
.provider('dynamicNumberStrategy', function() {
var strategies = {};
this.addStrategy = function(name, strategy){
strategies[name]=strategy;
};
this.getStrategy = function(name) {
return strategies[name];
};
this.$get = function(){
return {
getStrategy: function(name) {
return strategies[name];
}
};
};
})
.filter('awnum', function() {
return function(value, numFract, numSep, numRound, numFixed, numThousand) {
var fractionPart = initFractionPart(numFract, 2);
var fractionSeparator = initSeparator(numSep, '.');
var roundFunction = initRound(numRound, Math.round);
var isFixed = initIsFixed(numFixed, false);
var isThousandSeparator = initIsThousand(numThousand, false);
return filterModelValue(value, fractionPart, fractionSeparator, roundFunction, isFixed, isThousandSeparator);
};
})
.directive('awnum', ['dynamicNumberStrategy',dynamicNumberDirective]);
})(window,window.angular);

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

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

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc