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

react-currency-input-field

Package Overview
Dependencies
Maintainers
1
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-currency-input-field - npm Package Compare versions

Comparing version 3.0.0-beta.2 to 3.0.0-beta.3

16

CHANGELOG.md

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

# [3.0.0-beta.3](https://github.com/cchanxzy/react-currency-input-field/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2020-12-06)
### Features
* renamed precision to decimalScale ([c545b78](https://github.com/cchanxzy/react-currency-input-field/commit/c545b780815bff7c98c66e527f3f3f4a1cc8ee67))
* renamed turnOffAbbreviations to disableAbbreviations ([7751a43](https://github.com/cchanxzy/react-currency-input-field/commit/7751a4386baee5554aa030839d1cdc0f3750f360))
* renamed turnOffSeparators to disableGroupSeparators ([b16f577](https://github.com/cchanxzy/react-currency-input-field/commit/b16f577e29646e2fba9db370fb4eda2c73ae632e))
### BREAKING CHANGES
* Renamed "turnOffAbbreviations" to "disableAbbreviations"
* Renamed "turnOffSeparators" to "disableGroupSeparators"
* renamed precision to decimalScale
# [3.0.0-beta.2](https://github.com/cchanxzy/react-currency-input-field/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2020-12-03)

@@ -2,0 +18,0 @@

33

dist/components/CurrencyInputProps.d.ts

@@ -39,4 +39,10 @@ import { Ref } from 'react';

/**
* Default value if not passing in value
* Specify decimal scale for padding/trimming
*
* Eg. 1 -> 1.99 or 1.234 -> 1.23
*/
decimalScale?: number;
/**
* Default value if not passing in value via props
*/
defaultValue?: number | string;

@@ -51,2 +57,6 @@ /**

* Value will always have the specified length of decimals
*
* Eg. 123 -> 1.23
*
* Note: This formatting only happens onBlur
*/

@@ -64,10 +74,6 @@ fixedDecimalLength?: number;

/**
* Placeholder
* Placeholder if there is no value
*/
placeholder?: string;
/**
* Specify decimal precision for padding/trimming
*/
precision?: number;
/**
* Include a prefix eg. £

@@ -81,11 +87,11 @@ */

/**
* Separator between integer part and fractional part of value. Cannot be a number
* Separator between integer part and fractional part of value.
*
* Default = "."
* This cannot be a number
*/
decimalSeparator?: string;
/**
* Separator between thousand, million and billion. Cannot be a number
* Separator between thousand, million and billion
*
* Default = ","
* This cannot be a number
*/

@@ -98,3 +104,3 @@ groupSeparator?: string;

*/
turnOffSeparators?: boolean;
disableGroupSeparators?: boolean;
/**

@@ -105,3 +111,3 @@ * Disable abbreviations eg. 1k > 1,000, 2m > 2,000,000

*/
turnOffAbbreviations?: boolean;
disableAbbreviations?: boolean;
/**

@@ -112,3 +118,4 @@ * International locale config, examples:

*
* Any prefix, groupSeparator or decimalSeparator options passed in will override locale defaults
* Any prefix, groupSeparator or decimalSeparator options passed in
* will override Intl Locale config
*/

@@ -115,0 +122,0 @@ intlConfig?: IntlConfig;

@@ -8,3 +8,3 @@ export declare type CleanValueOptions = {

allowNegativeValue?: boolean;
turnOffAbbreviations?: boolean;
disableAbbreviations?: boolean;
prefix?: string;

@@ -15,2 +15,2 @@ };

*/
export declare const cleanValue: ({ value, groupSeparator, decimalSeparator, allowDecimals, decimalsLimit, allowNegativeValue, turnOffAbbreviations, prefix, }: CleanValueOptions) => string;
export declare const cleanValue: ({ value, groupSeparator, decimalSeparator, allowDecimals, decimalsLimit, allowNegativeValue, disableAbbreviations, prefix, }: CleanValueOptions) => string;

@@ -26,3 +26,3 @@ import { IntlConfig } from '../CurrencyInputProps';

*/
turnOffSeparators?: boolean;
disableGroupSeparators?: boolean;
/**

@@ -29,0 +29,0 @@ * Intl locale currency config

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

export declare const padTrimValue: (value: string, decimalSeparator?: string, precision?: number | undefined) => string;
export declare const padTrimValue: (value: string, decimalSeparator?: string, decimalScale?: number | undefined) => string;

@@ -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=2)}([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.__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 n=t(0);r.formatValue=function(e){var r=e.value,t=e.decimalSeparator,a=e.intlConfig,u=e.prefix,l=void 0===u?"":u;if(""===r||void 0===r)return"";if("-"===r)return"-";var c=new RegExp("^\\d?-"+(l?n.escapeRegExp(l)+"?":"")+"\\d").test(String(r)),f="."!==t?o(String(r),t,c):String(r),p=(a?new Intl.NumberFormat(a.locale,{style:"currency",currency:a.currency,minimumFractionDigits:0}):new Intl.NumberFormat).formatToParts(Number(f)),d=i(p,e);a||(d=c?d.replace(/^-/g,"-"+l):""+l+d);var s=f.slice(-1)===t?t:"",v=(f.match(RegExp("\\d+\\.(\\d+)"))||[])[1];return v&&t&&(d=d.includes(t)?d.replace(RegExp("(\\d+)("+n.escapeRegExp(t)+")(\\d+)","g"),"$1$2"+v):""+d+t+v),[d,s].join("")};var o=function(e,r,t){var a=e;return r&&"."!==r&&(a=a.replace(RegExp(n.escapeRegExp(r),"g"),"."),t&&"-"===r&&(a="-"+a.slice(1))),a},i=function(e,r){var t=r.prefix,n=r.groupSeparator,o=r.decimalSeparator,i=r.turnOffSeparators,u=void 0!==i&&i;return e.reduce((function(e,r){var i=r.type,l=r.value;return"currency"===i&&t?a(e,[t]):"group"===i?u?e:a(e,[void 0!==n?n:l]):"decimal"===i?u?e:a(e,[void 0!==o?o:l]):a(e,[l])}),[""]).join("")}},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(3));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(4)),c=t(5);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,d=e.className,s=e.decimalsLimit,v=e.defaultValue,g=e.disabled,m=void 0!==g&&g,b=e.maxLength,y=e.value,h=e.onChange,S=e.onBlurValue,_=e.fixedDecimalLength,O=e.placeholder,x=e.precision,w=e.prefix,j=e.intlConfig,P=e.step,V=e.turnOffSeparators,E=void 0!==V&&V,M=e.turnOffAbbreviations,R=void 0!==M&&M,N=u(e,["allowDecimals","allowNegativeValue","id","name","className","decimalsLimit","defaultValue","disabled","maxLength","value","onChange","onBlurValue","fixedDecimalLength","placeholder","precision","prefix","intlConfig","step","turnOffSeparators","turnOffAbbreviations"]);if(N.decimalSeparator&&N.groupSeparator&&N.decimalSeparator===N.groupSeparator)throw new Error("decimalSeparator cannot be the same as groupSeparator");if(N.decimalSeparator&&c.isNumber(N.decimalSeparator))throw new Error("decimalSeparator cannot be a number");if(N.groupSeparator&&c.isNumber(N.groupSeparator))throw new Error("groupSeparator cannot be a number");var C=l.useMemo((function(){return c.getLocaleConfig(j)}),[j]),A=N.decimalSeparator||C.decimalSeparator||"",D=N.groupSeparator||C.groupSeparator||"",I={decimalSeparator:A,groupSeparator:D,turnOffSeparators:E,intlConfig:j,prefix:w},L={decimalSeparator:A,groupSeparator:D,allowDecimals:n,decimalsLimit:s||_||2,allowNegativeValue:i,turnOffAbbreviations:R,prefix:w},T=void 0!==v?c.formatValue(a({value:String(v)},I)):"",F=l.useState(T),k=F[0],B=F[1],$=l.useState(0),U=$[0],q=$[1],G=r||l.useRef(null),K=function(e,r){var t=c.cleanValue(a({value:e},L));if(!t)return h&&h(void 0,p),void B("");if(!(b&&t.replace(/-/g,"").length>b)){if("-"===t)return h&&h(void 0,p),void B(e);var n=c.formatValue(a({value:t},I));if(null!=r){var o=r+(n.length-e.length)||1;q(o)}B(n),h&&h(t,p)}};l.useEffect((function(){G&&"object"==typeof G&&G.current&&G.current.setSelectionRange(U,U)}),[U,G]);var z=void 0!==y?c.formatValue(a(a({},I),{value:String(y)})):void 0;return l.default.createElement("input",a({type:"text",inputMode:"decimal",id:f,name:p,className:d,onChange:function(e){var r=e.target,t=r.value,a=r.selectionStart;K(t,a)},onBlur:function(e){var r=e.target.value,t=c.cleanValue(a({value:r},L));if("-"===t||!t)return S&&S(void 0,p),void B("");var n=c.fixedDecimalValue(t,A,_),o=c.padTrimValue(n,A,x||_);h&&h(o,p),S&&S(o,p);var i=c.formatValue(a(a({},I),{value:o}));B(i)},onFocus:function(){return k?k.length:0},onKeyDown:function(e){var r=e.key;if(P&&("ArrowUp"===r||"ArrowDown"===r)){var t=Number(void 0!==y?y:c.cleanValue(a({value:k},L)))||0,n=String("ArrowUp"===r?t+Number(P):t-Number(P));K(n)}},placeholder:O,disabled:m,value:void 0!==z&&"-"!==k?z:k,ref:G},N))})),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(6),r),n(t(10),r),n(t(1),r),n(t(11),r),n(t(12),r),n(t(13),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(7),o=t(8),i=t(9),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,d=void 0===p||p,s=e.decimalsLimit,v=void 0===s?2:s,g=e.allowNegativeValue,m=void 0===g||g,b=e.turnOffAbbreviations,y=void 0!==b&&b,h=e.prefix,S=void 0===h?"":h;if("-"===r)return r;var _=y?[]:["k","m","b"],O=new RegExp("^\\d?-"+(S?u.escapeRegExp(S)+"?":"")+"\\d").test(r),x=RegExp("(\\d+)-?"+u.escapeRegExp(S)).exec(r)||[],w=x[0],j=x[1],P=S?r.replace(w,"").concat(j):r,V=o.removeSeparators(P,l),E=i.removeInvalidChars(V,a([l,f],_)),M=E;if(!y){if(_.some((function(e){return e===E.toLowerCase()})))return"";var R=n.parseAbbrValue(E,f);R&&(M=String(R))}var N=O&&m?"-":"";if(String(M).includes(f)){var C=E.split(f),A=C[0],D=C[1],I=v?D.slice(0,v):D;return""+N+A+(d?""+f+I:"")}return""+N+M}},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()];if(i&&l)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=2)}([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.__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 i=arguments[r],o=0,u=i.length;o<u;o++,n++)a[n]=i[o];return a};Object.defineProperty(r,"__esModule",{value:!0}),r.formatValue=void 0;var n=t(0);r.formatValue=function(e){var r=e.value,t=e.decimalSeparator,a=e.intlConfig,u=e.prefix,l=void 0===u?"":u;if(""===r||void 0===r)return"";if("-"===r)return"-";var c=new RegExp("^\\d?-"+(l?n.escapeRegExp(l)+"?":"")+"\\d").test(String(r)),d="."!==t?i(String(r),t,c):String(r),p=(a?new Intl.NumberFormat(a.locale,{style:"currency",currency:a.currency,minimumFractionDigits:0}):new Intl.NumberFormat).formatToParts(Number(d)),f=o(p,e);a||(f=c?f.replace(/^-/g,"-"+l):""+l+f);var s=d.slice(-1)===t?t:"",v=(d.match(RegExp("\\d+\\.(\\d+)"))||[])[1];return v&&t&&(f=f.includes(t)?f.replace(RegExp("(\\d+)("+n.escapeRegExp(t)+")(\\d+)","g"),"$1$2"+v):""+f+t+v),[f,s].join("")};var i=function(e,r,t){var a=e;return r&&"."!==r&&(a=a.replace(RegExp(n.escapeRegExp(r),"g"),"."),t&&"-"===r&&(a="-"+a.slice(1))),a},o=function(e,r){var t=r.prefix,n=r.groupSeparator,i=r.decimalSeparator,o=r.disableGroupSeparators,u=void 0!==o&&o;return e.reduce((function(e,r){var o=r.type,l=r.value;return"currency"===o&&t?a(e,[t]):"group"===o?u?e:a(e,[void 0!==n?n:l]):"decimal"===o?u?e:a(e,[void 0!==i?i:l]):a(e,[l])}),[""]).join("")}},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(3));r.default=n.default;var i=t(1);Object.defineProperty(r,"formatValue",{enumerable:!0,get:function(){return i.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]}),i=this&&this.__setModuleDefault||(Object.create?function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}:function(e,r){e.default=r}),o=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},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=o(t(4)),c=t(5);r.CurrencyInput=l.forwardRef((function(e,r){var t=e.allowDecimals,n=void 0===t||t,i=e.allowNegativeValue,o=void 0===i||i,d=e.id,p=e.name,f=e.className,s=e.decimalsLimit,v=e.defaultValue,g=e.disabled,m=void 0!==g&&g,b=e.maxLength,y=e.value,h=e.onChange,S=e.onBlurValue,_=e.fixedDecimalLength,x=e.placeholder,O=e.decimalScale,w=e.prefix,j=e.intlConfig,P=e.step,V=e.disableGroupSeparators,E=void 0!==V&&V,M=e.disableAbbreviations,R=void 0!==M&&M,N=u(e,["allowDecimals","allowNegativeValue","id","name","className","decimalsLimit","defaultValue","disabled","maxLength","value","onChange","onBlurValue","fixedDecimalLength","placeholder","decimalScale","prefix","intlConfig","step","disableGroupSeparators","disableAbbreviations"]);if(N.decimalSeparator&&N.groupSeparator&&N.decimalSeparator===N.groupSeparator)throw new Error("decimalSeparator cannot be the same as groupSeparator");if(N.decimalSeparator&&c.isNumber(N.decimalSeparator))throw new Error("decimalSeparator cannot be a number");if(N.groupSeparator&&c.isNumber(N.groupSeparator))throw new Error("groupSeparator cannot be a number");var C=l.useMemo((function(){return c.getLocaleConfig(j)}),[j]),A=N.decimalSeparator||C.decimalSeparator||"",D=N.groupSeparator||C.groupSeparator||"",I={decimalSeparator:A,groupSeparator:D,disableGroupSeparators:E,intlConfig:j,prefix:w},L={decimalSeparator:A,groupSeparator:D,allowDecimals:n,decimalsLimit:s||_||2,allowNegativeValue:o,disableAbbreviations:R,prefix:w},T=void 0!==v?c.formatValue(a({value:String(v)},I)):"",F=l.useState(T),k=F[0],B=F[1],G=l.useState(0),$=G[0],U=G[1],q=r||l.useRef(null),K=function(e,r){var t=c.cleanValue(a({value:e},L));if(!t)return h&&h(void 0,p),void B("");if(!(b&&t.replace(/-/g,"").length>b)){if("-"===t)return h&&h(void 0,p),void B(e);var n=c.formatValue(a({value:t},I));if(null!=r){var i=r+(n.length-e.length)||1;U(i)}B(n),h&&h(t,p)}};l.useEffect((function(){q&&"object"==typeof q&&q.current&&q.current.setSelectionRange($,$)}),[$,q]);var z=void 0!==y?c.formatValue(a(a({},I),{value:String(y)})):void 0;return l.default.createElement("input",a({type:"text",inputMode:"decimal",id:d,name:p,className:f,onChange:function(e){var r=e.target,t=r.value,a=r.selectionStart;K(t,a)},onBlur:function(e){var r=e.target.value,t=c.cleanValue(a({value:r},L));if("-"===t||!t)return S&&S(void 0,p),void B("");var n=c.fixedDecimalValue(t,A,_),i=c.padTrimValue(n,A,O||_);h&&h(i,p),S&&S(i,p);var o=c.formatValue(a(a({},I),{value:i}));B(o)},onFocus:function(){return k?k.length:0},onKeyDown:function(e){var r=e.key;if(P&&("ArrowUp"===r||"ArrowDown"===r)){var t=Number(void 0!==y?y:c.cleanValue(a({value:k},L)))||0,n=String("ArrowUp"===r?t+Number(P):t-Number(P));K(n)}},placeholder:x,disabled:m,value:void 0!==z&&"-"!==k?z:k,ref:q},N))})),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(6),r),n(t(10),r),n(t(1),r),n(t(11),r),n(t(12),r),n(t(13),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 i=arguments[r],o=0,u=i.length;o<u;o++,n++)a[n]=i[o];return a};Object.defineProperty(r,"__esModule",{value:!0}),r.cleanValue=void 0;var n=t(7),i=t(8),o=t(9),u=t(0);r.cleanValue=function(e){var r=e.value,t=e.groupSeparator,l=void 0===t?",":t,c=e.decimalSeparator,d=void 0===c?".":c,p=e.allowDecimals,f=void 0===p||p,s=e.decimalsLimit,v=void 0===s?2:s,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=i.removeSeparators(P,l),E=o.removeInvalidChars(V,a([l,d],_)),M=E;if(!y){if(_.some((function(e){return e===E.toLowerCase()})))return"";var R=n.parseAbbrValue(E,d);R&&(M=String(R))}var N=x&&m?"-":"";if(String(M).includes(d)){var C=E.split(d),A=C[0],D=C[1],I=v?D.slice(0,v):D;return""+N+A+(f?""+d+I:"")}return""+N+M}},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 o=i[1],u=i[3],l=n[u.toLowerCase()];if(o&&l)return Number(o.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((i=a[1]).length>t)return""+n+r+i.slice(0,t)}var i,o=e.length>t?new RegExp("(\\d+)(\\d{"+t+"})"):new RegExp("(\\d)(\\d+)"),u=e.match(o);if(u)return""+(n=u[1])+r+(i=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,i=r.currency;return(t&&i?new Intl.NumberFormat(t,{currency:i,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],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": "3.0.0-beta.2",
"version": "3.0.0-beta.3",
"description": "React <input /> component for formatting currency and numbers.",

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

@@ -57,3 +57,3 @@ # React Currency Input Field Component

This can be turned off by passing in `turnOffAbbreviations`.
This can be turned off by passing in `disableAbbreviations`.

@@ -74,3 +74,3 @@ ## Separators

To turn off auto adding the group separator, add `turnOffSeparators={true}`.
To turn off auto adding the group separator, add `disableGroupSeparators={true}`.

@@ -114,25 +114,25 @@ ## Intl Locale Config

| Name | Type | Default | Description |
| -------------------- | ---------- | -------------- | ------------------------------------------------------------------------ |
| allowDecimals | `boolean` | `true` | Allow decimals |
| allowNegativeValue | `boolean` | `true` | Allow user to enter negative value |
| className | `string` | | Class names |
| decimalsLimit | `number` | `2` | Limit length of decimals allowed |
| defaultValue | `number` | | Default value |
| value | `number` | | Programmatically set the 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 |
| onBlurValue | `function` | | Handle value onBlur |
| placeholder | `string` | | Placeholder if no value |
| precision | `number` | | Specify decimal precision for padding/trimming |
| prefix | `string` | | Include a prefix eg. £ or \$ |
| step | `number` | | Incremental value change on arrow down and arrow up key press |
| decimalSeparator | `string` | locale default | Separator between integer part and fractional part of value |
| groupSeparator | `string` | locale default | Separator between thousand, million and billion |
| intlConfig | `object` | | International locale config |
| turnOffAbbreviations | `boolean` | `false` | Disable abbreviations eg. 1k > 1,000, 2m > 2,000,000 |
| turnOffSeparators | `boolean` | `false` | Disable auto adding the group separator between values, eg. 1000 > 1,000 |
| Name | Type | Default | Description |
| ---------------------- | ---------- | -------------- | ------------------------------------------------------------------------ |
| allowDecimals | `boolean` | `true` | Allow decimals |
| allowNegativeValue | `boolean` | `true` | Allow user to enter negative value |
| className | `string` | | Class names |
| decimalsLimit | `number` | `2` | Limit length of decimals allowed |
| defaultValue | `number` | | Default value |
| value | `number` | | Programmatically set the 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 |
| onBlurValue | `function` | | Handle value onBlur |
| placeholder | `string` | | Placeholder if no value |
| decimalScale | `number` | | Specify decimal scale for padding/trimming |
| prefix | `string` | | Include a prefix eg. £ or \$ |
| step | `number` | | Incremental value change on arrow down and arrow up key press |
| decimalSeparator | `string` | locale default | Separator between integer part and fractional part of value |
| groupSeparator | `string` | locale default | Separator between thousand, million and billion |
| intlConfig | `object` | | International locale config |
| disableAbbreviations | `boolean` | `false` | Disable abbreviations eg. 1k > 1,000, 2m > 2,000,000 |
| disableGroupSeparators | `boolean` | `false` | Disable auto adding the group separator between values, eg. 1000 > 1,000 |

@@ -150,3 +150,3 @@ ## Format values for display

decimalSeparator = '.',
turnOffSeparators = false,
disableGroupSeparators = false,
prefix = '$',

@@ -153,0 +153,0 @@ });

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