react-currency-input-field
Advanced tools
Comparing version 3.0.0-beta.9 to 3.0.0-beta.10
@@ -0,1 +1,8 @@ | ||
# [3.0.0-beta.10](https://github.com/cchanxzy/react-currency-input-field/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-01-02) | ||
### Features | ||
* allow customInput prop ([f372201](https://github.com/cchanxzy/react-currency-input-field/commit/f3722015650c24efd522f93dfb8a482bc4ba87a4)) | ||
# [3.0.0-beta.9](https://github.com/cchanxzy/react-currency-input-field/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-01-02) | ||
@@ -2,0 +9,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Ref } from 'react'; | ||
import { Ref, ElementType } from 'react'; | ||
declare type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U; | ||
@@ -33,2 +33,8 @@ export declare type IntlConfig = { | ||
/** | ||
* Custom component | ||
* | ||
* Default = <input/> | ||
*/ | ||
customInput?: ElementType; | ||
/** | ||
* Limit length of decimals allowed | ||
@@ -35,0 +41,0 @@ * |
@@ -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=3)}([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.__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.__spreadArrays||function(){for(var e=0,r=0,t=arguments.length;r<t;r++)e+=arguments[r].length;var a=Array(e),n=0;for(r=0;r<t;r++)for(var o=arguments[r],i=0,u=o.length;i<u;i++,n++)a[n]=o[i];return a};Object.defineProperty(r,"__esModule",{value:!0}),r.formatValue=void 0;var o=t(0),i=t(2);r.formatValue=function(e){var r=e.value,t=e.decimalSeparator,n=e.intlConfig,c=e.prefix,f=void 0===c?"":c;if(""===r||void 0===r)return"";if("-"===r)return"-";var p=new RegExp("^\\d?-"+(f?o.escapeRegExp(f)+"?":"")+"\\d").test(r),s="."!==t?u(r,t,p):r,d=(n?new Intl.NumberFormat(n.locale,{style:"currency",currency:n.currency,minimumFractionDigits:0,maximumFractionDigits:20}):new Intl.NumberFormat(void 0,{minimumFractionDigits:0,maximumFractionDigits:20})).formatToParts(Number(s)),v=l(d,e);n||(v=p?v.replace(/^-/g,"-"+f):""+f+v);var g=i.getSuffix(v,a({},e)),m=r.slice(-1)===t?t:"",b=(s.match(RegExp("\\d+\\.(\\d+)"))||[])[1];return b&&t&&(v=v.includes(t)?v.replace(RegExp("(\\d+)("+o.escapeRegExp(t)+")(\\d+)","g"),"$1$2"+b):g?v.replace(g,""+t+b+g):""+v+t+b),g&&m?v.replace(g,""+m+g):[v,m].join("")};var u=function(e,r,t){var a=e;return r&&"."!==r&&(a=a.replace(RegExp(o.escapeRegExp(r),"g"),"."),t&&"-"===r&&(a="-"+a.slice(1))),a},l=function(e,r){var t=r.prefix,a=r.groupSeparator,o=r.decimalSeparator,i=r.disableGroupSeparators,u=void 0!==i&&i;return e.reduce((function(e,r){var i=r.type,l=r.value;return"currency"===i&&t?n(e,[t]):"group"===i?u?e:n(e,[void 0!==a?a:l]):n(e,"decimal"===i?[void 0!==o?o:l]:[l])}),[""]).join("")}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.getSuffix=void 0;var a=t(0);r.getSuffix=function(e,r){var t=r.groupSeparator,n=void 0===t?",":t,o=r.decimalSeparator,i=void 0===o?".":o,u=new RegExp("\\d([^"+a.escapeRegExp(n)+a.escapeRegExp(i)+"0-9].)"),l=e.match(u);return l?l[1]:void 0}},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(4));r.default=n.default;var o=t(1);Object.defineProperty(r,"formatValue",{enumerable:!0,get:function(){return o.formatValue}})},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}),i=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},u=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=i(t(5)),c=t(6);r.CurrencyInput=l.forwardRef((function(e,r){var t=e.allowDecimals,n=void 0===t||t,o=e.allowNegativeValue,i=void 0===o||o,f=e.id,p=e.name,s=e.className,d=e.decimalsLimit,v=e.defaultValue,g=e.disabled,m=void 0!==g&&g,b=e.maxLength,y=e.value,h=e.onValueChange,S=e.fixedDecimalLength,_=e.placeholder,x=e.decimalScale,O=e.prefix,w=e.intlConfig,j=e.step,P=e.disableGroupSeparators,V=void 0!==P&&P,E=e.disableAbbreviations,R=void 0!==E&&E,M=e.decimalSeparator,C=e.groupSeparator,D=e.onChange,N=e.onFocus,A=e.onBlur,I=e.onKeyDown,L=e.onKeyUp,F=u(e,["allowDecimals","allowNegativeValue","id","name","className","decimalsLimit","defaultValue","disabled","maxLength","value","onValueChange","fixedDecimalLength","placeholder","decimalScale","prefix","intlConfig","step","disableGroupSeparators","disableAbbreviations","decimalSeparator","groupSeparator","onChange","onFocus","onBlur","onKeyDown","onKeyUp"]);if(M&&C&&M===C)throw new Error("decimalSeparator cannot be the same as groupSeparator");if(M&&c.isNumber(M))throw new Error("decimalSeparator cannot be a number");if(C&&c.isNumber(C))throw new Error("groupSeparator cannot be a number");var T=l.useMemo((function(){return c.getLocaleConfig(w)}),[w]),K=M||T.decimalSeparator||"",k=C||T.groupSeparator||"",B={decimalSeparator:K,groupSeparator:k,disableGroupSeparators:V,intlConfig:w,prefix:O},G={decimalSeparator:K,groupSeparator:k,allowDecimals:n,decimalsLimit:d||S||2,allowNegativeValue:i,disableAbbreviations:R,prefix:O},U=void 0!==v?c.formatValue(a({value:String(v)},B)):void 0!==y?c.formatValue(a({value:String(y)},B)):"",$=l.useState(U),q=$[0],z=$[1],H=l.useState(0),J=H[0],Q=H[1],W=r||l.useRef(null),X=function(e,r){var t=c.cleanValue(a({value:e},G));if(""===t)return h&&h(void 0,p),void z("");if(!(b&&t.replace(/-/g,"").length>b)){if("-"===t)return h&&h(void 0,p),void z(e);var n=c.formatValue(a({value:t},B));if(null!=r){var o=r+(n.length-e.length)||1;Q(o)}z(n),h&&h(t,p)}};l.useEffect((function(){W&&"object"==typeof W&&W.current&&W.current.setSelectionRange(J,J)}),[J,W]);var Y=void 0!==y?c.formatValue(a(a({},B),{value:String(y)})):void 0;return l.default.createElement("input",a({type:"text",inputMode:"decimal",id:f,name:p,className:s,onChange:function(e){var r=e.target,t=r.value,a=r.selectionStart;X(t,a),D&&D(e)},onBlur:function(e){var r=e.target.value,t=c.cleanValue(a({value:r},G));if("-"===t||!t)return z(""),void(A&&A(e));var n=c.fixedDecimalValue(t,K,S),o=c.padTrimValue(n,K,x||S);h&&h(o,p);var i=c.formatValue(a(a({},B),{value:o}));z(i),A&&A(e)},onFocus:function(e){return N&&N(e),q?q.length:0},onKeyDown:function(e){var r=e.key;if(j&&("ArrowUp"===r||"ArrowDown"===r)){e.preventDefault();var t=Number(void 0!==y?y:c.cleanValue(a({value:q},G)))||0;X(String("ArrowUp"===r?t+j:t-j))}I&&I(e)},onKeyUp:function(e){var r=e.currentTarget.selectionStart,t=c.getSuffix(q,{groupSeparator:k,decimalSeparator:K});if(t&&r&&r>q.length-t.length&&W&&"object"==typeof W&&W.current){var a=q.length-t.length;W.current.setSelectionRange(a,a)}L&&L(e)},placeholder:_,disabled:m,value:void 0!==Y&&"-"!==q?Y:q,ref:W},F))})),r.CurrencyInput.displayName="CurrencyInput",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(7),r),n(t(11),r),n(t(1),r),n(t(12),r),n(t(2),r),n(t(13),r),n(t(14),r)},function(e,r,t){"use strict";var a=this&&this.__spreadArrays||function(){for(var e=0,r=0,t=arguments.length;r<t;r++)e+=arguments[r].length;var a=Array(e),n=0;for(r=0;r<t;r++)for(var o=arguments[r],i=0,u=o.length;i<u;i++,n++)a[n]=o[i];return a};Object.defineProperty(r,"__esModule",{value:!0}),r.cleanValue=void 0;var n=t(8),o=t(9),i=t(10),u=t(0);r.cleanValue=function(e){var r=e.value,t=e.groupSeparator,l=void 0===t?",":t,c=e.decimalSeparator,f=void 0===c?".":c,p=e.allowDecimals,s=void 0===p||p,d=e.decimalsLimit,v=void 0===d?2:d,g=e.allowNegativeValue,m=void 0===g||g,b=e.disableAbbreviations,y=void 0!==b&&b,h=e.prefix,S=void 0===h?"":h;if("-"===r)return r;var _=y?[]:["k","m","b"],x=new RegExp("^\\d?-"+(S?u.escapeRegExp(S)+"?":"")+"\\d").test(r),O=RegExp("(\\d+)-?"+u.escapeRegExp(S)).exec(r)||[],w=O[0],j=O[1],P=S?r.replace(w,"").concat(j):r,V=o.removeSeparators(P,l),E=i.removeInvalidChars(V,a([l,f],_)),R=E;if(!y){if(_.some((function(e){return e===E.toLowerCase()})))return"";var M=n.parseAbbrValue(E,f);M&&(R=String(M))}var C=x&&m?"-":"";if(f&&R.includes(f)){var D=E.split(f),N=D[0],A=D[1],I=v&&A?A.slice(0,v):A;return""+C+N+(s?""+f+I:"")}return""+C+R}},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 i=o[1],u=o[3],l=n[u.toLowerCase()];return Number(i.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.removeInvalidChars=void 0;var a=t(0);r.removeInvalidChars=function(e,r){var t=a.escapeRegExp(r.join("")),n=new RegExp("[^\\d"+t+"]","gi");return e.replace(n,"")}},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((o=a[1]).length>t)return""+n+r+o.slice(0,t)}var o,i=e.length>t?new RegExp("(\\d+)(\\d{"+t+"})"):new RegExp("(\\d)(\\d+)"),u=e.match(i);if(u)return""+(n=u[1])+r+(o=u[2])}return e}},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)};Object.defineProperty(r,"__esModule",{value:!0}),r.getLocaleConfig=void 0;var n={currencySymbol:"",groupSeparator:"",decimalSeparator:""};r.getLocaleConfig=function(e){var r=e||{},t=r.locale,o=r.currency;return(t&&o?new Intl.NumberFormat(t,{currency:o,style:"currency"}):new Intl.NumberFormat).formatToParts(1000.1).reduce((function(e,r){return"currency"===r.type?a(a({},e),{currencySymbol:r.value}):"group"===r.type?a(a({},e),{groupSeparator:r.value}):"decimal"===r.type?a(a({},e),{decimalSeparator:r.value}):e}),n)}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.isNumber=void 0,r.isNumber=function(e){return RegExp(/\d/,"gi").test(e)}},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||""===e||void 0===e)return e;if(!e.match(/\d/g))return"";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=3)}([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.__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.__spreadArrays||function(){for(var e=0,r=0,t=arguments.length;r<t;r++)e+=arguments[r].length;var a=Array(e),n=0;for(r=0;r<t;r++)for(var o=arguments[r],i=0,u=o.length;i<u;i++,n++)a[n]=o[i];return a};Object.defineProperty(r,"__esModule",{value:!0}),r.formatValue=void 0;var o=t(0),i=t(2);r.formatValue=function(e){var r=e.value,t=e.decimalSeparator,n=e.intlConfig,c=e.prefix,f=void 0===c?"":c;if(""===r||void 0===r)return"";if("-"===r)return"-";var p=new RegExp("^\\d?-"+(f?o.escapeRegExp(f)+"?":"")+"\\d").test(r),s="."!==t?u(r,t,p):r,d=(n?new Intl.NumberFormat(n.locale,{style:"currency",currency:n.currency,minimumFractionDigits:0,maximumFractionDigits:20}):new Intl.NumberFormat(void 0,{minimumFractionDigits:0,maximumFractionDigits:20})).formatToParts(Number(s)),v=l(d,e);n||(v=p?v.replace(/^-/g,"-"+f):""+f+v);var g=i.getSuffix(v,a({},e)),m=r.slice(-1)===t?t:"",b=(s.match(RegExp("\\d+\\.(\\d+)"))||[])[1];return b&&t&&(v=v.includes(t)?v.replace(RegExp("(\\d+)("+o.escapeRegExp(t)+")(\\d+)","g"),"$1$2"+b):g?v.replace(g,""+t+b+g):""+v+t+b),g&&m?v.replace(g,""+m+g):[v,m].join("")};var u=function(e,r,t){var a=e;return r&&"."!==r&&(a=a.replace(RegExp(o.escapeRegExp(r),"g"),"."),t&&"-"===r&&(a="-"+a.slice(1))),a},l=function(e,r){var t=r.prefix,a=r.groupSeparator,o=r.decimalSeparator,i=r.disableGroupSeparators,u=void 0!==i&&i;return e.reduce((function(e,r){var i=r.type,l=r.value;return"currency"===i&&t?n(e,[t]):"group"===i?u?e:n(e,[void 0!==a?a:l]):n(e,"decimal"===i?[void 0!==o?o:l]:[l])}),[""]).join("")}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.getSuffix=void 0;var a=t(0);r.getSuffix=function(e,r){var t=r.groupSeparator,n=void 0===t?",":t,o=r.decimalSeparator,i=void 0===o?".":o,u=new RegExp("\\d([^"+a.escapeRegExp(n)+a.escapeRegExp(i)+"0-9].)"),l=e.match(u);return l?l[1]:void 0}},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(4));r.default=n.default;var o=t(1);Object.defineProperty(r,"formatValue",{enumerable:!0,get:function(){return o.formatValue}})},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}),i=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},u=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=i(t(5)),c=t(6);r.CurrencyInput=l.forwardRef((function(e,r){var t=e.allowDecimals,n=void 0===t||t,o=e.allowNegativeValue,i=void 0===o||o,f=e.id,p=e.name,s=e.className,d=e.customInput,v=e.decimalsLimit,g=e.defaultValue,m=e.disabled,b=void 0!==m&&m,y=e.maxLength,h=e.value,S=e.onValueChange,_=e.fixedDecimalLength,x=e.placeholder,O=e.decimalScale,w=e.prefix,j=e.intlConfig,P=e.step,E=e.disableGroupSeparators,V=void 0!==E&&E,R=e.disableAbbreviations,M=void 0!==R&&R,C=e.decimalSeparator,D=e.groupSeparator,N=e.onChange,I=e.onFocus,A=e.onBlur,L=e.onKeyDown,F=e.onKeyUp,T=u(e,["allowDecimals","allowNegativeValue","id","name","className","customInput","decimalsLimit","defaultValue","disabled","maxLength","value","onValueChange","fixedDecimalLength","placeholder","decimalScale","prefix","intlConfig","step","disableGroupSeparators","disableAbbreviations","decimalSeparator","groupSeparator","onChange","onFocus","onBlur","onKeyDown","onKeyUp"]);if(C&&D&&C===D)throw new Error("decimalSeparator cannot be the same as groupSeparator");if(C&&c.isNumber(C))throw new Error("decimalSeparator cannot be a number");if(D&&c.isNumber(D))throw new Error("groupSeparator cannot be a number");var K=l.useMemo((function(){return c.getLocaleConfig(j)}),[j]),k=C||K.decimalSeparator||"",B=D||K.groupSeparator||"",G={decimalSeparator:k,groupSeparator:B,disableGroupSeparators:V,intlConfig:j,prefix:w},U={decimalSeparator:k,groupSeparator:B,allowDecimals:n,decimalsLimit:v||_||2,allowNegativeValue:i,disableAbbreviations:M,prefix:w},$=void 0!==g?c.formatValue(a({value:String(g)},G)):void 0!==h?c.formatValue(a({value:String(h)},G)):"",q=l.useState($),z=q[0],H=q[1],J=l.useState(0),Q=J[0],W=J[1],X=r||l.useRef(null),Y=function(e,r){var t=c.cleanValue(a({value:e},U));if(""===t)return S&&S(void 0,p),void H("");if(!(y&&t.replace(/-/g,"").length>y)){if("-"===t)return S&&S(void 0,p),void H(e);var n=c.formatValue(a({value:t},G));if(null!=r){var o=r+(n.length-e.length)||1;W(o)}H(n),S&&S(t,p)}};l.useEffect((function(){X&&"object"==typeof X&&X.current&&X.current.setSelectionRange(Q,Q)}),[Q,X]);var Z=void 0!==h?c.formatValue(a(a({},G),{value:String(h)})):void 0,ee=a({type:"text",inputMode:"decimal",id:f,name:p,className:s,onChange:function(e){var r=e.target,t=r.value,a=r.selectionStart;Y(t,a),N&&N(e)},onBlur:function(e){var r=e.target.value,t=c.cleanValue(a({value:r},U));if("-"===t||!t)return H(""),void(A&&A(e));var n=c.fixedDecimalValue(t,k,_),o=c.padTrimValue(n,k,O||_);S&&S(o,p);var i=c.formatValue(a(a({},G),{value:o}));H(i),A&&A(e)},onFocus:function(e){return I&&I(e),z?z.length:0},onKeyDown:function(e){var r=e.key;if(P&&("ArrowUp"===r||"ArrowDown"===r)){e.preventDefault();var t=Number(void 0!==h?h:c.cleanValue(a({value:z},U)))||0;Y(String("ArrowUp"===r?t+P:t-P))}L&&L(e)},onKeyUp:function(e){var r=e.currentTarget.selectionStart,t=c.getSuffix(z,{groupSeparator:B,decimalSeparator:k});if(t&&r&&r>z.length-t.length&&X&&"object"==typeof X&&X.current){var a=z.length-t.length;X.current.setSelectionRange(a,a)}F&&F(e)},placeholder:x,disabled:b,value:void 0!==Z&&"-"!==z?Z:z,ref:X},T);if(d){var re=d;return l.default.createElement(re,a({},ee))}return l.default.createElement("input",a({},ee))})),r.CurrencyInput.displayName="CurrencyInput",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(7),r),n(t(11),r),n(t(1),r),n(t(12),r),n(t(2),r),n(t(13),r),n(t(14),r)},function(e,r,t){"use strict";var a=this&&this.__spreadArrays||function(){for(var e=0,r=0,t=arguments.length;r<t;r++)e+=arguments[r].length;var a=Array(e),n=0;for(r=0;r<t;r++)for(var o=arguments[r],i=0,u=o.length;i<u;i++,n++)a[n]=o[i];return a};Object.defineProperty(r,"__esModule",{value:!0}),r.cleanValue=void 0;var n=t(8),o=t(9),i=t(10),u=t(0);r.cleanValue=function(e){var r=e.value,t=e.groupSeparator,l=void 0===t?",":t,c=e.decimalSeparator,f=void 0===c?".":c,p=e.allowDecimals,s=void 0===p||p,d=e.decimalsLimit,v=void 0===d?2:d,g=e.allowNegativeValue,m=void 0===g||g,b=e.disableAbbreviations,y=void 0!==b&&b,h=e.prefix,S=void 0===h?"":h;if("-"===r)return r;var _=y?[]:["k","m","b"],x=new RegExp("^\\d?-"+(S?u.escapeRegExp(S)+"?":"")+"\\d").test(r),O=RegExp("(\\d+)-?"+u.escapeRegExp(S)).exec(r)||[],w=O[0],j=O[1],P=S?r.replace(w,"").concat(j):r,E=o.removeSeparators(P,l),V=i.removeInvalidChars(E,a([l,f],_)),R=V;if(!y){if(_.some((function(e){return e===V.toLowerCase()})))return"";var M=n.parseAbbrValue(V,f);M&&(R=String(M))}var C=x&&m?"-":"";if(f&&R.includes(f)){var D=V.split(f),N=D[0],I=D[1],A=v&&I?I.slice(0,v):I;return""+C+N+(s?""+f+A:"")}return""+C+R}},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 i=o[1],u=o[3],l=n[u.toLowerCase()];return Number(i.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.removeInvalidChars=void 0;var a=t(0);r.removeInvalidChars=function(e,r){var t=a.escapeRegExp(r.join("")),n=new RegExp("[^\\d"+t+"]","gi");return e.replace(n,"")}},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((o=a[1]).length>t)return""+n+r+o.slice(0,t)}var o,i=e.length>t?new RegExp("(\\d+)(\\d{"+t+"})"):new RegExp("(\\d)(\\d+)"),u=e.match(i);if(u)return""+(n=u[1])+r+(o=u[2])}return e}},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)};Object.defineProperty(r,"__esModule",{value:!0}),r.getLocaleConfig=void 0;var n={currencySymbol:"",groupSeparator:"",decimalSeparator:""};r.getLocaleConfig=function(e){var r=e||{},t=r.locale,o=r.currency;return(t&&o?new Intl.NumberFormat(t,{currency:o,style:"currency"}):new Intl.NumberFormat).formatToParts(1000.1).reduce((function(e,r){return"currency"===r.type?a(a({},e),{currencySymbol:r.value}):"group"===r.type?a(a({},e),{groupSeparator:r.value}):"decimal"===r.type?a(a({},e),{decimalSeparator:r.value}):e}),n)}},function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.isNumber=void 0,r.isNumber=function(e){return RegExp(/\d/,"gi").test(e)}},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||""===e||void 0===e)return e;if(!e.match(/\d/g))return"";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}}]); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "react-currency-input-field", | ||
"version": "3.0.0-beta.9", | ||
"description": "React <input /> component for formatting currency and numbers.", | ||
"version": "3.0.0-beta.10", | ||
"description": "React <input/> component for formatting currency and numbers.", | ||
"files": [ | ||
@@ -6,0 +6,0 @@ "dist/**/*" |
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
87051
282