react-currency-input-field
Advanced tools
Comparing version 2.2.0-beta.1 to 2.2.0-beta.2
@@ -0,1 +1,8 @@ | ||
# [2.2.0-beta.2](https://github.com/cchanxzy/react-currency-input-field/compare/v2.2.0-beta.1...v2.2.0-beta.2) (2020-08-20) | ||
### Features | ||
* fixed decimal length prop ([7089248](https://github.com/cchanxzy/react-currency-input-field/commit/70892489f5f62a914e5b26e2cb461e25076a1441)) | ||
# [2.2.0-beta.1](https://github.com/cchanxzy/react-currency-input-field/compare/v2.1.0...v2.2.0-beta.1) (2020-08-14) | ||
@@ -2,0 +9,0 @@ |
@@ -40,2 +40,6 @@ /// <reference types="react" /> | ||
/** | ||
* Value will always have the specified length of decimals | ||
*/ | ||
fixedDecimalLength?: number; | ||
/** | ||
* Handle change in value | ||
@@ -57,3 +61,3 @@ */ | ||
/** | ||
* Separator between integer part and fractional part of value. Can only be "," or "." | ||
* Separator between integer part and fractional part of value. Cannot be a number | ||
* | ||
@@ -64,3 +68,3 @@ * Default = "." | ||
/** | ||
* Separator between thousand, million and billion. Can only be "," or "." | ||
* Separator between thousand, million and billion. Cannot be a number | ||
* | ||
@@ -67,0 +71,0 @@ * Default = "," |
export * from './checkIsValidNumber'; | ||
export * from './cleanValue'; | ||
export * from './fixedDecimalValue'; | ||
export * from './formatValue'; | ||
export * from './padTrimValue'; |
@@ -1,2 +0,2 @@ | ||
module.exports=function(e){var r={};function t(a){if(r[a])return r[a].exports;var n=r[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,t),n.l=!0,n.exports}return t.m=e,t.c=r,t.d=function(e,r,a){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:a})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(t.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(a,n,function(r){return e[r]}.bind(null,n));return a},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=1)}([function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.escapeRegExp=void 0,r.escapeRegExp=function(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}},function(e,r,t){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0});var n=a(t(2));r.default=n.default},function(e,r,t){"use strict";var a=this&&this.__assign||function(){return(a=Object.assign||function(e){for(var r,t=1,a=arguments.length;t<a;t++)for(var n in r=arguments[t])Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n]);return e}).apply(this,arguments)},n=this&&this.__createBinding||(Object.create?function(e,r,t,a){void 0===a&&(a=t),Object.defineProperty(e,a,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,a){void 0===a&&(a=t),e[a]=r[t]}),o=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),u=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)"default"!==t&&Object.hasOwnProperty.call(e,t)&&n(r,e,t);return o(r,e),r},i=this&&this.__rest||function(e,r){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&r.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(a=Object.getOwnPropertySymbols(e);n<a.length;n++)r.indexOf(a[n])<0&&Object.prototype.propertyIsEnumerable.call(e,a[n])&&(t[a[n]]=e[a[n]])}return t};Object.defineProperty(r,"__esModule",{value:!0}),r.CurrencyInput=void 0;var l=u(t(3)),c=t(4);r.CurrencyInput=function(e){var r=e.allowDecimals,t=void 0===r||r,n=e.id,o=e.name,u=e.className,f=e.decimalsLimit,d=void 0===f?2:f,s=e.defaultValue,p=e.disabled,v=void 0!==p&&p,m=e.maxLength,b=e.value,g=e.onChange,h=e.placeholder,_=e.precision,y=e.prefix,O=e.decimalSeparator,S=void 0===O?".":O,j=e.groupSeparator,x=void 0===j?",":j,P=e.turnOffSeparators,V=void 0!==P&&P,M=i(e,["allowDecimals","id","name","className","decimalsLimit","defaultValue","disabled","maxLength","value","onChange","placeholder","precision","prefix","decimalSeparator","groupSeparator","turnOffSeparators"]);if(S===x)throw new Error("decimalSeparator cannot be the same as groupSeparator");if(c.checkIsValidNumber(S))throw new Error("decimalSeparator cannot be a number");if(c.checkIsValidNumber(x))throw new Error("groupSeparator cannot be a number");var w={decimalSeparator:S,groupSeparator:x,turnOffSeparators:V,prefix:y},N={decimalSeparator:S,groupSeparator:x,allowDecimals:t,decimalsLimit:d,prefix:y},E=s?c.formatValue(a({value:String(s)},w)):"",I=l.useState(E),L=I[0],k=I[1],C=l.useRef(null),R=b?c.formatValue(a({value:String(b)},w)):void 0;return l.default.createElement("input",a({type:"text",inputMode:"decimal",id:n,name:o,className:u,onChange:function(e){var r=e.target.value,t=c.cleanValue(a({value:r},N));if(!t)return g&&g(void 0,o),k("");var n=c.formatValue(a({value:t},w));k(n),g&&g(t,o)},onBlur:function(e){var r=e.target.value,t=c.cleanValue(a({value:r},N)),n=c.padTrimValue(t,S,_),u=c.formatValue(a({value:n},w));k(u),g&&g(n,o)},onFocus:function(){return L?L.length:0},placeholder:h,disabled:v,value:R||L,ref:C,maxLength:m},M))},r.default=r.CurrencyInput},function(e,r){e.exports=require("react")},function(e,r,t){"use strict";var a=this&&this.__createBinding||(Object.create?function(e,r,t,a){void 0===a&&(a=t),Object.defineProperty(e,a,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,a){void 0===a&&(a=t),e[a]=r[t]}),n=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||r.hasOwnProperty(t)||a(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),n(t(5),r),n(t(6),r),n(t(9),r),n(t(11),r)},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.checkIsValidNumber=void 0,r.checkIsValidNumber=function(e){return!(Number(e)<0||Number.isNaN(Number(e)))}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.cleanValue=void 0;var a=t(7),n=t(8);r.cleanValue=function(e){var r=e.value,t=e.decimalSeparator,o=e.groupSeparator,u=e.allowDecimals,i=e.decimalsLimit,l=e.prefix,c=l?r.replace(l,""):r,f=n.removeSeparators(c,o),d=a.parseAbbrValue(f,t)||f;if(String(d).includes(t)){var s=f.split(t),p=s[0],v=s[1],m=i?v.slice(0,i):v;return""+p+(u?""+t+m:"")}return String(d)}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.parseAbbrValue=r.abbrValue=void 0;var a=t(0);r.abbrValue=function(e,r,t){if(void 0===r&&(r="."),void 0===t&&(t=10),e>999){var a=(""+e).length,n=Math.pow,o=n(10,t);return a-=a%3,(Math.round(e*o/n(10,a))/o+" kMGTPE"[a/3]).replace(".",r)}return String(e)};var n={k:1e3,m:1e6,b:1e9};r.parseAbbrValue=function(e,r){void 0===r&&(r=".");var t=new RegExp("(\\d+("+a.escapeRegExp(r)+"\\d+)?)([kmb])$","i"),o=e.match(t);if(o){var u=o[1],i=o[3],l=i?n[i.toLowerCase()]:null;if(u&&l)return Number(u.replace(r,"."))*l}}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.removeSeparators=void 0;var a=t(0);r.removeSeparators=function(e,r){void 0===r&&(r=",");var t=new RegExp(a.escapeRegExp(r),"g");return e.replace(t,"")}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.formatValue=void 0;var a=t(10);r.formatValue=function(e){var r=e.value,t=e.decimalSeparator,n=e.groupSeparator,o=e.turnOffSeparators,u=e.prefix,i=r.split(t),l=i[0],c=i[1],f=u||"",d=r.includes(t)?""+t+c:"";return""+f+(o?l:a.addSeparators(l,n))+d}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.addSeparators=void 0,r.addSeparators=function(e,r){return void 0===r&&(r=","),e.replace(/\B(?=(\d{3})+(?!\d))/g,r)}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.padTrimValue=void 0,r.padTrimValue=function(e,r,t){if(void 0===r&&(r="."),!t)return e;var a=e.split(r),n=a[0],o=a[1]||"";if(o.length<t)for(;o.length<t;)o+="0";else o=o.slice(0,t);return""+n+r+o}}]); | ||
module.exports=function(e){var r={};function t(a){if(r[a])return r[a].exports;var n=r[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,t),n.l=!0,n.exports}return t.m=e,t.c=r,t.d=function(e,r,a){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:a})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(t.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)t.d(a,n,function(r){return e[r]}.bind(null,n));return a},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=1)}([function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.escapeRegExp=void 0,r.escapeRegExp=function(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}},function(e,r,t){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0});var n=a(t(2));r.default=n.default},function(e,r,t){"use strict";var a=this&&this.__assign||function(){return(a=Object.assign||function(e){for(var r,t=1,a=arguments.length;t<a;t++)for(var n in r=arguments[t])Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n]);return e}).apply(this,arguments)},n=this&&this.__createBinding||(Object.create?function(e,r,t,a){void 0===a&&(a=t),Object.defineProperty(e,a,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,a){void 0===a&&(a=t),e[a]=r[t]}),i=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),u=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)"default"!==t&&Object.hasOwnProperty.call(e,t)&&n(r,e,t);return i(r,e),r},o=this&&this.__rest||function(e,r){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&r.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(a=Object.getOwnPropertySymbols(e);n<a.length;n++)r.indexOf(a[n])<0&&Object.prototype.propertyIsEnumerable.call(e,a[n])&&(t[a[n]]=e[a[n]])}return t};Object.defineProperty(r,"__esModule",{value:!0}),r.CurrencyInput=void 0;var l=u(t(3)),c=t(4);r.CurrencyInput=function(e){var r=e.allowDecimals,t=void 0===r||r,n=e.id,i=e.name,u=e.className,f=e.decimalsLimit,d=e.defaultValue,s=e.disabled,p=void 0!==s&&s,v=e.maxLength,m=e.value,b=e.onChange,g=e.fixedDecimalLength,h=e.placeholder,_=e.precision,y=e.prefix,O=e.decimalSeparator,S=void 0===O?".":O,j=e.groupSeparator,x=void 0===j?",":j,P=e.turnOffSeparators,V=void 0!==P&&P,w=o(e,["allowDecimals","id","name","className","decimalsLimit","defaultValue","disabled","maxLength","value","onChange","fixedDecimalLength","placeholder","precision","prefix","decimalSeparator","groupSeparator","turnOffSeparators"]);if(S===x)throw new Error("decimalSeparator cannot be the same as groupSeparator");if(c.checkIsValidNumber(S))throw new Error("decimalSeparator cannot be a number");if(c.checkIsValidNumber(x))throw new Error("groupSeparator cannot be a number");var M={decimalSeparator:S,groupSeparator:x,turnOffSeparators:V,prefix:y},E={decimalSeparator:S,groupSeparator:x,allowDecimals:t,decimalsLimit:f||g||2,prefix:y},N=d?c.formatValue(a({value:String(d)},M)):"",D=l.useState(N),L=D[0],R=D[1],I=l.useRef(null),k=m?c.formatValue(a({value:String(m)},M)):void 0;return l.default.createElement("input",a({type:"text",inputMode:"decimal",id:n,name:i,className:u,onChange:function(e){var r=e.target.value,t=c.cleanValue(a({value:r},E));if(!t)return b&&b(void 0,i),R("");if(!(v&&t.length>v)){var n=c.formatValue(a({value:t},M));R(n),b&&b(t,i)}},onBlur:function(e){var r=e.target.value,t=c.cleanValue(a({value:r},E)),n=c.fixedDecimalValue(t,S,g),u=c.padTrimValue(n,S,_||g),o=c.formatValue(a({value:u},M));R(o),b&&b(u,i)},onFocus:function(){return L?L.length:0},placeholder:h,disabled:p,value:k||L,ref:I},w))},r.default=r.CurrencyInput},function(e,r){e.exports=require("react")},function(e,r,t){"use strict";var a=this&&this.__createBinding||(Object.create?function(e,r,t,a){void 0===a&&(a=t),Object.defineProperty(e,a,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,a){void 0===a&&(a=t),e[a]=r[t]}),n=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||r.hasOwnProperty(t)||a(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),n(t(5),r),n(t(6),r),n(t(9),r),n(t(10),r),n(t(12),r)},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.checkIsValidNumber=void 0,r.checkIsValidNumber=function(e){return!(Number(e)<0||Number.isNaN(Number(e)))}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.cleanValue=void 0;var a=t(7),n=t(8);r.cleanValue=function(e){var r=e.value,t=e.decimalSeparator,i=e.groupSeparator,u=e.allowDecimals,o=e.decimalsLimit,l=e.prefix,c=l?r.replace(l,""):r,f=n.removeSeparators(c,i),d=a.parseAbbrValue(f,t)||f;if(String(d).includes(t)){var s=f.split(t),p=s[0],v=s[1],m=o?v.slice(0,o):v;return""+p+(u?""+t+m:"")}return String(d)}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.parseAbbrValue=r.abbrValue=void 0;var a=t(0);r.abbrValue=function(e,r,t){if(void 0===r&&(r="."),void 0===t&&(t=10),e>999){var a=(""+e).length,n=Math.pow,i=n(10,t);return a-=a%3,(Math.round(e*i/n(10,a))/i+" kMGTPE"[a/3]).replace(".",r)}return String(e)};var n={k:1e3,m:1e6,b:1e9};r.parseAbbrValue=function(e,r){void 0===r&&(r=".");var t=new RegExp("(\\d+("+a.escapeRegExp(r)+"\\d+)?)([kmb])$","i"),i=e.match(t);if(i){var u=i[1],o=i[3],l=o?n[o.toLowerCase()]:null;if(u&&l)return Number(u.replace(r,"."))*l}}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.removeSeparators=void 0;var a=t(0);r.removeSeparators=function(e,r){void 0===r&&(r=",");var t=new RegExp(a.escapeRegExp(r),"g");return e.replace(t,"")}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.fixedDecimalValue=void 0,r.fixedDecimalValue=function(e,r,t){if(t&&e.length>1){if(e.includes(r)){var a=e.split(r),n=a[0];if((i=a[1]).length>t)return""+n+r+i.slice(0,t)}var i,u=e.length>t?new RegExp("(\\d+)(\\d{"+t+"})"):new RegExp("(\\d)(\\d+)"),o=e.match(u);if(o)return""+(n=o[1])+r+(i=o[2])}return e}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.formatValue=void 0;var a=t(11);r.formatValue=function(e){var r=e.value,t=e.decimalSeparator,n=e.groupSeparator,i=e.turnOffSeparators,u=e.prefix,o=r.split(t),l=o[0],c=o[1],f=u||"",d=r.includes(t)?""+t+c:"";return""+f+(i?l:a.addSeparators(l,n))+d}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.addSeparators=void 0,r.addSeparators=function(e,r){return void 0===r&&(r=","),e.replace(/\B(?=(\d{3})+(?!\d))/g,r)}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.padTrimValue=void 0,r.padTrimValue=function(e,r,t){if(void 0===r&&(r="."),!t)return e;var a=e.split(r),n=a[0],i=a[1]||"";if(i.length<t)for(;i.length<t;)i+="0";else i=i.slice(0,t);return""+n+r+i}}]); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "react-currency-input-field", | ||
"version": "2.2.0-beta.1", | ||
"version": "2.2.0-beta.2", | ||
"description": "React <input /> component for formatting currency and numbers.", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -77,20 +77,34 @@ # React Currency Input Field Component | ||
## Fixed Decimal Length | ||
Use `fixedDecimalLength` so that the value will always have the specified length of decimals. | ||
Example if `fixedDecimalLength` was 2: | ||
```md | ||
- 1 -> 1.00 | ||
- 123 -> 1.23 | ||
- 12.3 -> 12.30 | ||
- 12.34 -> 12.34 | ||
``` | ||
## Props | ||
| Name | Type | Default | Description | | ||
| ----------------- | ---------- | ------- | ------------------------------------------------------------------------ | | ||
| allowDecimals | `boolean` | `true` | Allow decimals | | ||
| className | `string` | | Class names | | ||
| decimalsLimit | `number` | `2` | Limit length of decimals allowed | | ||
| defaultValue | `number` | | Default value | | ||
| disabled | `boolean` | `false` | Disabled | | ||
| id | `string` | | Component id | | ||
| maxLength | `number` | | Maximum characters the user can enter | | ||
| onChange | `function` | | Handle change in value | | ||
| placeholder | `string` | | Placeholder if no value | | ||
| precision | `number` | | Specify decimal precision for padding/trimming | | ||
| prefix | `string` | | Include a prefix eg. £ or \$ | | ||
| decimalSeparator | `string` | `.` | Separator between integer part and fractional part of value | | ||
| groupSeparator | `string` | `,` | Separator between thousand, million and billion | | ||
| turnOffSeparators | `boolean` | `false` | Disable auto adding the group separator between values, eg. 1000 > 1,000 | | ||
| Name | Type | Default | Description | | ||
| ------------------ | ---------- | ------- | ------------------------------------------------------------------------ | | ||
| allowDecimals | `boolean` | `true` | Allow decimals | | ||
| className | `string` | | Class names | | ||
| decimalsLimit | `number` | `2` | Limit length of decimals allowed | | ||
| defaultValue | `number` | | Default value | | ||
| disabled | `boolean` | `false` | Disabled | | ||
| fixedDecimalLength | `number` | | Value will always have the specified length of decimals | | ||
| id | `string` | | Component id | | ||
| maxLength | `number` | | Maximum characters the user can enter | | ||
| onChange | `function` | | Handle change in value | | ||
| placeholder | `string` | | Placeholder if no value | | ||
| precision | `number` | | Specify decimal precision for padding/trimming | | ||
| prefix | `string` | | Include a prefix eg. £ or \$ | | ||
| decimalSeparator | `string` | `.` | Separator between integer part and fractional part of value | | ||
| groupSeparator | `string` | `,` | Separator between thousand, million and billion | | ||
| turnOffSeparators | `boolean` | `false` | Disable auto adding the group separator between values, eg. 1000 > 1,000 | | ||
@@ -97,0 +111,0 @@ ## Issues |
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
49285
19
170
113