use-mask-input 3.0.6 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +13 -19
  2. package/dist/index.cjs +191 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +34 -3
  5. package/dist/index.js +184 -1
  6. package/dist/index.js.map +1 -1
  7. package/package.json +49 -48
  8. package/src/index.tsx +3 -2
  9. package/src/types.ts +6 -0
  10. package/src/useMaskInput.ts +12 -9
  11. package/src/utils.spec.ts +14 -0
  12. package/src/utils.ts +23 -0
  13. package/src/withHookFormMask.ts +8 -17
  14. package/src/withMask.ts +5 -6
  15. package/dist/example/App.example.d.ts +0 -3
  16. package/dist/example/index.d.ts +0 -1
  17. package/dist/index.modern.js +0 -2
  18. package/dist/index.modern.js.map +0 -1
  19. package/dist/index.umd.js +0 -2
  20. package/dist/index.umd.js.map +0 -1
  21. package/dist/useMaskInput.d.ts +0 -9
  22. package/dist/withHookFormMask.d.ts +0 -16
  23. package/dist/withMask.d.ts +0 -3
  24. package/node_modules/inputmask/LICENSE.txt +0 -7
  25. package/node_modules/inputmask/README.md +0 -1279
  26. package/node_modules/inputmask/bundle.js +0 -6
  27. package/node_modules/inputmask/dist/bindings/inputmask.binding.js +0 -26
  28. package/node_modules/inputmask/dist/inputmask.es6.js +0 -5
  29. package/node_modules/inputmask/dist/inputmask.js +0 -3031
  30. package/node_modules/inputmask/dist/inputmask.min.js +0 -8
  31. package/node_modules/inputmask/dist/jquery.inputmask.js +0 -2985
  32. package/node_modules/inputmask/dist/jquery.inputmask.min.js +0 -8
  33. package/node_modules/inputmask/lib/bindings/inputmask.binding.js +0 -26
  34. package/node_modules/inputmask/lib/bindings/inputmask.es6.js +0 -5
  35. package/node_modules/inputmask/lib/canUseDOM.js +0 -7
  36. package/node_modules/inputmask/lib/defaults.js +0 -101
  37. package/node_modules/inputmask/lib/definitions.js +0 -13
  38. package/node_modules/inputmask/lib/dependencyLibs/data.js +0 -8
  39. package/node_modules/inputmask/lib/dependencyLibs/events.js +0 -199
  40. package/node_modules/inputmask/lib/dependencyLibs/extend.js +0 -58
  41. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jquery.js +0 -13
  42. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.js +0 -41
  43. package/node_modules/inputmask/lib/environment.js +0 -9
  44. package/node_modules/inputmask/lib/escapeRegex.js +0 -4
  45. package/node_modules/inputmask/lib/eventhandlers.js +0 -513
  46. package/node_modules/inputmask/lib/eventruler.js +0 -124
  47. package/node_modules/inputmask/lib/extensions/inputmask.date.extensions.js +0 -588
  48. package/node_modules/inputmask/lib/extensions/inputmask.extensions.js +0 -133
  49. package/node_modules/inputmask/lib/extensions/inputmask.numeric.extensions.js +0 -631
  50. package/node_modules/inputmask/lib/global/window.js +0 -3
  51. package/node_modules/inputmask/lib/inputHandling.js +0 -252
  52. package/node_modules/inputmask/lib/inputmask.js +0 -355
  53. package/node_modules/inputmask/lib/inputmaskElement.js +0 -33
  54. package/node_modules/inputmask/lib/jquery.inputmask.js +0 -81
  55. package/node_modules/inputmask/lib/keycode.json +0 -25
  56. package/node_modules/inputmask/lib/mask-lexer.js +0 -467
  57. package/node_modules/inputmask/lib/mask.js +0 -244
  58. package/node_modules/inputmask/lib/masktoken.js +0 -13
  59. package/node_modules/inputmask/lib/polyfills/Array.includes.js +0 -48
  60. package/node_modules/inputmask/lib/polyfills/Object.getPrototypeOf.js +0 -7
  61. package/node_modules/inputmask/lib/positioning.js +0 -348
  62. package/node_modules/inputmask/lib/validation-tests.js +0 -597
  63. package/node_modules/inputmask/lib/validation.js +0 -664
  64. package/node_modules/inputmask/package.json +0 -60
  65. package/src/example/App.example.tsx +0 -68
  66. package/src/example/index.tsx +0 -5
