@react-input/number-format
Advanced tools
Comparing version 1.0.20 to 1.0.21
@@ -8,5 +8,3 @@ import type { CustomInputEvent, CustomInputEventHandler } from '@react-input/core'; | ||
export type NumberFormatEventHandler = CustomInputEventHandler<NumberFormatEvent>; | ||
type ResolveOptions<T extends { | ||
[key: string]: any; | ||
}> = Pick<T, 'currency' | 'currencyDisplay' | 'unit' | 'unitDisplay' | 'signDisplay' | 'minimumIntegerDigits' | 'minimumFractionDigits' | 'maximumFractionDigits'>; | ||
type ResolveOptions<T extends Record<string, any>> = Pick<T, 'currency' | 'currencyDisplay' | 'unit' | 'unitDisplay' | 'signDisplay' | 'minimumIntegerDigits' | 'minimumFractionDigits' | 'maximumFractionDigits'>; | ||
interface IncludedOptions { | ||
@@ -13,0 +11,0 @@ format?: Intl.NumberFormatOptions['style']; |
@@ -1,1 +0,1 @@ | ||
export{default as InputNumberFormat}from"./InputNumberFormat.js";export{u as useNumberFormat}from"./useNumberFormat-5d3209bd.js";import"react";import"@react-input/core"; | ||
export{default as InputNumberFormat}from"./InputNumberFormat.js";export{default as useNumberFormat}from"./useNumberFormat.js";import"react/jsx-runtime";import"react";import"@react-input/core"; |
@@ -1,10 +0,1 @@ | ||
import{_ as e,u as r,a as t}from"./useNumberFormat-5d3209bd.js";import n,{forwardRef as o}from"react";import{useConnectedInputRef as a}from"@react-input/core";var i,s={exports:{}},c={};var u,l={}; | ||
/** | ||
* @license React | ||
* react-jsx-runtime.development.js | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/"production"===process.env.NODE_ENV?s.exports=function(){if(i)return c;i=1;var e=n,r=Symbol.for("react.element"),t=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,a=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function u(e,t,n){var i,c={},u=null,l=null;for(i in void 0!==n&&(u=""+n),void 0!==t.key&&(u=""+t.key),void 0!==t.ref&&(l=t.ref),t)o.call(t,i)&&!s.hasOwnProperty(i)&&(c[i]=t[i]);if(e&&e.defaultProps)for(i in t=e.defaultProps)void 0===c[i]&&(c[i]=t[i]);return{$$typeof:r,type:e,key:u,ref:l,props:c,_owner:a.current}}return c.Fragment=t,c.jsx=u,c.jsxs=u,c}():s.exports=(u||(u=1,"production"!==process.env.NODE_ENV&&function(){var e=n,r=Symbol.for("react.element"),t=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),s=Symbol.for("react.provider"),c=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),f=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),d=Symbol.for("react.offscreen"),v=Symbol.iterator,g="@@iterator",b=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function h(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];!function(e,r,t){var n=b.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(r+="%s",t=t.concat([n]));var o=t.map((function(e){return String(e)}));o.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,o)}("error",e,t)}var _,k=!1,w=!1,S=!1,O=!1,j=!1;function D(e){return e.displayName||"Context"}function R(e){if(null==e)return null;if("number"==typeof e.tag&&h("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case o:return"Fragment";case t:return"Portal";case i:return"Profiler";case a:return"StrictMode";case f:return"Suspense";case p:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case c:return D(e)+".Consumer";case s:return D(e._context)+".Provider";case u:return function(e,r,t){var n=e.displayName;if(n)return n;var o=r.displayName||r.name||"";return""!==o?t+"("+o+")":t}(e,e.render,"ForwardRef");case y:var r=e.displayName||null;return null!==r?r:R(e.type)||"Memo";case m:var n=e,l=n._payload,d=n._init;try{return R(d(l))}catch(e){return null}}return null}_=Symbol.for("react.module.reference");var E,x,P,F,T,N,$,C=Object.assign,I=0;function L(){}L.__reactDisabledLog=!0;var W,U=b.ReactCurrentDispatcher;function A(e,r,t){if(void 0===W)try{throw Error()}catch(e){var n=e.stack.trim().match(/\n( *(at )?)/);W=n&&n[1]||""}return"\n"+W+e}var z,M=!1,Y="function"==typeof WeakMap?WeakMap:Map;function B(e,r){if(!e||M)return"";var t,n=z.get(e);if(void 0!==n)return n;M=!0;var o,a=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=U.current,U.current=null,function(){if(0===I){E=console.log,x=console.info,P=console.warn,F=console.error,T=console.group,N=console.groupCollapsed,$=console.groupEnd;var e={configurable:!0,enumerable:!0,value:L,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}I++}();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(i,[])}catch(e){t=e}Reflect.construct(e,[],i)}else{try{i.call()}catch(e){t=e}e.call(i.prototype)}}else{try{throw Error()}catch(e){t=e}e()}}catch(r){if(r&&t&&"string"==typeof r.stack){for(var s=r.stack.split("\n"),c=t.stack.split("\n"),u=s.length-1,l=c.length-1;u>=1&&l>=0&&s[u]!==c[l];)l--;for(;u>=1&&l>=0;u--,l--)if(s[u]!==c[l]){if(1!==u||1!==l)do{if(u--,--l<0||s[u]!==c[l]){var f="\n"+s[u].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&z.set(e,f),f}}while(u>=1&&l>=0);break}}}finally{M=!1,U.current=o,function(){if(0==--I){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:C({},e,{value:E}),info:C({},e,{value:x}),warn:C({},e,{value:P}),error:C({},e,{value:F}),group:C({},e,{value:T}),groupCollapsed:C({},e,{value:N}),groupEnd:C({},e,{value:$})})}I<0&&h("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=a}var p=e?e.displayName||e.name:"",y=p?A(p):"";return"function"==typeof e&&z.set(e,y),y}function V(e,r,t){if(null==e)return"";if("function"==typeof e)return B(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return A(e);switch(e){case f:return A("Suspense");case p:return A("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case u:return B(e.render,!1);case y:return V(e.type,r,t);case m:var o=e,a=o._payload,i=o._init;try{return V(i(a),r,t)}catch(e){}}return""}z=new Y;var q=Object.prototype.hasOwnProperty,H={},J=b.ReactDebugCurrentFrame;function X(e){if(e){var r=e._owner,t=V(e.type,e._source,r?r.type:null);J.setExtraStackFrame(t)}else J.setExtraStackFrame(null)}var G=Array.isArray;function K(e){return G(e)}function Q(e){return""+e}function Z(e){if(function(e){try{return Q(e),!1}catch(e){return!0}}(e))return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),Q(e)}var ee,re,te,ne=b.ReactCurrentOwner,oe={key:!0,ref:!0,__self:!0,__source:!0};te={};var ae=function(e,t,n,o,a,i,s){var c={$$typeof:r,type:e,key:t,ref:n,props:s,_owner:i,_store:{}};return Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c};function ie(e,r,t,n,o){var a,i={},s=null,c=null;for(a in void 0!==t&&(Z(t),s=""+t),function(e){if(q.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return void 0!==e.key}(r)&&(Z(r.key),s=""+r.key),function(e){if(q.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return void 0!==e.ref}(r)&&(c=r.ref,function(e,r){if("string"==typeof e.ref&&ne.current&&r&&ne.current.stateNode!==r){var t=R(ne.current.type);te[t]||(h('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',R(ne.current.type),e.ref),te[t]=!0)}}(r,o)),r)q.call(r,a)&&!oe.hasOwnProperty(a)&&(i[a]=r[a]);if(e&&e.defaultProps){var u=e.defaultProps;for(a in u)void 0===i[a]&&(i[a]=u[a])}if(s||c){var l="function"==typeof e?e.displayName||e.name||"Unknown":e;s&&function(e,r){var t=function(){ee||(ee=!0,h("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}(i,l),c&&function(e,r){var t=function(){re||(re=!0,h("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}(i,l)}return ae(e,s,c,o,n,ne.current,i)}var se,ce=b.ReactCurrentOwner,ue=b.ReactDebugCurrentFrame;function le(e){if(e){var r=e._owner,t=V(e.type,e._source,r?r.type:null);ue.setExtraStackFrame(t)}else ue.setExtraStackFrame(null)}function fe(e){return"object"==typeof e&&null!==e&&e.$$typeof===r}function pe(){if(ce.current){var e=R(ce.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}se=!1;var ye={};function me(e,r){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var t=function(e){var r=pe();if(!r){var t="string"==typeof e?e:e.displayName||e.name;t&&(r="\n\nCheck the top-level render call using <"+t+">.")}return r}(r);if(!ye[t]){ye[t]=!0;var n="";e&&e._owner&&e._owner!==ce.current&&(n=" It was passed a child from "+R(e._owner.type)+"."),le(e),h('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),le(null)}}}function de(e,r){if("object"==typeof e)if(K(e))for(var t=0;t<e.length;t++){var n=e[t];fe(n)&&me(n,r)}else if(fe(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var r=v&&e[v]||e[g];return"function"==typeof r?r:null}(e);if("function"==typeof o&&o!==e.entries)for(var a,i=o.call(e);!(a=i.next()).done;)fe(a.value)&&me(a.value,r)}}function ve(e){var r,t=e.type;if(null!=t&&"string"!=typeof t){if("function"==typeof t)r=t.propTypes;else{if("object"!=typeof t||t.$$typeof!==u&&t.$$typeof!==y)return;r=t.propTypes}if(r){var n=R(t);!function(e,r,t,n,o){var a=Function.call.bind(q);for(var i in e)if(a(e,i)){var s=void 0;try{if("function"!=typeof e[i]){var c=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw c.name="Invariant Violation",c}s=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){s=e}!s||s instanceof Error||(X(o),h("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof s),X(null)),s instanceof Error&&!(s.message in H)&&(H[s.message]=!0,X(o),h("Failed %s type: %s",t,s.message),X(null))}}(r,e.props,"prop",n,e)}else void 0===t.PropTypes||se||(se=!0,h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",R(t)||"Unknown"));"function"!=typeof t.getDefaultProps||t.getDefaultProps.isReactClassApproved||h("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ge(e,t,n,l,v,g){var b=function(e){return"string"==typeof e||"function"==typeof e||!!(e===o||e===i||j||e===a||e===f||e===p||O||e===d||k||w||S)||"object"==typeof e&&null!==e&&(e.$$typeof===m||e.$$typeof===y||e.$$typeof===s||e.$$typeof===c||e.$$typeof===u||e.$$typeof===_||void 0!==e.getModuleId)}(e);if(!b){var D="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(D+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var E,x=function(e){return void 0!==e?"\n\nCheck your code at "+e.fileName.replace(/^.*[\\\/]/,"")+":"+e.lineNumber+".":""}(v);D+=x||pe(),null===e?E="null":K(e)?E="array":void 0!==e&&e.$$typeof===r?(E="<"+(R(e.type)||"Unknown")+" />",D=" Did you accidentally export a JSX literal instead of a component?"):E=typeof e,h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",E,D)}var P=ie(e,t,n,v,g);if(null==P)return P;if(b){var F=t.children;if(void 0!==F)if(l)if(K(F)){for(var T=0;T<F.length;T++)de(F[T],e);Object.freeze&&Object.freeze(F)}else h("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else de(F,e)}return e===o?function(e){for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if("children"!==n&&"key"!==n){le(e),h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),le(null);break}}null!==e.ref&&(le(e),h("Invalid attribute `ref` supplied to `React.Fragment`."),le(null))}(P):ve(P),P}var be=function(e,r,t){return ge(e,r,t,!1)},he=function(e,r,t){return ge(e,r,t,!0)};l.Fragment=o,l.jsx=be,l.jsxs=he}()),l);var f=s.exports;var p=o((function(n,o){var i=n.component,s=n.locales,c=n.format,u=n.currency,l=n.currencyDisplay,p=n.unit,y=n.unitDisplay,m=n.signDisplay,d=n.groupDisplay,v=n.minimumIntegerDigits,g=n.maximumIntegerDigits,b=n.minimumFractionDigits,h=n.maximumFractionDigits,_=n.onNumberFormat,k=e(n,["component","locales","format","currency","currencyDisplay","unit","unitDisplay","signDisplay","groupDisplay","minimumIntegerDigits","maximumIntegerDigits","minimumFractionDigits","maximumFractionDigits","onNumberFormat"]),w=r({locales:s,format:c,currency:u,currencyDisplay:l,unit:p,unitDisplay:y,signDisplay:m,groupDisplay:d,minimumIntegerDigits:v,maximumIntegerDigits:g,minimumFractionDigits:b,maximumFractionDigits:h,onNumberFormat:_}),S=a(w,o);return i?f.jsx(i,t({ref:S},k)):f.jsx("input",t({ref:S},k))}));export{p as default}; | ||
import{jsx as i}from"react/jsx-runtime";import{forwardRef as r}from"react";import{useConnectedInputRef as m}from"@react-input/core";import t from"./useNumberFormat.js";const n=r((function({component:r,locales:n,format:o,currency:a,currencyDisplay:e,unit:u,unitDisplay:s,signDisplay:c,groupDisplay:p,minimumIntegerDigits:g,maximumIntegerDigits:D,minimumFractionDigits:l,maximumFractionDigits:y,onNumberFormat:f,...F},x){const I=t({locales:n,format:o,currency:a,currencyDisplay:e,unit:u,unitDisplay:s,signDisplay:c,groupDisplay:p,minimumIntegerDigits:g,maximumIntegerDigits:D,minimumFractionDigits:l,maximumFractionDigits:y,onNumberFormat:f}),b=m(I,x);return i(r||"input",{ref:b,...F})}));export{n as default}; |
@@ -1,1 +0,1 @@ | ||
import"react";import"@react-input/core";export{u as default}from"./useNumberFormat-5d3209bd.js"; | ||
import{useEffect as e,useRef as i,useCallback as t}from"react";import{SyntheticChangeError as n,useInput as s}from"@react-input/core";function r(e,i={}){const{format:t,groupDisplay:n,maximumIntegerDigits:s=21,...r}=i,l=Intl.NumberFormat(e,{...r,style:t,useGrouping:n}).resolvedOptions();l.format=l.style,l.groupDisplay=l.useGrouping,l.maximumIntegerDigits=s,l.maximumIntegerDigits<l.minimumIntegerDigits&&(l.maximumIntegerDigits=l.minimumIntegerDigits);const a=l;return delete a.style,delete a.currencySign,delete a.useGrouping,delete a.minimumSignificantDigits,delete a.maximumSignificantDigits,delete a.compactDisplay,delete a.notation,delete a.numberingSystem,delete a.localeMatcher,delete a.roundingIncrement,delete a.roundingMode,delete a.roundingPriority,delete a.trailingZeroDisplay,{current:i,resolved:l}}function l(e){const i=Intl.NumberFormat(e,{useGrouping:!1,signDisplay:"always",minimumIntegerDigits:10,minimumFractionDigits:1,maximumFractionDigits:1}).format(-1234567890.1),t=i.startsWith("")||i.startsWith(""),n=t?i[1]:i[0],s=i[i.length-2];let r=i.slice(t?2:1,-2);return r=r[9]+r.slice(0,-1),{signBackwards:t,minusSign:n,decimal:s,digits:r}}function a({resolvedOptions:e}){const{minimumFractionDigits:i=0}=e;return i<0?0:i}function c(c){const{locales:g,format:o,currency:u,currencyDisplay:m,unit:d,unitDisplay:p,signDisplay:$,groupDisplay:f,minimumIntegerDigits:x,maximumIntegerDigits:D,minimumFractionDigits:h,maximumFractionDigits:v,onNumberFormat:E}=c??{},y={format:o,currency:u,currencyDisplay:m,unit:d,unitDisplay:p,signDisplay:$,groupDisplay:f,minimumIntegerDigits:x,maximumIntegerDigits:D,minimumFractionDigits:h,maximumFractionDigits:v},I=i(null),R=JSON.stringify(g),S=JSON.stringify(y),O=t((({initialValue:e})=>{const i={locales:g,options:y};return I.current={value:e,props:i,fallbackProps:i},{value:e}}),[]),w=t((({inputType:e,addedValue:i,previousValue:t,changeStart:s,changeEnd:c})=>{if(null===I.current)throw new n("The state has not been initialized.");I.current.value!==t?I.current.props=I.current.fallbackProps:I.current.fallbackProps=I.current.props;const o=l(I.current.props.locales),u=l(g),{current:m,resolved:d}=r(g,y),p=e=>{const i=`\\-\\${u.minusSign}`,t=`.,${u.decimal}`,n=`\\d${u.digits}`,s=`[^${i}${t}${n}]|[${t}](?=.*[${t}])`,r=e.replace(RegExp(s,"g"),"");if(u.signBackwards)return r.replace(RegExp(`[${i}](?=.*[${i}${t}${n}])`,"g"),"");const l=r.search(RegExp(`[${i}]`)),a=r.search(RegExp(`[${t}]`)),c=r.search(RegExp(`[${n}]`));return r.replace(RegExp(`[${i}]`,"g"),((e,i)=>-1!==l&&i>l||-1!==a&&i>a||-1!==c&&i>c?"":e))};if(i=p(i),"insert"===e&&!i)throw new n("The added value does not contain allowed characters.");const $=RegExp(`[^\\${o.minusSign}${o.decimal}${o.digits}]`,"g");let f=t.slice(0,s).replace($,"")+i+t.slice(c).replace($,"");f=p(f).replace(RegExp(`[,${u.decimal}]`,"g"),".").replace(RegExp(u.minusSign,"g"),"-").replace(RegExp(`[${u.digits}]`,"g"),(e=>{const i=u.digits.indexOf(e);return-1!==i?i.toString():e}));{const e=RegExp(`^[\\-\\${u.minusSign}]$`).test(i)&&s===c,n=t.includes(o.minusSign),r=f.includes("-");e&&n&&r&&(f=f.replace("-","")),!e||n||r||(f=`-${f}`)}if(f.endsWith("-")&&(f=`-${f.slice(0,-1)}`),/\..*0$/.test(f)){let e="",i=-1;for(let n=0,s=!1;n<t.length;n++){const r=o.digits.includes(t[n]),l=t[n]===o.decimal;s?r&&(e+=t[n],-1===i&&(i=n)):l&&(s=!0)}if(-1!==i){const t=a({resolvedOptions:r(I.current.props.locales,I.current.props.options).resolved});s>=i&&c<i+(t||1)&&e.length<=(t||1)&&(f=f.replace(/0+$/g,""))}}const x=function(e,{inputType:i,locales:t,localizedValues:n,currentOptions:s,resolvedOptions:r}){if(("deleteBackward"===i||"deleteForward"===i)&&(""===e||"-"===e||/^-?\.?0*$/.test(e)))return{value:"",number:0};const l=e.startsWith("-"),c=l?e.slice(1):e;let[g,o]=c.split("."),u=r.minimumFractionDigits;const m=r.maximumFractionDigits;g=g.replace(/^0+/g,"").slice(0,r.maximumIntegerDigits),o=o?.slice(0,m);const d=Number((l?"-":"")+(g||"0")+(o?`.${o}`:""));u=a({resolvedOptions:r}),"insert"===i&&""===o&&0===u&&m>0&&(u=1),void 0!==o&&o.length>u&&(u=o.length);const{format:p,groupDisplay:$,maximumIntegerDigits:f,...x}=s??{};let D=Intl.NumberFormat(t,{...x,style:p,useGrouping:$,minimumFractionDigits:u}).format(d);D=D.replace(/\s/g," ");const h=D.includes("+")?"+":D.includes(n.minusSign)?n.minusSign:void 0;if(void 0!==h&&n.signBackwards){D=D.replace(RegExp(`[\\${h}]`,"g"),"");const e=D.search(RegExp(`[${n.digits}](?!.*[${n.digits}])`));-1!==e&&(D=D.slice(0,e+1)+h+D.slice(e+1),D.startsWith("")||(D=`${D}`))}return{value:D,number:d}}(f,{inputType:e,locales:g,localizedValues:u,currentOptions:m,resolvedOptions:d}),D=function({localizedValues:e,previousLocalizedValues:i,resolvedOptions:t,inputType:n,addedValue:s,previousValue:r,nextValue:l,changeStart:a,changeEnd:c}){if(RegExp(`^[.,${e.decimal}]$`).test(s)&&r.includes(e.decimal)){const i=l.indexOf(e.decimal);if(-1!==i){const e=i+1;return{start:e,end:e}}}if(RegExp(`^[\\-\\${e.minusSign}]$`).test(s)&&r.includes(e.minusSign)){const i=l.indexOf(e.minusSign);if(-1!==i){const t=i+(e.signBackwards?0:1);return{start:t,end:t}}}if("deleteBackward"===n||"deleteForward"===n){const[e]=r.split(i.decimal);if(c<=e.length&&!RegExp(`[${i.digits.slice(1)}]`).test(e)){const t=e.indexOf(i.digits[0]),n=e.lastIndexOf(i.digits[0]);if(-1!==t&&-1!==n&&(a!==t||c!==n+1)&&c>t&&c<=n+1)return{start:t,end:n+1}}}let g=l.length,o=0;for(let e=0,t=!1;e<a;e++){const n=i.digits.includes(r[e]);if(!t){const s=r[e]===i.decimal,l=n&&r[e]!==i.digits[0];(s||l)&&(t=!0)}t&&n&&(o+=1)}if("insert"===n){const n=r.slice(0,a);let[l,g=""]=n.replace(RegExp(`[^${i.decimal}${i.digits}]`,"g"),"").replace(RegExp(`^${i.digits[0]}+`,"g"),"").split(i.decimal);const u=RegExp(`[^\\d${e.digits}]+`,"g"),m=r.indexOf(i.decimal);let d=s.replace(RegExp(`[\\-\\${e.minusSign}]`,"g"),"").replace(RegExp(`[,${e.decimal}]`,"g"),".");-1!==m&&c<=m&&(d=d.replace(u,""));let[p,$=""]=d.split(".");if(-1!==m&&a>m)if(d.includes(".")){const e=l+g;e.length>t.maximumIntegerDigits&&(o=t.maximumIntegerDigits,l=e.slice(0,t.maximumIntegerDigits))}else $=p,p="";const f=`[${i.decimal}${i.digits.slice(1)}]`;if(!RegExp(f).test(n)){const e=`^[0${i.digits[0]}]+`;p=p.replace(RegExp(e,"g"),"")}o+=(p.slice(0,t.maximumIntegerDigits-l.length)+$).replace(u,"").length}for(let i=0,t=!1,n=0;i<l.length;i++){if(t||e.decimal!==l[i]&&!e.digits.slice(1).includes(l[i])||(t=!0),t&&n>=o){g=i;break}t&&e.digits.includes(l[i])&&(n+=1)}if("deleteForward"===n){const i=`^.{${g}}[^${e.digits}]*[\\${e.minusSign}${e.digits}]`,t=l.match(RegExp(i))?.[0].length;void 0!==t&&(g=t-1)}else{const i=`[${"deleteBackward"===n?`\\${e.minusSign}`:""}${e.digits}][^${e.digits}]*.{${l.length-g}}$`,t=l.match(RegExp(i))?.index;void 0!==t&&(g=t+1),l[g]===e.decimal&&RegExp(`[.,${e.decimal}]`).test(s[s.length-1]??"")&&(g+=1)}{const i=`[\\${e.minusSign}${e.decimal}${e.digits.slice(1)}]`,t=`[\\${e.minusSign}${e.digits}][^${e.digits}]*$`,n=l.search(RegExp(i)),s=l.search(RegExp(t));-1!==n&&g<n?g=n:-1!==s&&g>s+1&&(g=s+1)}return{start:g,end:g}}({localizedValues:u,previousLocalizedValues:o,resolvedOptions:d,inputType:e,addedValue:i,previousValue:t,nextValue:x.value,changeStart:s,changeEnd:c});return I.current.value=x.value,I.current.props={locales:g,options:y},{value:x.value,selectionStart:D.start,selectionEnd:D.end,__detail:x}}),[R,S]),F=s({init:O,tracking:w,customInputEventType:"input-number-format",customInputEventHandler:E});return function({locales:i,options:t}){e((()=>{if("production"===process.env.NODE_ENV)return;const{current:e,resolved:n}=r(i,t),s="number"!=typeof e.maximumIntegerDigits&&void 0!==e.maximumIntegerDigits,l="number"==typeof e.maximumIntegerDigits&&e.maximumIntegerDigits<n.minimumIntegerDigits;if(s||l)throw new RangeError("maximumIntegerDigits value is out of range.")}),[])}({locales:g,options:y}),F}export{c as default}; |
{ | ||
"name": "@react-input/number-format", | ||
"version": "1.0.20", | ||
"version": "1.0.21", | ||
"author": "Nikolay Goncharuk <goncharuk.bro@gmail.com>", | ||
@@ -88,10 +88,10 @@ "description": "React input component for formatted number input with locale-specific.", | ||
"scripts": { | ||
"remove:dist": "node ../../scripts/remove-dist.js", | ||
"clear:types": "node ../../scripts/clear-types.js", | ||
"restore:dist": "node ../../scripts/restore-dist.js", | ||
"remove:dist": "ts-node ../../scripts/remove-dist.ts", | ||
"clear:types": "ts-node ../../scripts/clear-types.ts", | ||
"restore:dist": "ts-node ../../scripts/restore-dist.ts", | ||
"build:rollup": "rollup --config rollup.config.js", | ||
"build": "npm run remove:dist && npm run build:rollup && npm run clear:types && npm run restore:dist && node ../../scripts/console-success.js" | ||
"build": "npm run remove:dist && npm run build:rollup && npm run clear:types && npm run restore:dist && ts-node ../../scripts/console-success.ts" | ||
}, | ||
"dependencies": { | ||
"@react-input/core": "^1.0.5" | ||
"@react-input/core": "^1.0.7" | ||
}, | ||
@@ -98,0 +98,0 @@ "peerDependencies": { |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances 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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
2
49709
13
109
1
Updated@react-input/core@^1.0.7