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

@react-input/number-format

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-input/number-format - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

dist/module/helpers-bSXZ1mLm.js

2

dist/@types/utils.d.ts

@@ -25,2 +25,2 @@ import type { NumberFormatOptions } from './types';

*/
export declare function unformat(formattedValue: string, locales?: Intl.LocalesArgument): string;
export declare function unformat(value: string, locales?: Intl.LocalesArgument): string;

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

"use client";import{_ as i,a as r}from"./helpers-ZrL-K9bK.js";import m,{forwardRef as t}from"react";import{useConnectedInputRef as n}from"@react-input/core";import a from"./useNumberFormat.js";var e=["component","locales","format","currency","currencyDisplay","unit","unitDisplay","signDisplay","groupDisplay","minimumIntegerDigits","maximumIntegerDigits","minimumFractionDigits","maximumFractionDigits","onNumberFormat"];function o(t,o){var s=t.component,u=t.locales,c=t.format,p=t.currency,g=t.currencyDisplay,D=t.unit,l=t.unitDisplay,y=t.signDisplay,f=t.groupDisplay,F=t.minimumIntegerDigits,x=t.maximumIntegerDigits,I=t.minimumFractionDigits,b=t.maximumFractionDigits,N=t.onNumberFormat,v=i(t,e),j=a({locales:u,format:c,currency:p,currencyDisplay:g,unit:D,unitDisplay:l,signDisplay:y,groupDisplay:f,minimumIntegerDigits:F,maximumIntegerDigits:x,minimumFractionDigits:I,maximumFractionDigits:b,onNumberFormat:N}),E=n(j,o);return s?m.createElement(s,r({ref:E},v)):m.createElement("input",r({ref:E},v))}var s=t(o);export{s as default};
"use client";import{_ as i,a as r}from"./helpers-bSXZ1mLm.js";import m,{forwardRef as t}from"react";import{useConnectedInputRef as n}from"@react-input/core";import a from"./useNumberFormat.js";var e=["component","locales","format","currency","currencyDisplay","unit","unitDisplay","signDisplay","groupDisplay","minimumIntegerDigits","maximumIntegerDigits","minimumFractionDigits","maximumFractionDigits","onNumberFormat"];function o(t,o){var s=t.component,u=t.locales,c=t.format,p=t.currency,g=t.currencyDisplay,D=t.unit,l=t.unitDisplay,y=t.signDisplay,f=t.groupDisplay,F=t.minimumIntegerDigits,x=t.maximumIntegerDigits,I=t.minimumFractionDigits,b=t.maximumFractionDigits,N=t.onNumberFormat,v=i(t,e),j=a({locales:u,format:c,currency:p,currencyDisplay:g,unit:D,unitDisplay:l,signDisplay:y,groupDisplay:f,minimumIntegerDigits:F,maximumIntegerDigits:x,minimumFractionDigits:I,maximumFractionDigits:b,onNumberFormat:N}),E=n(j,o);return s?m.createElement(s,r({ref:E},v)):m.createElement("input",r({ref:E},v))}var s=t(o);export{s as default};

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

