react-currency-input-field
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -0,1 +1,9 @@ | ||
# [0.10.0](https://github.com/cchanxzy/react-currency-input-field/compare/v0.9.0...v0.10.0) (2020-05-08) | ||
### Features | ||
* can parse abbreviated values k, m, b ([f588dcf](https://github.com/cchanxzy/react-currency-input-field/commit/f588dcfdb09e15eb4cf08bd8b777e162f65010f7)) | ||
* updated examples ([6a2db92](https://github.com/cchanxzy/react-currency-input-field/commit/6a2db9215098ec4a6a3fc8207998576d46e915ce)) | ||
# [0.9.0](https://github.com/cchanxzy/react-currency-input-field/compare/v0.8.4...v0.9.0) (2020-05-08) | ||
@@ -2,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var u=t[n]={i:n,l:!1,exports:{}};return e[n].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var u in e)r.d(n,u,function(t){return e[t]}.bind(null,u));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var u=n(r(1));t.default=u.default},function(e,t,r){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var u in t=arguments[r])Object.prototype.hasOwnProperty.call(t,u)&&(e[u]=t[u]);return e}).apply(this,arguments)},u=this&&this.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var u=0;for(n=Object.getOwnPropertySymbols(e);u<n.length;u++)t.indexOf(n[u])<0&&Object.prototype.propertyIsEnumerable.call(e,n[u])&&(r[n[u]]=e[n[u]])}return r},a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});var o=a(r(2)),l=r(3);t.CurrencyInput=function(e){var t=e.allowDecimals,r=void 0===t||t,a=e.id,i=e.name,c=e.className,f=e.decimalsLimit,s=void 0===f?2:f,d=e.defaultValue,p=e.disabled,m=void 0!==p&&p,v=e.onChange,b=e.placeholder,y=e.prefix,h=e.maxLength,g=u(e,["allowDecimals","id","name","className","decimalsLimit","defaultValue","disabled","onChange","placeholder","prefix","maxLength"]),O=d?l.formatValue(String(d),y):"",_=o.useState(O),j=_[0],x=_[1],P=o.useState(0),S=P[0],M=P[1],N=o.useRef(null);return o.useEffect((function(){N&&N.current&&N.current.setSelectionRange(S,S)}),[S,N,j]),o.default.createElement("input",n({type:"text",inputMode:"decimal",id:a,name:i,className:c,onChange:function(e){var t=e.target,n=t.selectionStart,u=t.value,a=l.cleanValue(u,r,s,y);if(!a)return v&&v(null,i),x("");if(l.checkIsValidNumber(a)){var o=l.formatValue(a,y);if(n){var c=n+(o.length-u.length)||1;M(c)}x(o)}v&&v(Number(a),i)},onFocus:function(){return j?j.length:0},placeholder:b,disabled:m,value:j,ref:N,maxLength:h},g))},t.default=t.CurrencyInput},function(e,t){e.exports=require("react")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.addCommas=function(e){return e.replace(/\B(?=(\d{3})+(?!\d))/g,",")},t.removeCommas=function(e){return e.replace(/,/g,"")},t.checkIsValidNumber=function(e){return!(Number(e)<0||isNaN(Number(e)))},t.cleanValue=function(e,r,n,u){var a=u?e.replace(u,""):e,o=t.removeCommas(a);if(o.includes(".")){var l=o.split("."),i=l[0],c=l[1];return""+i+(r?"."+(n?c.slice(0,n):c):"")}return o},t.formatValue=function(e,r){var n=e.split("."),u=n[0],a=n[1],o=r||"",l=e.includes(".")?"."+a:"";return""+o+t.addCommas(u)+l}}]); | ||
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var u=t[n]={i:n,l:!1,exports:{}};return e[n].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var u in e)r.d(n,u,function(t){return e[t]}.bind(null,u));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var u=n(r(1));t.default=u.default},function(e,t,r){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var u in t=arguments[r])Object.prototype.hasOwnProperty.call(t,u)&&(e[u]=t[u]);return e}).apply(this,arguments)},u=this&&this.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var u=0;for(n=Object.getOwnPropertySymbols(e);u<n.length;u++)t.indexOf(n[u])<0&&Object.prototype.propertyIsEnumerable.call(e,n[u])&&(r[n[u]]=e[n[u]])}return r},a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});var o=a(r(2)),i=r(3);t.CurrencyInput=function(e){var t=e.allowDecimals,r=void 0===t||t,a=e.id,l=e.name,c=e.className,f=e.decimalsLimit,s=void 0===f?2:f,d=e.defaultValue,p=e.disabled,m=void 0!==p&&p,b=e.onChange,v=e.placeholder,h=e.prefix,y=e.maxLength,g=u(e,["allowDecimals","id","name","className","decimalsLimit","defaultValue","disabled","onChange","placeholder","prefix","maxLength"]),_=d?i.formatValue(String(d),h):"",O=o.useState(_),j=O[0],S=O[1],x=o.useState(0),P=x[0],M=x[1],V=o.useRef(null);return o.useEffect((function(){V&&V.current&&V.current.setSelectionRange(P,P)}),[P,V,j]),o.default.createElement("input",n({type:"text",inputMode:"decimal",id:a,name:l,className:c,onChange:function(e){var t=e.target,n=t.selectionStart,u=t.value,a=i.cleanValue(u,r,s,h);if(!a)return b&&b(null,l),S("");if(i.checkIsValidNumber(a)){var o=i.formatValue(a,h);if(n){var c=n+(o.length-u.length)||1;M(c)}S(o)}b&&b(Number(a),l)},onFocus:function(){return j?j.length:0},placeholder:v,disabled:m,value:j,ref:V,maxLength:y},g))},t.default=t.CurrencyInput},function(e,t){e.exports=require("react")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(4);t.addCommas=function(e){return e.replace(/\B(?=(\d{3})+(?!\d))/g,",")},t.removeCommas=function(e){return e.replace(/,/g,"")},t.checkIsValidNumber=function(e){return!(Number(e)<0||isNaN(Number(e)))},t.cleanValue=function(e,r,u,a){var o=a?e.replace(a,""):e,i=t.removeCommas(o),l=n.parseAbbrValue(i)||i;if(String(l).includes(".")){var c=i.split("."),f=c[0],s=c[1];return""+f+(r?"."+(u?s.slice(0,u):s):"")}return String(l)},t.formatValue=function(e,r){var n=e.split("."),u=n[0],a=n[1],o=r||"",i=e.includes(".")?"."+a:"";return""+o+t.addCommas(u)+i}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.abbrValue=function(e,t){if(void 0===t&&(t=10),e>999){var r=(""+e).length,n=Math.pow,u=n(10,t);return r-=r%3,Math.round(e*u/n(10,r))/u+" kMGTPE"[r/3]}return String(e)};var n={k:1e3,m:1e6,b:1e9};t.parseAbbrValue=function(e){var t=e.match(/(\d+(.\d+)?)([kmb])$/i);if(t){var r=t[1],u=t[3],a=u?n[u.toLowerCase()]:null;if(r&&a)return Number(r)*a}}}]); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "react-currency-input-field", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "React <input /> component for formatting currency and numbers.", | ||
@@ -18,3 +18,3 @@ "files": [ | ||
"gh-predeploy": "NODE_ENV='dev' webpack --mode=development", | ||
"gh-deploy": "gh-pages -d dist", | ||
"gh-deploy": "yarn gh-predeploy && gh-pages -d dist", | ||
"ci": "yarn && yarn build", | ||
@@ -21,0 +21,0 @@ "codecov": "codecov", |
@@ -7,8 +7,11 @@ # React Currency Input Field Component | ||
- Allows abbreviations eg. 1k = 1,000 2.5m = 2,500,000 | ||
- Prefix option eg. £ or \$ | ||
- Can allow/disallow decimals | ||
- Automatically inserts comma separator | ||
- Only allows numbers | ||
- Only allows valid numbers | ||
- Lightweight and simple | ||
## Demo | ||
[Live Demo](https://cchanxzy.github.io/react-currency-input-field) | ||
@@ -42,4 +45,14 @@ | ||
Have a look in [`src/examples`](https://github.com/cchanxzy/react-currency-input-field/tree/master/src/examples) for more examples on implementing. | ||
Have a look in [`src/examples`](https://github.com/cchanxzy/react-currency-input-field/tree/master/src/examples) for more examples on implementing and validation. | ||
## Abbreviations | ||
It can parse values with abbreviations `k`, `m` and `b` | ||
Examples: | ||
- 1k = 1,000 | ||
- 2.5m = 2,500,000 | ||
- 3.456B = 3,456,000,000 | ||
## Props | ||
@@ -46,0 +59,0 @@ |
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
33365
11
95
75