Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dynamic-number

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynamic-number - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

3

example/app.js

@@ -59,4 +59,3 @@ /******/ (function(modules) { // webpackBootstrap

'use strict';Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var DynamicNumber=function(){function DynamicNumber(){_classCallCheck(this,DynamicNumber);this._separator='.';this._integer=10;this._fraction=10;this._positive=true;this._negative=true;this._regexp=this._buildRegexp();this._isThousand=false;this._thousand=null;}_createClass(DynamicNumber,[{key:'clone',value:function clone(){var other=new DynamicNumber();other._separator=this._separator;other._integer=this._integer;other._fraction=this._fraction;other._positive=this._positive;other._negative=this._negative;other._regexp=this._regexp;other._isThousand=this._isThousand;other._thousand=this._thousand;other._cursor=this._cursor;return other;}},{key:'calculateFromModel',value:function calculateFromModel(){var modelValue=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;return this._createViewValueFromModel(modelValue);}},{key:'calculateFromView',value:function calculateFromView(){var rawViewValue=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;var cursorPosition=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;this._rawViewValue=rawViewValue;this._newModelValue=0;this._newViewValue='';this._cursor=cursorPosition;var value=String(this._rawViewValue);value=this._removeThousandSeparator(value);value=this._removeLeadingZero(value);if(value===""&&String(this._rawViewValue).charAt(0)==="0"){return this._createCorrectResponse("0",0,1);}if(value===undefined||value===""){return this._createCorrectResponse("",0,0);}if(value==="-"){return this._createCorrectResponse("-",0,1);}//test fails, therefore we use old values
if(this._regexp.test(value)===false){return false;}else{return this._createCorrectResponse(this._createViewValueFromView(value),this._createModelValueFromView(value),this._calculateNewCursorPosition());}}},{key:'_createCorrectResponse',value:function _createCorrectResponse(view,model,cursor){return{view:view,model:model,cursor:cursor};}},{key:'_calculateThousandSeparator',/**
'use strict';Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var DynamicNumber=function(){function DynamicNumber(){_classCallCheck(this,DynamicNumber);this._separator='.';this._integer=10;this._fraction=10;this._positive=true;this._negative=true;this._regexp=this._buildRegexp();this._isThousand=false;this._thousand=null;}_createClass(DynamicNumber,[{key:'clone',value:function clone(){var other=new DynamicNumber();other._separator=this._separator;other._integer=this._integer;other._fraction=this._fraction;other._positive=this._positive;other._negative=this._negative;other._regexp=this._regexp;other._isThousand=this._isThousand;other._thousand=this._thousand;other._cursor=this._cursor;return other;}},{key:'calculateFromModel',value:function calculateFromModel(){var modelValue=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;return this._createViewValueFromModel(modelValue);}},{key:'calculateFromView',value:function calculateFromView(){var rawViewValue=arguments.length>0&&arguments[0]!==undefined?arguments[0]:0;var cursorPosition=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;this._rawViewValue=rawViewValue;this._newViewValue='';this._cursor=cursorPosition;var value=String(this._rawViewValue);value=this._removeThousandSeparator(value);value=this._removeLeadingZero(value);if(value===""&&String(this._rawViewValue).charAt(0)==="0"){return this._createCorrectResponse("0",0,1);}if(value===undefined||value===""){return this._createCorrectResponse("",0,0);}if(value==="-"){return this._createCorrectResponse("-",0,1);}if(this._regexp.test(value)===false){return this._createWrongResponse();}else{return this._createCorrectResponse(this._createViewValueFromView(value),this._createModelValueFromView(value),this._calculateNewCursorPosition());}}},{key:'_createCorrectResponse',value:function _createCorrectResponse(view,model,cursor){return{view:view,model:model,cursor:cursor};}},{key:'_createWrongResponse',value:function _createWrongResponse(){return false;}},{key:'_calculateThousandSeparator',/**
* private function which calculate thousand separator.

@@ -63,0 +62,0 @@ */value:function _calculateThousandSeparator(){if(this._thousand!==' '){if(this._separator==='.'){this._thousand=',';}else{this._thousand='.';}}}/**

{
"name": "dynamic-number",
"version": "0.2.0",
"version": "0.2.1",
"description": "Highly customizable module for numbers",

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

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

!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i=t();for(var r in i)("object"==typeof exports?exports:e)[r]=i[r]}}(this,function(){return function(e){function t(r){if(i[r])return i[r].exports;var s=i[r]={exports:{},id:r,loaded:!1};return e[r].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}var i={};return t.m=e,t.c=i,t.p="",t(0)}([function(e,t,i){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var s=i(1),a=r(s);t.default=a.default},function(e,t){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var i=0;i<t.length;i++){var r=t[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),s=function(){function e(){i(this,e),this._separator=".",this._integer=10,this._fraction=10,this._positive=!0,this._negative=!0,this._regexp=this._buildRegexp(),this._isThousand=!1,this._thousand=null}return r(e,[{key:"clone",value:function(){var t=new e;return t._separator=this._separator,t._integer=this._integer,t._fraction=this._fraction,t._positive=this._positive,t._negative=this._negative,t._regexp=this._regexp,t._isThousand=this._isThousand,t._thousand=this._thousand,t._cursor=this._cursor,t}},{key:"calculateFromModel",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this._createViewValueFromModel(e)}},{key:"calculateFromView",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this._rawViewValue=e,this._newModelValue=0,this._newViewValue="",this._cursor=t;var i=String(this._rawViewValue);return i=this._removeThousandSeparator(i),i=this._removeLeadingZero(i),""===i&&"0"===String(this._rawViewValue).charAt(0)?this._createCorrectResponse("0",0,1):void 0===i||""===i?this._createCorrectResponse("",0,0):"-"===i?this._createCorrectResponse("-",0,1):this._regexp.test(i)!==!1&&this._createCorrectResponse(this._createViewValueFromView(i),this._createModelValueFromView(i),this._calculateNewCursorPosition())}},{key:"_createCorrectResponse",value:function(e,t,i){return{view:e,model:t,cursor:i}}},{key:"_calculateThousandSeparator",value:function(){" "!==this._thousand&&("."===this._separator?this._thousand=",":this._thousand=".")}},{key:"_calculateNewCursorPosition",value:function(){var e=String(this._rawViewValue).slice(0,this._cursor);e=this._removeThousandSeparator(e),e=this._removeLeadingZero(e);var t=e.length;if(this._isThousand){var i=0,r=0,s=void 0,a=this._newViewValue.length;for(s=0;s<a;s++)if(this._newViewValue[s]!==this._thousand){if(i++,i>=t)break}else r++;t+=r}return t}},{key:"_buildRegexp",value:function(){var e="-?";this._positive===!1&&this._negative===!0?e="-":this._positive===!0&&this._negative===!1&&(e="");var t="[0-9]{0,"+this._integer+"}";0===this._integer&&(t="0");var i="(\\"+this._separator+"([0-9]){0,"+this._fraction+"})";return 0===this._fraction&&(i=""),new RegExp("^"+e+t+i+"?$")}},{key:"_removeLeadingZero",value:function(e){return e.replace(/^0+/g,"").replace(/^-0(\d+)/g,"-$1").replace(/^-([\.,])/,"-0$1").replace(/^[\.,]/g,"0$&")}},{key:"_removeThousandSeparator",value:function(e){return this._isThousand?e.replace(new RegExp("\\"+this._thousand,"g"),""):e}},{key:"_createModelValueFromView",value:function(e){return","===this._separator?parseFloat(e.replace(/\./g,"").replace(",",".")):parseFloat(e.replace(/,/g,""))}},{key:"_createViewValueFromView",value:function(e){return this._isThousand?(e=e.split(this._separator),e[0]=e[0].replace(/\B(?=(\d{3})+(?!\d))/g,this._thousand),e.join(this._separator)):e}},{key:"_createViewValueFromModel",value:function(e){var t=String(e);return this._isThousand?(t=t.split("."),t[0]=t[0].replace(/\B(?=(\d{3})+(?!\d))/g,this._thousand),t.join(this._separator)):t.replace(/\./g,this._separator)}},{key:"separator",set:function(e){this._separator="."===e||","===e?e:this._separator,this._regexp=this._buildRegexp(),this._calculateThousandSeparator()}},{key:"integer",set:function(e){if(e>=0){var t=parseInt(e,10);isNaN(t)===!1&&isFinite(t)&&t>=0&&(this._integer=t)}this._regexp=this._buildRegexp()}},{key:"fraction",set:function(e){if(e>=0){var t=parseInt(e,10);isNaN(t)===!1&&isFinite(t)&&t>=0&&(this._fraction=t)}this._regexp=this._buildRegexp()}},{key:"positive",set:function(e){e!==!0&&e!==!1||(this._positive=e),this._regexp=this._buildRegexp()}},{key:"negative",set:function(e){e!==!0&&e!==!1||(this._negative=e),this._regexp=this._buildRegexp()}},{key:"thousand",set:function(e){this._isThousand=e||" "===e," "===e&&(this._thousand=" "),this._calculateThousandSeparator()}},{key:"cursorPosition",get:function(){return this._cursor}}]),e}();t.default=s}])});
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i=t();for(var r in i)("object"==typeof exports?exports:e)[r]=i[r]}}(this,function(){return function(e){function t(r){if(i[r])return i[r].exports;var s=i[r]={exports:{},id:r,loaded:!1};return e[r].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}var i={};return t.m=e,t.c=i,t.p="",t(0)}([function(e,t,i){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var s=i(1),a=r(s);t.default=a.default},function(e,t){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var i=0;i<t.length;i++){var r=t[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),s=function(){function e(){i(this,e),this._separator=".",this._integer=10,this._fraction=10,this._positive=!0,this._negative=!0,this._regexp=this._buildRegexp(),this._isThousand=!1,this._thousand=null}return r(e,[{key:"clone",value:function(){var t=new e;return t._separator=this._separator,t._integer=this._integer,t._fraction=this._fraction,t._positive=this._positive,t._negative=this._negative,t._regexp=this._regexp,t._isThousand=this._isThousand,t._thousand=this._thousand,t._cursor=this._cursor,t}},{key:"calculateFromModel",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this._createViewValueFromModel(e)}},{key:"calculateFromView",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this._rawViewValue=e,this._newViewValue="",this._cursor=t;var i=String(this._rawViewValue);return i=this._removeThousandSeparator(i),i=this._removeLeadingZero(i),""===i&&"0"===String(this._rawViewValue).charAt(0)?this._createCorrectResponse("0",0,1):void 0===i||""===i?this._createCorrectResponse("",0,0):"-"===i?this._createCorrectResponse("-",0,1):this._regexp.test(i)===!1?this._createWrongResponse():this._createCorrectResponse(this._createViewValueFromView(i),this._createModelValueFromView(i),this._calculateNewCursorPosition())}},{key:"_createCorrectResponse",value:function(e,t,i){return{view:e,model:t,cursor:i}}},{key:"_createWrongResponse",value:function(){return!1}},{key:"_calculateThousandSeparator",value:function(){" "!==this._thousand&&("."===this._separator?this._thousand=",":this._thousand=".")}},{key:"_calculateNewCursorPosition",value:function(){var e=String(this._rawViewValue).slice(0,this._cursor);e=this._removeThousandSeparator(e),e=this._removeLeadingZero(e);var t=e.length;if(this._isThousand){var i=0,r=0,s=void 0,a=this._newViewValue.length;for(s=0;s<a;s++)if(this._newViewValue[s]!==this._thousand){if(i++,i>=t)break}else r++;t+=r}return t}},{key:"_buildRegexp",value:function(){var e="-?";this._positive===!1&&this._negative===!0?e="-":this._positive===!0&&this._negative===!1&&(e="");var t="[0-9]{0,"+this._integer+"}";0===this._integer&&(t="0");var i="(\\"+this._separator+"([0-9]){0,"+this._fraction+"})";return 0===this._fraction&&(i=""),new RegExp("^"+e+t+i+"?$")}},{key:"_removeLeadingZero",value:function(e){return e.replace(/^0+/g,"").replace(/^-0(\d+)/g,"-$1").replace(/^-([\.,])/,"-0$1").replace(/^[\.,]/g,"0$&")}},{key:"_removeThousandSeparator",value:function(e){return this._isThousand?e.replace(new RegExp("\\"+this._thousand,"g"),""):e}},{key:"_createModelValueFromView",value:function(e){return","===this._separator?parseFloat(e.replace(/\./g,"").replace(",",".")):parseFloat(e.replace(/,/g,""))}},{key:"_createViewValueFromView",value:function(e){return this._isThousand?(e=e.split(this._separator),e[0]=e[0].replace(/\B(?=(\d{3})+(?!\d))/g,this._thousand),e.join(this._separator)):e}},{key:"_createViewValueFromModel",value:function(e){var t=String(e);return this._isThousand?(t=t.split("."),t[0]=t[0].replace(/\B(?=(\d{3})+(?!\d))/g,this._thousand),t.join(this._separator)):t.replace(/\./g,this._separator)}},{key:"separator",set:function(e){this._separator="."===e||","===e?e:this._separator,this._regexp=this._buildRegexp(),this._calculateThousandSeparator()}},{key:"integer",set:function(e){if(e>=0){var t=parseInt(e,10);isNaN(t)===!1&&isFinite(t)&&t>=0&&(this._integer=t)}this._regexp=this._buildRegexp()}},{key:"fraction",set:function(e){if(e>=0){var t=parseInt(e,10);isNaN(t)===!1&&isFinite(t)&&t>=0&&(this._fraction=t)}this._regexp=this._buildRegexp()}},{key:"positive",set:function(e){e!==!0&&e!==!1||(this._positive=e),this._regexp=this._buildRegexp()}},{key:"negative",set:function(e){e!==!0&&e!==!1||(this._negative=e),this._regexp=this._buildRegexp()}},{key:"thousand",set:function(e){this._isThousand=e||" "===e," "===e&&(this._thousand=" "),this._calculateThousandSeparator()}},{key:"cursorPosition",get:function(){return this._cursor}}]),e}();t.default=s}])});

@@ -83,3 +83,2 @@ class DynamicNumber {

this._rawViewValue = rawViewValue;
this._newModelValue = 0;
this._newViewValue = '';

@@ -100,5 +99,5 @@ this._cursor = cursorPosition;

}
//test fails, therefore we use old values
if(this._regexp.test(value) === false){
return false;
return this._createWrongResponse();
}

@@ -122,2 +121,6 @@ else {

_createWrongResponse() {
return false;
}
get cursorPosition() {

@@ -124,0 +127,0 @@ return this._cursor;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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