import{useRef as e}from"react";import{useInput as i,SyntheticChangeError as a}from"@react-input/core";import{c as t,l as c,b as n,r,u as l,f as s}from"./helpers-ZrL-K9bK.js";function o(){var o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},d=o.locales,u=o.format,g=o.currency,m=o.currencyDisplay,p=o.unit,v=o.unitDisplay,f=o.signDisplay,x=o.groupDisplay,h=o.minimumIntegerDigits,E=o.maximumIntegerDigits,D=o.minimumFractionDigits,R=o.maximumFractionDigits,y=o.onNumberFormat,S={format:u,currency:g,currencyDisplay:m,unit:p,unitDisplay:v,signDisplay:f,groupDisplay:x,minimumIntegerDigits:h,maximumIntegerDigits:E,minimumFractionDigits:D,maximumFractionDigits:R},F=e(null);return i({init:function(e){var i=e.controlled,a=e.initialValue;if(!i){var t=c(d),o=n(a,t);if(o.length>0){var u=r(d,S),g=l(o,t);a=s(g,{locales:d,options:S,localizedValues:t,resolvedOptions:u}).value}}var m={locales:d,options:S};return F.current={value:a,props:m,fallbackProps:m},{value:a}},tracking:function(e){var i=e.inputType,o=e.previousValue,u=e.addedValue,g=e.changeStart,m=e.changeEnd;if(null===F.current)throw new a("The state has not been initialized.");F.current.value!==o?F.current.props=F.current.fallbackProps:F.current.fallbackProps=F.current.props;var p=c(F.current.props.locales),v=c(d),f=r(d,S);if(u=n(u,v),0===f.maximumFractionDigits&&(u=u.replace(RegExp("[.,".concat(v.decimal,"]"),"g"),"")),"insert"===i&&!u)throw new a("The added value does not contain allowed characters.");var x=RegExp("[^\\".concat(p.minusSign).concat(p.decimal).concat(p.digits,"]"),"g"),h=o.slice(0,g).replace(x,""),E=o.slice(m).replace(x,""),D=n(h+u+E,v),R=l(D,v),y=RegExp("^[\\-\\".concat(v.minusSign,"]$")).test(u)&&g===m,V=o.includes(p.minusSign),w=R.includes("-");if(y&&V&&w&&(R=R.replace("-","")),!y||V||w||(R="-".concat(R)),/\..*0$/.test(R)){for(var b="",$=-1,k=0,O=!1;k<o.length;k++){var z=p.digits.includes(o[k]),I=o[k]===p.decimal;O?z&&(b+=o[k],-1===$&&($=k)):I&&(O=!0)}if(-1!==$){var T,B=null!==(T=r(F.current.props.locales,F.current.props.options).minimumFractionDigits)&&void 0!==T?T:0;g>=$&&m<$+(B||1)&&b.length<=(B||1)&&(R=R.replace(/0+$/g,""))}}var P="deleteBackward"===i||"deleteForward"===i;if(P&&o.includes(p.decimal)&&!R.includes(".")){var L,N="[".concat(p.digits[0],"]*[^").concat(p.decimal).concat(p.digits,"]*$"),_="[^".concat(p.digits[0],"]"),j=null===(L=RegExp(N).exec(o))||void 0===L?void 0:L[0].replace(RegExp(_,"g"),"").length;void 0!==j&&void 0!==f.minimumFractionDigits&&(j>f.minimumFractionDigits&&(j=f.minimumFractionDigits),R=R.replace(RegExp("0{0,".concat(j,"}$")),""))}var H={value:"",number:0},q=""===R||"-"===R||/^-?(\.0*)?$/.test(R);P&&q||(H=s(R,{locales:d,options:S,localizedValues:v,resolvedOptions:f}));var A=function(e){var i=e.localizedValues,a=e.previousLocalizedValues,c=e.resolvedOptions,n=e.inputType,r=e.value,l=e.previousValue,s=e.addedValue,o=e.changeStart,d=e.changeEnd;if(l.includes(i.decimal)&&RegExp("^[.,".concat(i.decimal,"]$")).test(s)){var u=r.indexOf(i.decimal);if(-1!==u){var g=u+1;return{start:g,end:g}}}if(l.includes(i.minusSign)&&RegExp("^[\\-\\".concat(i.minusSign,"]$")).test(s)){var m=r.indexOf(i.minusSign);if(-1!==m){var p=m+(i.signBackwards?0:1);return{start:p,end:p}}}if("deleteBackward"===n||"deleteForward"===n){var v=l.split(a.decimal),f=t(v,1)[0];if(d<=f.length&&!RegExp("[".concat(a.digits.slice(1),"]")).test(f)){var x=f.indexOf(a.digits[0]),h=f.lastIndexOf(a.digits[0]);if(-1!==x&&-1!==h){var E=h+1;if((o!==x||d!==E)&&d>x&&d<=E)return{start:x,end:E}}}}for(var D=void 0!==c.maximumIntegerDigits?Number(c.maximumIntegerDigits):void 0,R=r.length,y=0,S=0,F=!1;S<o;S++){var V=a.digits.includes(l[S]),w=l[S]===a.decimal;!F&&(w||V&&l[S]!==a.digits[0])&&(F=!0),F&&(w||V)&&(y+=1)}if("insert"===n){var b=l.slice(0,o),$=l.indexOf(a.decimal),k=b.replace(RegExp("[^".concat(a.decimal).concat(a.digits,"]"),"g"),"").replace(RegExp("^".concat(a.digits[0],"+"),"g"),"").split(a.decimal),O=t(k,2),z=O[0],I=O[1],T=void 0===I?"":I,B=s.replace(RegExp("[\\-\\".concat(i.minusSign,"]"),"g"),"").replace(RegExp("[,".concat(i.decimal,"]"),"g"),".");-1!==$&&d<=$&&(B=B.replace(RegExp("[^\\d".concat(i.digits,"]+"),"g"),""));var P=B.includes("."),L=B.split("."),N=t(L,2),_=N[0],j=N[1],H=void 0===j?"":j;if(-1!==$&&o>$)if(P){y-=1;var q=z+T;void 0!==D&&q.length>D&&(y=D,z=q.slice(0,D))}else H=_,_="";var A="[".concat(a.decimal).concat(a.digits.slice(1),"]");RegExp(A).test(b)||(_=_.replace(RegExp("^[0".concat(a.digits[0],"]+"),"g"),""));var C=void 0!==D?D-z.length:void 0;y+=(_.slice(0,C)+(P?".":"")+H).replace(RegExp("[^\\.".concat(i.decimal,"\\d").concat(i.digits,"]+"),"g"),"").length}for(var G=0,J=!1,K=0;G<r.length;G++){var M=i.digits.includes(r[G]),Q=r[G]===i.decimal;if(!J&&(Q||M&&r[G]!==i.digits[0])&&(J=!0),J&&K>=y){R=G;break}J&&(Q||M)&&(K+=1)}if("deleteForward"===n){var U,W="\\".concat(i.minusSign),X="^.{".concat(R,"}[^").concat(i.decimal).concat(i.digits,"]*[").concat(W).concat(i.decimal).concat(i.digits,"]"),Y=null===(U=RegExp(X).exec(r))||void 0===U?void 0:U[0].length;void 0!==Y&&(R=Y-1)}else{var Z,ee,ie="deleteBackward"===n?"\\".concat(i.minusSign):"",ae="[".concat(ie).concat(i.decimal).concat(i.digits,"][^").concat(i.decimal).concat(i.digits,"]*.{").concat(r.length-R,"}$"),te=null===(Z=RegExp(ae).exec(r))||void 0===Z?void 0:Z.index;void 0!==te&&(R=te+1),r[R]===i.decimal&&RegExp("[.,".concat(i.decimal,"]")).test(null!==(ee=s[s.length-1])&&void 0!==ee?ee:"")&&(R+=1)}var ce="[\\".concat(i.minusSign).concat(i.decimal).concat(i.digits.slice(1),"]"),ne="[\\".concat(i.minusSign).concat(i.decimal).concat(i.digits,"][^").concat(i.decimal).concat(i.digits,"]*$"),re=r.search(RegExp(ce)),le=r.search(RegExp(ne));return-1!==re&&R<re?R=re:-1!==le&&R>le+1&&(R=le+1),{start:R,end:R}}({localizedValues:v,previousLocalizedValues:p,resolvedOptions:f,inputType:i,value:H.value,previousValue:o,addedValue:u,changeStart:g,changeEnd:m});return F.current.value=H.value,F.current.props={locales:d,options:S},{value:H.value,selectionStart:A.start,selectionEnd:A.end,__detail:H}},eventType:"input-number-format",eventHandler:y})}export{o as default};
import{useRef as e}from"react";import{useInput as i,SyntheticChangeError as a}from"@react-input/core";import{c as t,l as c,r as n,f as r,e as l,b as s,n as o}from"./helpers-bSXZ1mLm.js";function d(e,i){var a={minusSign:"-",decimal:".",digits:"\\d",signBackwards:!1},t=l(e,i),c=l(e.replace(",","."),a);return e=s(t||c,t?i:a),e=o(e,i)}function u(){var u=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},g=u.locales,p=u.format,m=u.currency,v=u.currencyDisplay,f=u.unit,x=u.unitDisplay,h=u.signDisplay,D=u.groupDisplay,E=u.minimumIntegerDigits,y=u.maximumIntegerDigits,R=u.minimumFractionDigits,$=u.maximumFractionDigits,w=u.onNumberFormat,S={format:p,currency:m,currencyDisplay:v,unit:f,unitDisplay:x,signDisplay:h,groupDisplay:D,minimumIntegerDigits:E,maximumIntegerDigits:y,minimumFractionDigits:R,maximumFractionDigits:$},V=e(null);return i({init:function(e){var i=e.controlled,a=e.initialValue;if(!i&&a.length>0){var t=c(g),l=n(g,S),s=d(a,t);(s=s.replace(/(.+)(-)$/,"$2$1")).length>0&&(a=r(s,{locales:g,options:S,localizedValues:t,resolvedOptions:l}).value)}var o={locales:g,options:S};return V.current={value:a,props:o,fallbackProps:o},{value:a}},tracking:function(e){var i=e.inputType,u=e.previousValue,p=e.addedValue,m=e.changeStart,v=e.changeEnd;if(null===V.current)throw new a("The state has not been initialized.");V.current.value!==u?V.current.props=V.current.fallbackProps:V.current.fallbackProps=V.current.props;var f=c(V.current.props.locales),x=c(g),h=n(g,S),D=RegExp("^[".concat(x.minusSign,"]$")),E=RegExp("^[,".concat(x.decimal,"]$"));if(p=D.test(p)?p.replace(D,"-"):E.test(p)?p.replace(E,"."):d(p,x),"insert"===i&&!p)throw new a("The added value does not contain allowed characters.");var y=u.slice(0,m);y=l(y,f),y=s(y,f),y=o(y,f);var R=u.slice(v);R=l(R,f),R=s(R,f);var $=y+p+(R=o(R,f));if($=$.replace(/[.](?=.*[.])/g,""),x.signBackwards)$=$.replace(/[-](?=.*[-.\d])/g,"");else{var w=$.search(/[-.\d]/);$=$.replace(/[-]/g,(function(e,i){return-1!==w&&i>w?"":e}))}$=$.replace(/(.+)(-)$/,"$2$1");var F="-"===p&&m===v,b=u.includes(f.minusSign),k=$.includes("-");if(F&&b&&k&&($=$.replace("-","")),!F||b||k||($="-".concat($)),/\..*0$/.test($)){var O="([".concat(f.digits,"])([").concat(f.decimal,"])([").concat(f.digits,"]+)"),z=RegExp(O).exec(u);if(null!==z){var I,B=z[3],T=Number(z[5])+z[1].length+z[2].length,N=null!==(I=n(V.current.props.locales,V.current.props.options).minimumFractionDigits)&&void 0!==I?I:0;m>=T&&v<T+(N||1)&&B.length<=(N||1)&&($=$.replace(/0+$/g,""))}}var P="deleteBackward"===i||"deleteForward"===i;if(P&&u.includes(f.decimal)&&!$.includes(".")){var L,_="[".concat(f.digits[0],"]*[^").concat(f.decimal).concat(f.digits,"]*$"),j="[^".concat(f.digits[0],"]"),H=null===(L=RegExp(_).exec(u))||void 0===L?void 0:L[0].replace(RegExp(j,"g"),"").length;void 0!==H&&void 0!==h.minimumFractionDigits&&(H>h.minimumFractionDigits&&(H=h.minimumFractionDigits),$=$.replace(RegExp("0{0,".concat(H,"}$")),""))}var q={value:"",number:0},A=""===$||"-"===$||/^-?(\.0*)?$/.test($);P&&A||(q=r($,{locales:g,options:S,localizedValues:x,resolvedOptions:h}));var C=function(e){var i=e.localizedValues,a=e.previousLocalizedValues,c=e.resolvedOptions,n=e.inputType,r=e.value,l=e.previousValue,s=e.addedValue,o=e.changeStart,d=e.changeEnd;if(l.includes(i.decimal)&&"."===s){var u=r.indexOf(i.decimal);if(-1!==u){var g=u+1;return{start:g,end:g}}}if(l.includes(i.minusSign)&&"-"===s){var p=r.indexOf(i.minusSign);if(-1!==p){var m=p+(i.signBackwards?0:1);return{start:m,end:m}}}if("deleteBackward"===n||"deleteForward"===n){var v=l.split(a.decimal),f=t(v,1)[0];if(d<=f.length&&!RegExp("[".concat(a.digits.slice(1),"]")).test(f)){var x=f.indexOf(a.digits[0]),h=f.lastIndexOf(a.digits[0]);if(-1!==x&&-1!==h){var D=h+1;if((o!==x||d!==D)&&d>x&&d<=D)return{start:x,end:D}}}}for(var E=void 0!==c.maximumIntegerDigits?Number(c.maximumIntegerDigits):void 0,y=r.length,R=0,$=0,w=!1;$<o;$++){var S=a.digits.includes(l[$]),V=l[$]===a.decimal;!w&&(V||S&&l[$]!==a.digits[0])&&(w=!0),w&&(V||S)&&(R+=1)}if("insert"===n){var F=l.slice(0,o),b=l.indexOf(a.decimal),k=F.replace(RegExp("[^".concat(a.decimal).concat(a.digits,"]"),"g"),"").replace(RegExp("^".concat(a.digits[0],"+"),"g"),"").split(a.decimal),O=t(k,2),z=O[0],I=O[1],B=void 0===I?"":I,T=-1!==b&&d<=b?"\\.":"\\.(?=.*\\.)",N=s.replace(RegExp("-|".concat(T),"g"),""),P=N.includes("."),L=N.split("."),_=t(L,2),j=_[0],H=_[1],q=void 0===H?"":H;if(-1!==b&&o>b)if(P){R-=1;var A=z+B;void 0!==E&&A.length>E&&(R=E,z=A.slice(0,E))}else q=j,j="";var C="[".concat(a.decimal).concat(a.digits.slice(1),"]");RegExp(C).test(F)||(j=j.replace(/^0+/g,""));var G=void 0!==E?E-z.length:void 0;R+=(j.slice(0,G)+(P?".":"")+q).replace(RegExp("[^\\.".concat(i.decimal,"\\d").concat(i.digits,"]+"),"g"),"").length}for(var J=0,K=!1,M=0;J<r.length;J++){var Q=i.digits.includes(r[J]),U=r[J]===i.decimal;if(!K&&(U||Q&&r[J]!==i.digits[0])&&(K=!0),K&&M>=R){y=J;break}K&&(U||Q)&&(M+=1)}if("deleteForward"===n){var W,X="\\".concat(i.minusSign),Y="^.{".concat(y,"}[^").concat(i.decimal).concat(i.digits,"]*[").concat(X).concat(i.decimal).concat(i.digits,"]"),Z=null===(W=RegExp(Y).exec(r))||void 0===W?void 0:W[0].length;void 0!==Z&&(y=Z-1)}else{var ee,ie="deleteBackward"===n?"\\".concat(i.minusSign):"",ae="[".concat(ie).concat(i.decimal).concat(i.digits,"][^").concat(i.decimal).concat(i.digits,"]*.{").concat(r.length-y,"}$"),te=null===(ee=RegExp(ae).exec(r))||void 0===ee?void 0:ee.index;void 0!==te&&(y=te+1)}var ce="[\\".concat(i.minusSign).concat(i.decimal).concat(i.digits.slice(1),"]"),ne="[\\".concat(i.minusSign).concat(i.decimal).concat(i.digits,"][^").concat(i.decimal).concat(i.digits,"]*$"),re=r.search(RegExp(ce)),le=r.search(RegExp(ne));return-1!==re&&y<re?y=re:-1!==le&&y>le+1&&(y=le+1),{start:y,end:y}}({localizedValues:x,previousLocalizedValues:f,resolvedOptions:h,inputType:i,value:q.value,previousValue:u,addedValue:p,changeStart:m,changeEnd:v});return V.current.value=q.value,V.current.props={locales:g,options:S},{value:q.value,selectionStart:C.start,selectionEnd:C.end,__detail:q}},eventType:"input-number-format",eventHandler:w})}export{u as default};

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