@@ -1,5 +1,6 @@
1
1
  import { useEffect, useRef } from 'react';
2
2
  import Inputmask from 'inputmask';
3
+ import { isServer } from './utils';
3
4
 
4
5
  interface UseInputMaskOptions {
5
6
  mask: Inputmask.Options['mask']
@@ -9,21 +10,23 @@ interface UseInputMaskOptions {
9
10
 
10
11
  const useInputMask = (props: UseInputMaskOptions) => {
11
12
  const { mask, register, options } = props;
12
-
13
13
  const ref = useRef<HTMLInputElement>(null);
14
+ if (isServer) return ref;
14
15
 
15
16
  useEffect(() => {
16
- if (!ref.current) return;
17
+ if (!isServer) {
18
+ if (!ref.current) return;
17
19
 
18
- const maskInput = Inputmask({
19
- mask,
20
- ...options,
21
- });
20
+ const maskInput = Inputmask({
21
+ mask,
22
+ ...options,
23
+ });
22
24
 
23
- maskInput.mask(ref.current);
25
+ maskInput.mask(ref.current);
24
26
 
25
- if (register && ref.current) {
26
- register(ref.current);
27
+ if (register && ref.current) {
28
+ register(ref.current);
29
+ }
27
30
  }
28
31
  }, [mask, register, options]);
29
32
 
@@ -0,0 +1,14 @@
1
+ import { describe } from 'vitest';
2
+
3
+ import { flow } from './utils';
4
+
5
+ describe('utils', (it) => {
6
+ it('flow', ({ expect }) => {
7
+ const res = flow(
8
+ (a: number) => a + 1,
9
+ (a:number) => a + 2,
10
+ )(1);
11
+
12
+ expect(res).toBe(4);
13
+ });
14
+ });
package/src/utils.ts ADDED
@@ -0,0 +1,23 @@
1
+ export const isServer = !(
2
+ typeof window !== 'undefined'
3
+ && window.document
4
+ && window.document.createElement
5
+ );
6
+
7
+ export function flow(...funcs: Array<Function>) : Function {
8
+ const { length } = funcs;
9
+ let index = length;
10
+ while (index--) {
11
+ if (typeof funcs[index] !== 'function') {
12
+ throw new TypeError('Expected a function');
13
+ }
14
+ }
15
+ return (...args: Array<Function>) => {
16
+ let i = 0;
17
+ let result = length ? funcs[i].apply(this, args) : args[0];
18
+ while (++i < length) {
19
+ result = funcs[i].call(this, result);
20
+ }
21
+ return result;
22
+ };
23
+ }
@@ -1,36 +1,27 @@
1
- /* eslint-disable @typescript-eslint/space-before-blocks */
2
- /* eslint-disable @typescript-eslint/no-unused-vars */
3
1
  import Inputmask from 'inputmask';
4
- import type { UseFormRegisterReturn } from 'react-hook-form';
5
- import flowright from 'lodash.flowright';
2
+ import { flow } from './utils';
3
+ import { Mask, Options, Register } from './types';
6
4
 
7
- const withHookFormMask = (
8
- registerReturn: UseFormRegisterReturn,
9
- mask: Inputmask.Options['mask'],
10
- options?: Inputmask.Options,
11
- ) => {
5
+ export const withHookFormMask = (register: Register, mask: Mask, options?: Options) => {
12
6
  //
13
7
  let newRef;
14
8
 
15
- if (registerReturn){
16
- const { ref } = registerReturn;
9
+ if (register) {
10
+ const { ref } = register;
17
11
 
18
12
  const maskInput = Inputmask({
19
13
  mask,
20
- jitMasking: true,
21
14
  ...options,
22
15
  });
23
16
 
24
- newRef = flowright(ref, (_ref) => {
17
+ newRef = flow((_ref: HTMLElement) => {
25
18
  if (_ref) maskInput.mask(_ref);
26
19
  return _ref;
27
- });
20
+ }, ref);
28
21
  }
29
22
 
30
23
  return {
31
- ...registerReturn,
24
+ ...register,
32
25
  ref: newRef,
33
26
  };
34
27
  };
35
-
36
- export default withHookFormMask;
package/src/withMask.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import Inputmask from 'inputmask';
2
+ import { isServer } from './utils';
3
+ import { Input, Mask, Options } from './types';
2
4
 
3
- const withFinalFormMask = (
4
- mask: Inputmask.Options['mask'],
5
- options?: Inputmask.Options,
6
- ) => (input: HTMLElement | HTMLInputElement | null) => {
5
+ export const withMask = (mask: Mask, options?: Options) => (input: Input) => {
7
6
  //
7
+ if (isServer) return input;
8
+
8
9
  const maskInput = Inputmask({
9
10
  mask,
10
11
  ...options,
@@ -16,5 +17,3 @@ const withFinalFormMask = (
16
17
 
17
18
  return input;
18
19
  };
19
-
20
- export default withFinalFormMask;
@@ -1,3 +0,0 @@
1
- /// <reference types="react" />
2
- declare function App(): JSX.Element;
3
- export default App;
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import{useRef as r,useEffect as t}from"react";import n from"inputmask";import a from"lodash.flowright";function e(){return(e=Object.assign?Object.assign.bind():function(r){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(r[a]=n[a])}return r}).apply(this,arguments)}var o=function(r,t,o){var i;if(r){var u=r.ref,s=n(e({mask:t,jitMasking:!0},o));i=a(u,function(r){return r&&s.mask(r),r})}return e({},r,{ref:i})},i=function(r,t){return function(a){var o=n(e({mask:r},t));return a&&o.mask(a),a}};export default function(a){var o=a.mask,i=a.register,u=a.options,s=r(null);return t(function(){s.current&&(n(e({mask:o},u)).mask(s.current),i&&s.current&&i(s.current))},[o,i,u]),s}export{o as withHookFormMask,i as withMask};
2
- //# sourceMappingURL=index.modern.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.modern.js","sources":["../src/useMaskInput.ts","../src/withHookFormMask.ts","../src/withMask.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport Inputmask from 'inputmask';\n\ninterface UseInputMaskOptions {\n mask: Inputmask.Options['mask']\n register?(element: HTMLElement): void\n options?: Inputmask.Options\n}\n\nconst useInputMask = (props: UseInputMaskOptions) => {\n const { mask, register, options } = props;\n\n const ref = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (!ref.current) return;\n\n const maskInput = Inputmask({\n mask,\n ...options,\n });\n\n maskInput.mask(ref.current);\n\n if (register && ref.current) {\n register(ref.current);\n }\n }, [mask, register, options]);\n\n return ref;\n};\n\nexport default useInputMask;\n","/* eslint-disable @typescript-eslint/space-before-blocks */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport Inputmask from 'inputmask';\nimport type { UseFormRegisterReturn } from 'react-hook-form';\nimport flowright from 'lodash.flowright';\n\nconst withHookFormMask = (\n registerReturn: UseFormRegisterReturn,\n mask: Inputmask.Options['mask'],\n options?: Inputmask.Options,\n) => {\n //\n let newRef;\n\n if (registerReturn){\n const { ref } = registerReturn;\n\n const maskInput = Inputmask({\n mask,\n jitMasking: true,\n ...options,\n });\n\n newRef = flowright(ref, (_ref) => {\n if (_ref) maskInput.mask(_ref);\n return _ref;\n });\n }\n\n return {\n ...registerReturn,\n ref: newRef,\n };\n};\n\nexport default withHookFormMask;\n","import Inputmask from 'inputmask';\n\nconst withFinalFormMask = (\n mask: Inputmask.Options['mask'],\n options?: Inputmask.Options,\n) => (input: HTMLElement | HTMLInputElement | null) => {\n //\n const maskInput = Inputmask({\n mask,\n ...options,\n });\n\n if (input) {\n maskInput.mask(input);\n }\n\n return input;\n};\n\nexport default withFinalFormMask;\n"],"names":["registerReturn","mask","options","ref","Inputmask","jitMasking","newRef","flowright","_ref","maskInput","input","props","register","useRef","useEffect","current"],"mappings":"0UASA,MCHyB,SACvBA,EACAC,EACAC,GAGA,MAEA,GAAIF,EAAe,CACjB,MAAgBA,EAARG,MAEUC,KAChBH,KAAAA,EACAI,YAAY,GACTH,IAGLI,EAASC,EAAUJ,EAAK,SAACK,GAEvB,OADIA,GAAMC,EAAUR,KAAKO,OAK7B,YACKR,GACHG,IAAKG,OC7BiB,SACxBL,EACAC,mBACIQ,GAEJ,MAAkBN,KAChBH,KAAAA,GACGC,IAOL,OAJIQ,GACFD,EAAUR,KAAKS,sBFJE,SAACC,GACpB,MAAoCA,EAA5BV,KAAMW,EAAsBD,EAAtBC,SAAUV,EAAYS,EAAZT,UAEZW,EAAyB,MAiBrC,OAfAC,EAAU,WACHX,EAAIY,UAESX,KAChBH,KAAAA,GACGC,IAGKD,KAAKE,EAAIY,SAEfH,GAAYT,EAAIY,SAClBH,EAAST,EAAIY,WAEd,CAACd,EAAMW,EAAUV"}
package/dist/index.umd.js DELETED
@@ -1,2 +0,0 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("inputmask"),require("lodash.flowright")):"function"==typeof define&&define.amd?define(["exports","react","inputmask","lodash.flowright"],e):e((t=t||self).useMaskInput={},t.react,t.inputmask,t.flowright)}(this,function(t,e,r,n){function a(){return(a=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n,t.default=function(t){var n=t.mask,o=t.register,u=t.options,i=e.useRef(null);return e.useEffect(function(){i.current&&(r(a({mask:n},u)).mask(i.current),o&&i.current&&o(i.current))},[n,o,u]),i},t.withHookFormMask=function(t,e,o){var u;if(t){var i=t.ref,f=r(a({mask:e,jitMasking:!0},o));u=n(i,function(t){return t&&f.mask(t),t})}return a({},t,{ref:u})},t.withMask=function(t,e){return function(n){var o=r(a({mask:t},e));return n&&o.mask(n),n}}});
2
- //# sourceMappingURL=index.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/useMaskInput.ts","../src/withHookFormMask.ts","../src/withMask.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport Inputmask from 'inputmask';\n\ninterface UseInputMaskOptions {\n mask: Inputmask.Options['mask']\n register?(element: HTMLElement): void\n options?: Inputmask.Options\n}\n\nconst useInputMask = (props: UseInputMaskOptions) => {\n const { mask, register, options } = props;\n\n const ref = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (!ref.current) return;\n\n const maskInput = Inputmask({\n mask,\n ...options,\n });\n\n maskInput.mask(ref.current);\n\n if (register && ref.current) {\n register(ref.current);\n }\n }, [mask, register, options]);\n\n return ref;\n};\n\nexport default useInputMask;\n","/* eslint-disable @typescript-eslint/space-before-blocks */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport Inputmask from 'inputmask';\nimport type { UseFormRegisterReturn } from 'react-hook-form';\nimport flowright from 'lodash.flowright';\n\nconst withHookFormMask = (\n registerReturn: UseFormRegisterReturn,\n mask: Inputmask.Options['mask'],\n options?: Inputmask.Options,\n) => {\n //\n let newRef;\n\n if (registerReturn){\n const { ref } = registerReturn;\n\n const maskInput = Inputmask({\n mask,\n jitMasking: true,\n ...options,\n });\n\n newRef = flowright(ref, (_ref) => {\n if (_ref) maskInput.mask(_ref);\n return _ref;\n });\n }\n\n return {\n ...registerReturn,\n ref: newRef,\n };\n};\n\nexport default withHookFormMask;\n","import Inputmask from 'inputmask';\n\nconst withFinalFormMask = (\n mask: Inputmask.Options['mask'],\n options?: Inputmask.Options,\n) => (input: HTMLElement | HTMLInputElement | null) => {\n //\n const maskInput = Inputmask({\n mask,\n ...options,\n });\n\n if (input) {\n maskInput.mask(input);\n }\n\n return input;\n};\n\nexport default withFinalFormMask;\n"],"names":["props","mask","register","options","useRef","useEffect","ref","current","Inputmask","registerReturn","jitMasking","newRef","flowright","_ref","maskInput","input"],"mappings":"8rBASqB,SAACA,GACpB,MAAoCA,EAA5BC,KAAMC,EAAsBF,EAAtBE,SAAUC,EAAYH,EAAZG,UAEZC,SAAyB,MAiBrC,OAfAC,YAAU,WACHC,EAAIC,UAESC,KAChBP,KAAAA,GACGE,IAGKF,KAAKK,EAAIC,SAEfL,GAAYI,EAAIC,SAClBL,EAASI,EAAIC,WAEd,CAACN,EAAMC,EAAUC,0BCrBG,SACvBM,EACAR,EACAE,GAGA,MAEA,GAAIM,EAAe,CACjB,MAAgBA,EAARH,MAEUE,KAChBP,KAAAA,EACAS,YAAY,GACTP,IAGLQ,EAASC,EAAUN,EAAK,SAACO,GAEvB,OADIA,GAAMC,EAAUb,KAAKY,OAK7B,YACKJ,GACHH,IAAKK,gBC7BiB,SACxBV,EACAE,mBACIY,GAEJ,MAAkBP,KAChBP,KAAAA,GACGE,IAOL,OAJIY,GACFD,EAAUb,KAAKc"}
@@ -1,9 +0,0 @@
1
- /// <reference types="react" />
2
- import Inputmask from 'inputmask';
3
- interface UseInputMaskOptions {
4
- mask: Inputmask.Options['mask'];
5
- register?(element: HTMLElement): void;
6
- options?: Inputmask.Options;
7
- }
8
- declare const useInputMask: (props: UseInputMaskOptions) => import("react").RefObject<HTMLInputElement>;
9
- export default useInputMask;
@@ -1,16 +0,0 @@
1
- import Inputmask from 'inputmask';
2
- import type { UseFormRegisterReturn } from 'react-hook-form';
3
- declare const withHookFormMask: (registerReturn: UseFormRegisterReturn, mask: Inputmask.Options['mask'], options?: Inputmask.Options | undefined) => {
4
- ref: ((_ref: any) => void) | undefined;
5
- onChange: import("react-hook-form").ChangeHandler;
6
- onBlur: import("react-hook-form").ChangeHandler;
7
- name: string;
8
- min?: string | number | undefined;
9
- max?: string | number | undefined;
10
- maxLength?: number | undefined;
11
- minLength?: number | undefined;
12
- pattern?: string | undefined;
13
- required?: boolean | undefined;
14
- disabled?: boolean | undefined;
15
- };
16
- export default withHookFormMask;
@@ -1,3 +0,0 @@
1
- import Inputmask from 'inputmask';
2
- declare const withFinalFormMask: (mask: Inputmask.Options['mask'], options?: Inputmask.Options | undefined) => (input: HTMLElement | HTMLInputElement | null) => HTMLElement | HTMLInputElement | null;
3
- export default withFinalFormMask;
@@ -1,7 +0,0 @@
1
- Copyright (c) 2010 - 2018 Robin Herbots
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.