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 1.0.1 to 2.0.0

12

CHANGELOG.md

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

# [2.0.0](https://github.com/cchanxzy/react-currency-input-field/compare/v1.0.1...v2.0.0) (2020-07-02)
### Features
* allow value and precision props ([#46](https://github.com/cchanxzy/react-currency-input-field/issues/46)) ([912d6d9](https://github.com/cchanxzy/react-currency-input-field/commit/912d6d9422c38ba7039bba9572e9786f27f2ce4a))
### BREAKING CHANGES
* onChange will return string or undefined rather than number or null
## [1.0.1](https://github.com/cchanxzy/react-currency-input-field/compare/v1.0.0...v1.0.1) (2020-05-08)

@@ -2,0 +14,0 @@

8

dist/components/CurrencyInputProps.d.ts

@@ -36,5 +36,5 @@ /// <reference types="react" />

/**
* Handle change in value. Value will be `null` or `number`
* Handle change in value
*/
onChange?: (value: number | null, name?: string) => void;
onChange?: (value: string | undefined, name?: string) => void;
/**

@@ -45,2 +45,6 @@ * Placeholder

/**
* Specify decimal precision for padding/trimming
*/
precision?: number;
/**
* Include a prefix eg. £

@@ -47,0 +51,0 @@ */

@@ -10,2 +10,2 @@ /**

*/
export declare const parseAbbrValue: (value: string) => number | undefined;
export declare const parseAbbrValue: (value: string) => undefined | number;

@@ -8,2 +8,3 @@ export declare const addCommas: (value: string) => string;

export declare const cleanValue: (value: string, allowDecimals: boolean, decimalsLimit: number, prefix?: string | undefined) => string;
export declare const padTrimValue: (value: string, precision?: number | undefined) => string;
/**

@@ -10,0 +11,0 @@ * Format value with commas and prefix

@@ -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)),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}}}]);
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.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 a in e)r.d(n,a,function(t){return e[t]}.bind(null,a));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 a=n(r(1));t.default=a.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 a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},a=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),u=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.hasOwnProperty.call(e,r)&&a(t,e,r);return u(t,e),t},o=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 a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)t.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(r[n[a]]=e[n[a]])}return r};Object.defineProperty(t,"__esModule",{value:!0}),t.CurrencyInput=void 0;var l=i(r(2)),c=r(3);t.CurrencyInput=function(e){var t=e.allowDecimals,r=void 0===t||t,a=e.id,u=e.name,i=e.className,f=e.decimalsLimit,s=void 0===f?2:f,d=e.defaultValue,p=e.disabled,m=void 0!==p&&p,v=e.value,b=e.onChange,h=e.placeholder,g=e.precision,y=e.prefix,_=e.maxLength,O=o(e,["allowDecimals","id","name","className","decimalsLimit","defaultValue","disabled","value","onChange","placeholder","precision","prefix","maxLength"]),V=d?c.formatValue(String(d),y):"",j=l.useState(V),P=j[0],S=j[1],x=l.useState(0),M=x[0],C=x[1],N=l.useRef(null);l.useEffect((function(){N&&N.current&&N.current.setSelectionRange(M,M)}),[M,N,P]);var w=v?c.formatValue(String(v),y):void 0;return l.default.createElement("input",n({type:"text",inputMode:"decimal",id:a,name:u,className:i,onChange:function(e){var t=e.target,n=t.selectionStart,a=t.value,i=c.cleanValue(a,r,s,y);if(!i)return b&&b(void 0,u),S("");if(c.checkIsValidNumber(i)){var o=c.formatValue(i,y);if(n){var l=n+(o.length-a.length)||1;C(l)}S(o)}b&&b(i,u)},onBlur:function(e){var t=e.target.value,n=c.cleanValue(t,r,s,y),a=c.padTrimValue(n,g),i=c.formatValue(a,y);S(i),b&&b(a,u)},onFocus:function(){return P?P.length:0},placeholder:h,disabled:m,value:w||P,ref:N,maxLength:_},O))},t.default=t.CurrencyInput},function(e,t){e.exports=require("react")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.formatValue=t.padTrimValue=t.cleanValue=t.checkIsValidNumber=t.removeCommas=t.addCommas=void 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,a,u){var i=u?e.replace(u,""):e,o=t.removeCommas(i),l=n.parseAbbrValue(o)||o;if(String(l).includes(".")){var c=o.split("."),f=c[0],s=c[1];return""+f+(r?"."+(a?s.slice(0,a):s):"")}return String(l)},t.padTrimValue=function(e,t){if(!t)return e;var r=e.split("."),n=r[0],a=r[1]||"";if(a.length<t)for(;a.length<t;)a+="0";else a=a.slice(0,t);return n+"."+a},t.formatValue=function(e,r){var n=e.split("."),a=n[0],u=n[1],i=r||"",o=e.includes(".")?"."+u:"";return""+i+t.addCommas(a)+o}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.parseAbbrValue=t.abbrValue=void 0,t.abbrValue=function(e,t){if(void 0===t&&(t=10),e>999){var r=(""+e).length,n=Math.pow,a=n(10,t);return r-=r%3,Math.round(e*a/n(10,r))/a+" 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],a=t[3],u=a?n[a.toLowerCase()]:null;if(r&&u)return Number(r)*u}}}]);
//# sourceMappingURL=index.js.map
{
"name": "react-currency-input-field",
"version": "1.0.1",
"version": "2.0.0",
"description": "React <input /> component for formatting currency and numbers.",

@@ -43,36 +43,36 @@ "files": [

"devDependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@commitlint/cli": "^9.0.1",
"@commitlint/config-conventional": "^9.0.1",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@types/enzyme": "^3.10.5",
"@types/jest": "^25.2.1",
"@types/react": "^16.9.34",
"@types/react-dom": "^16.9.6",
"@typescript-eslint/eslint-plugin": "^2.29.0",
"@typescript-eslint/parser": "^2.29.0",
"@types/jest": "^26.0.3",
"@types/react": "^16.9.41",
"@types/react-dom": "^16.9.8",
"@typescript-eslint/eslint-plugin": "^3.5.0",
"@typescript-eslint/parser": "^3.5.0",
"awesome-typescript-loader": "^5.2.1",
"codecov": "^3.6.5",
"codecov": "^3.7.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^6.8.0",
"eslint": "^7.3.1",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.19.0",
"gh-pages": "^2.2.0",
"html-webpack-plugin": "^4.2.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.3",
"gh-pages": "^3.1.0",
"html-webpack-plugin": "^4.3.0",
"husky": "^4.2.5",
"jest": "^25.4.0",
"lint-staged": "^10.1.7",
"jest": "^26.1.0",
"lint-staged": "^10.2.11",
"prettier": "^2.0.5",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-hot-loader": "^4.12.20",
"semantic-release": "^17.0.7",
"source-map-loader": "^0.2.4",
"ts-jest": "^25.4.0",
"typescript": "^3.8.3",
"react-hot-loader": "^4.12.21",
"semantic-release": "^17.1.1",
"source-map-loader": "^1.0.1",
"ts-jest": "^26.1.1",
"typescript": "^3.9.6",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
},

@@ -79,0 +79,0 @@ "peerDependencies": {

@@ -58,15 +58,16 @@ # React Currency Input Field Component

| Name | Type | Default | Description |
| ------------- | ---------- | ------- | -------------------------------------------------------- |
| allowDecimals | `boolean` | `true` | Allow decimals |
| id | `string` | | Component id |
| name | `string` | | Component (input) name |
| className | `string` | | Class names |
| decimalsLimit | `number` | `2` | Limit length of decimals allowed |
| defaultValue | `number` | | Default value |
| disabled | `boolean` | `false` | Disabled |
| onChange | `function` | | Handle change in value. Value will be `null` or `number` |
| placeholder | `string` | | Placeholder if no value |
| prefix | `string` | | Include a prefix eg. £ or \$ |
| maxLength | `number` | | Maximum characters the user can enter |
| Name | Type | Default | Description |
| ------------- | ---------- | ------- | ---------------------------------------------- |
| allowDecimals | `boolean` | `true` | Allow decimals |
| id | `string` | | Component id |
| name | `string` | | Component (input) name |
| className | `string` | | Class names |
| decimalsLimit | `number` | `2` | Limit length of decimals allowed |
| defaultValue | `number` | | Default value |
| disabled | `boolean` | `false` | Disabled |
| 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 \$ |
| maxLength | `number` | | Maximum characters the user can enter |

@@ -73,0 +74,0 @@ ## Issues

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