import{_ as a,l as o,r as s,f as e,b as l,u as r}from"./helpers-ZrL-K9bK.js";var t=["locales"];function n(l){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=r.locales,i=a(r,t),u=o(n),c=s(n,i);return e(l.toString(),{locales:n,options:i,localizedValues:u,resolvedOptions:c}).value}function i(a,s){var e=o(s),t=l(a,e);return r(t,e)}export{n as format,i as unformat};
import{_ as e,l as a,r as l,f as r,e as s,b as o,n}from"./helpers-bSXZ1mLm.js";var t=["locales"];function c(s){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=o.locales,c=e(o,t),i=a(n),p=l(n,c);return r(s.toString(),{locales:n,options:c,localizedValues:i,resolvedOptions:p}).value}function i(e,l){var r=a(l),t=e;return t=s(e,r),t=o(t,r),(t=n(t,r)).replace(/(.+)(-)$/,"$2$1").replace(/\.$/,"")}export{c as format,i as unformat};
{
"name": "@react-input/number-format",
"version": "1.1.1",
"version": "1.1.2",
"license": "MIT",

@@ -80,8 +80,8 @@ "author": "Nikolay Goncharuk <goncharuk.bro@gmail.com>",

"dependencies": {
"@react-input/core": "^1.0.18"
"@react-input/core": "^1.0.19"
},
"peerDependencies": {
"@types/react": ">=16.8",
"react": ">=16.8",
"react-dom": ">=16.8"
"react": ">=16.8 || ^19.0.0-rc",
"react-dom": ">=16.8 || ^19.0.0-rc"
},

@@ -88,0 +88,0 @@ "peerDependenciesMeta": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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