use-mask-input 3.0.6 → 3.1.0

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 (65) hide show
  1. package/dist/index.cjs +178 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.ts +34 -3
  4. package/dist/index.js +171 -1
  5. package/dist/index.js.map +1 -1
  6. package/package.json +43 -43
  7. package/src/index.tsx +3 -2
  8. package/src/types.ts +6 -0
  9. package/src/useMaskInput.ts +12 -9
  10. package/src/utils.spec.ts +13 -0
  11. package/src/utils.ts +27 -0
  12. package/src/withHookFormMask.ts +9 -16
  13. package/src/withMask.ts +5 -6
  14. package/dist/example/App.example.d.ts +0 -3
  15. package/dist/example/index.d.ts +0 -1
  16. package/dist/index.modern.js +0 -2
  17. package/dist/index.modern.js.map +0 -1
  18. package/dist/index.umd.js +0 -2
  19. package/dist/index.umd.js.map +0 -1
  20. package/dist/useMaskInput.d.ts +0 -9
  21. package/dist/withHookFormMask.d.ts +0 -16
  22. package/dist/withMask.d.ts +0 -3
  23. package/node_modules/inputmask/LICENSE.txt +0 -7
  24. package/node_modules/inputmask/README.md +0 -1279
  25. package/node_modules/inputmask/bundle.js +0 -6
  26. package/node_modules/inputmask/dist/bindings/inputmask.binding.js +0 -26
  27. package/node_modules/inputmask/dist/inputmask.es6.js +0 -5
  28. package/node_modules/inputmask/dist/inputmask.js +0 -3031
  29. package/node_modules/inputmask/dist/inputmask.min.js +0 -8
  30. package/node_modules/inputmask/dist/jquery.inputmask.js +0 -2985
  31. package/node_modules/inputmask/dist/jquery.inputmask.min.js +0 -8
  32. package/node_modules/inputmask/lib/bindings/inputmask.binding.js +0 -26
  33. package/node_modules/inputmask/lib/bindings/inputmask.es6.js +0 -5
  34. package/node_modules/inputmask/lib/canUseDOM.js +0 -7
  35. package/node_modules/inputmask/lib/defaults.js +0 -101
  36. package/node_modules/inputmask/lib/definitions.js +0 -13
  37. package/node_modules/inputmask/lib/dependencyLibs/data.js +0 -8
  38. package/node_modules/inputmask/lib/dependencyLibs/events.js +0 -199
  39. package/node_modules/inputmask/lib/dependencyLibs/extend.js +0 -58
  40. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jquery.js +0 -13
  41. package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.js +0 -41
  42. package/node_modules/inputmask/lib/environment.js +0 -9
  43. package/node_modules/inputmask/lib/escapeRegex.js +0 -4
  44. package/node_modules/inputmask/lib/eventhandlers.js +0 -513
  45. package/node_modules/inputmask/lib/eventruler.js +0 -124
  46. package/node_modules/inputmask/lib/extensions/inputmask.date.extensions.js +0 -588
  47. package/node_modules/inputmask/lib/extensions/inputmask.extensions.js +0 -133
  48. package/node_modules/inputmask/lib/extensions/inputmask.numeric.extensions.js +0 -631
  49. package/node_modules/inputmask/lib/global/window.js +0 -3
  50. package/node_modules/inputmask/lib/inputHandling.js +0 -252
  51. package/node_modules/inputmask/lib/inputmask.js +0 -355
  52. package/node_modules/inputmask/lib/inputmaskElement.js +0 -33
  53. package/node_modules/inputmask/lib/jquery.inputmask.js +0 -81
  54. package/node_modules/inputmask/lib/keycode.json +0 -25
  55. package/node_modules/inputmask/lib/mask-lexer.js +0 -467
  56. package/node_modules/inputmask/lib/mask.js +0 -244
  57. package/node_modules/inputmask/lib/masktoken.js +0 -13
  58. package/node_modules/inputmask/lib/polyfills/Array.includes.js +0 -48
  59. package/node_modules/inputmask/lib/polyfills/Object.getPrototypeOf.js +0 -7
  60. package/node_modules/inputmask/lib/positioning.js +0 -348
  61. package/node_modules/inputmask/lib/validation-tests.js +0 -597
  62. package/node_modules/inputmask/lib/validation.js +0 -664
  63. package/node_modules/inputmask/package.json +0 -60
  64. package/src/example/App.example.tsx +0 -68
  65. package/src/example/index.tsx +0 -5
package/dist/index.cjs ADDED
@@ -0,0 +1,178 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var Inputmask = require('inputmask');
7
+
8
+ const isServer = !(typeof window !== 'undefined' && window.document && window.document.createElement);
9
+ const compose = (fn1, ...fns)=>fns.reduce((prevFn, nextFn)=>(value)=>prevFn(nextFn(value)), fn1);
10
+ const sum = compose((x)=>x + 1, (x)=>x + 1);
11
+ console.log(sum(1));
12
+
13
+ function _define_property$2(obj, key, value) {
14
+ if (key in obj) {
15
+ Object.defineProperty(obj, key, {
16
+ value: value,
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true
20
+ });
21
+ } else {
22
+ obj[key] = value;
23
+ }
24
+ return obj;
25
+ }
26
+ function _object_spread$2(target) {
27
+ for(var i = 1; i < arguments.length; i++){
28
+ var source = arguments[i] != null ? arguments[i] : {};
29
+ var ownKeys = Object.keys(source);
30
+ if (typeof Object.getOwnPropertySymbols === "function") {
31
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
32
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
33
+ }));
34
+ }
35
+ ownKeys.forEach(function(key) {
36
+ _define_property$2(target, key, source[key]);
37
+ });
38
+ }
39
+ return target;
40
+ }
41
+ const useInputMask = (props)=>{
42
+ const { mask , register , options } = props;
43
+ const ref = react.useRef(null);
44
+ if (isServer) return ref;
45
+ react.useEffect(()=>{
46
+ if (!isServer) {
47
+ if (!ref.current) return;
48
+ const maskInput = Inputmask(_object_spread$2({
49
+ mask
50
+ }, options));
51
+ maskInput.mask(ref.current);
52
+ if (register && ref.current) {
53
+ register(ref.current);
54
+ }
55
+ }
56
+ }, [
57
+ mask,
58
+ register,
59
+ options
60
+ ]);
61
+ return ref;
62
+ };
63
+
64
+ function _define_property$1(obj, key, value) {
65
+ if (key in obj) {
66
+ Object.defineProperty(obj, key, {
67
+ value: value,
68
+ enumerable: true,
69
+ configurable: true,
70
+ writable: true
71
+ });
72
+ } else {
73
+ obj[key] = value;
74
+ }
75
+ return obj;
76
+ }
77
+ function _object_spread$1(target) {
78
+ for(var i = 1; i < arguments.length; i++){
79
+ var source = arguments[i] != null ? arguments[i] : {};
80
+ var ownKeys = Object.keys(source);
81
+ if (typeof Object.getOwnPropertySymbols === "function") {
82
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
83
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
84
+ }));
85
+ }
86
+ ownKeys.forEach(function(key) {
87
+ _define_property$1(target, key, source[key]);
88
+ });
89
+ }
90
+ return target;
91
+ }
92
+ function ownKeys(object, enumerableOnly) {
93
+ var keys = Object.keys(object);
94
+ if (Object.getOwnPropertySymbols) {
95
+ var symbols = Object.getOwnPropertySymbols(object);
96
+ if (enumerableOnly) {
97
+ symbols = symbols.filter(function(sym) {
98
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
99
+ });
100
+ }
101
+ keys.push.apply(keys, symbols);
102
+ }
103
+ return keys;
104
+ }
105
+ function _object_spread_props(target, source) {
106
+ source = source != null ? source : {};
107
+ if (Object.getOwnPropertyDescriptors) {
108
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
109
+ } else {
110
+ ownKeys(Object(source)).forEach(function(key) {
111
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
112
+ });
113
+ }
114
+ return target;
115
+ }
116
+ const withHookFormMask = (register, mask, options)=>{
117
+ //
118
+ let newRef;
119
+ if (register) {
120
+ const { ref } = register;
121
+ const maskInput = Inputmask(_object_spread$1({
122
+ mask,
123
+ jitMasking: true
124
+ }, options));
125
+ newRef = compose((_ref)=>{
126
+ if (_ref) maskInput.mask(_ref);
127
+ return _ref;
128
+ }, ref);
129
+ }
130
+ return _object_spread_props(_object_spread$1({}, register), {
131
+ ref: newRef
132
+ });
133
+ };
134
+
135
+ function _define_property(obj, key, value) {
136
+ if (key in obj) {
137
+ Object.defineProperty(obj, key, {
138
+ value: value,
139
+ enumerable: true,
140
+ configurable: true,
141
+ writable: true
142
+ });
143
+ } else {
144
+ obj[key] = value;
145
+ }
146
+ return obj;
147
+ }
148
+ function _object_spread(target) {
149
+ for(var i = 1; i < arguments.length; i++){
150
+ var source = arguments[i] != null ? arguments[i] : {};
151
+ var ownKeys = Object.keys(source);
152
+ if (typeof Object.getOwnPropertySymbols === "function") {
153
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
154
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
155
+ }));
156
+ }
157
+ ownKeys.forEach(function(key) {
158
+ _define_property(target, key, source[key]);
159
+ });
160
+ }
161
+ return target;
162
+ }
163
+ const withMask = (mask, options)=>(input)=>{
164
+ //
165
+ if (isServer) return input;
166
+ const maskInput = Inputmask(_object_spread({
167
+ mask
168
+ }, options));
169
+ if (input) {
170
+ maskInput.mask(input);
171
+ }
172
+ return input;
173
+ };
174
+
175
+ exports.default = useInputMask;
176
+ exports.withHookFormMask = withHookFormMask;
177
+ exports.withMask = withMask;
178
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/useMaskInput.ts","../src/withHookFormMask.ts","../src/withMask.ts"],"sourcesContent":["export const isServer = !(\n typeof window !== 'undefined'\n && window.document\n && window.document.createElement\n);\n\nexport const pipe = <T extends any[], R>(\n fn1: (...args: T) => R,\n ...fns: Array<(a: R) => R>\n) => {\n const piped = fns.reduce(\n (prevFn, nextFn) => (value: R) => nextFn(prevFn(value)),\n (value) => value,\n );\n return (...args: T) => piped(fn1(...args));\n};\n\nexport const compose = <R>(\n fn1: (a: R) => R, ...fns: Array<(a: R) => R>\n) => fns.reduce((prevFn, nextFn) => (value) => prevFn(nextFn(value)), fn1);\n\nconst sum = compose(\n (x: number) => x + 1,\n (x: number) => x + 1,\n);\n\nconsole.log(sum(1));\n","import { useEffect, useRef } from 'react';\nimport Inputmask from 'inputmask';\nimport { isServer } from './utils';\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 const ref = useRef<HTMLInputElement>(null);\n if (isServer) return ref;\n\n useEffect(() => {\n if (!isServer) {\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 }\n }, [mask, register, options]);\n\n return ref;\n};\n\nexport default useInputMask;\n","import Inputmask from 'inputmask';\n\nimport { compose } from './utils';\nimport { Mask, Options, Register } from './types';\n\nexport const withHookFormMask = (register: Register, mask: Mask, options?: Options) => {\n //\n let newRef;\n\n if (register) {\n const { ref } = register;\n\n const maskInput = Inputmask({\n mask,\n jitMasking: true,\n ...options,\n });\n\n newRef = compose((_ref: HTMLElement) => {\n if (_ref) maskInput.mask(_ref);\n return _ref;\n }, ref);\n }\n\n return {\n ...register,\n ref: newRef,\n };\n};\n","import Inputmask from 'inputmask';\nimport { isServer } from './utils';\nimport { Input, Mask, Options } from './types';\n\nexport const withMask = (mask: Mask, options?: Options) => (input: Input) => {\n //\n if (isServer) return input;\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"],"names":["isServer","window","document","createElement","compose","fn1","fns","reduce","prevFn","nextFn","value","sum","x","console","log","useInputMask","props","mask","register","options","ref","useRef","useEffect","current","maskInput","Inputmask","_object_spread","withHookFormMask","newRef","jitMasking","_ref","withMask","input"],"mappings":";;;;;;;AAAO,MAAMA,QAAAA,GAAW,EACtB,OAAOC,MAAW,KAAA,WAAA,IACfA,MAAOC,CAAAA,QAAQ,IACfD,MAAOC,CAAAA,QAAQ,CAACC,aAAa,CAChC,CAAA;AAaK,MAAMC,OAAU,GAAA,CACrBC,GAAkB,EAAA,GAAGC,MAClBA,GAAIC,CAAAA,MAAM,CAAC,CAACC,QAAQC,MAAW,GAAA,CAACC,QAAUF,MAAOC,CAAAA,MAAAA,CAAOC,SAASL,GAAK,CA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M,EAAEE,GAAG,GAAE,GAAGF,QAAAA,CAAAA;AAEhB,QAAA,MAAMM,YAAYC,SAAU,CAAAC,gBAAA,CAAA;AAC1BT,YAAAA,IAAAA;AACAY,YAAAA,UAAAA,EAAY,IAAI;AACbV,SAAAA,EAAAA,OAAAA,CAAAA,CAAAA,CAAAA;QAGLS,MAASxB,GAAAA,OAAAA,CAAQ,CAAC0B,IAAsB,GAAA;YACtC,IAAIA,IAAAA,EAAMN,SAAUP,CAAAA,IAAI,CAACa,IAAAA,CAAAA,CAAAA;YACzB,OAAOA,IAAAA,CAAAA;SACNV,EAAAA,GAAAA,CAAAA,CAAAA;KACJ;AAED,IAAA,OAAO,oBACFF,CAAAA,gBAAAA,CAAAA,EAAAA,EAAAA,QAAAA,CAAAA,EAAAA;QACHE,GAAKQ,EAAAA,MAAAA;;AAET;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MCxBaG,QAAW,GAAA,CAACd,IAAYE,EAAAA,OAAAA,GAAsB,CAACa,KAAiB,GAAA;;AAE3E,QAAA,IAAIhC,UAAU,OAAOgC,KAAAA,CAAAA;AAErB,QAAA,MAAMR,YAAYC,SAAU,CAAA,cAAA,CAAA;AAC1BR,YAAAA,IAAAA;AACGE,SAAAA,EAAAA,OAAAA,CAAAA,CAAAA,CAAAA;AAGL,QAAA,IAAIa,KAAO,EAAA;AACTR,YAAAA,SAAAA,CAAUP,IAAI,CAACe,KAAAA,CAAAA,CAAAA;SAChB;QAED,OAAOA,KAAAA,CAAAA;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,34 @@
1
- export { default } from './useMaskInput';
2
- export { default as withHookFormMask } from './withHookFormMask';
3
- export { default as withMask } from './withMask';
1
+ import * as react from 'react';
2
+ import Inputmask$1 from 'inputmask';
3
+ import * as react_hook_form from 'react-hook-form';
4
+ import { UseFormRegisterReturn } from 'react-hook-form';
5
+
6
+ interface UseInputMaskOptions {
7
+ mask: Inputmask$1.Options['mask'];
8
+ register?(element: HTMLElement): void;
9
+ options?: Inputmask$1.Options;
10
+ }
11
+ declare const useInputMask: (props: UseInputMaskOptions) => react.RefObject<HTMLInputElement>;
12
+
13
+ type Register = UseFormRegisterReturn;
14
+ type Mask = Inputmask.Options['mask'];
15
+ type Options = Inputmask.Options;
16
+ type Input = HTMLInputElement | HTMLTextAreaElement | HTMLElement | HTMLInputElement | null;
17
+
18
+ declare const withHookFormMask: (register: Register, mask: Mask, options?: Options) => {
19
+ ref: ((a: any) => any) | undefined;
20
+ onChange: react_hook_form.ChangeHandler;
21
+ onBlur: react_hook_form.ChangeHandler;
22
+ name: string;
23
+ min?: string | number | undefined;
24
+ max?: string | number | undefined;
25
+ maxLength?: number | undefined;
26
+ minLength?: number | undefined;
27
+ pattern?: string | undefined;
28
+ required?: boolean | undefined;
29
+ disabled?: boolean | undefined;
30
+ };
31
+
32
+ declare const withMask: (mask: Mask, options?: Options) => (input: Input) => Input;
33
+
34
+ export { useInputMask as default, withHookFormMask, withMask };
package/dist/index.js CHANGED
@@ -1,2 +1,172 @@
1
- function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}var t=require("react"),e=r(require("inputmask")),n=r(require("lodash.flowright"));function u(){return(u=Object.assign?Object.assign.bind():function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}exports.default=function(r){var n=r.mask,a=r.register,i=r.options,o=t.useRef(null);return t.useEffect(function(){o.current&&(e(u({mask:n},i)).mask(o.current),a&&o.current&&a(o.current))},[n,a,i]),o},exports.withHookFormMask=function(r,t,a){var i;if(r){var o=r.ref,s=e(u({mask:t,jitMasking:!0},a));i=n(o,function(r){return r&&s.mask(r),r})}return u({},r,{ref:i})},exports.withMask=function(r,t){return function(n){var a=e(u({mask:r},t));return n&&a.mask(n),n}};
1
+ import { useRef, useEffect } from 'react';
2
+ import Inputmask from 'inputmask';
3
+
4
+ const isServer = !(typeof window !== 'undefined' && window.document && window.document.createElement);
5
+ const compose = (fn1, ...fns)=>fns.reduce((prevFn, nextFn)=>(value)=>prevFn(nextFn(value)), fn1);
6
+ const sum = compose((x)=>x + 1, (x)=>x + 1);
7
+ console.log(sum(1));
8
+
9
+ function _define_property$2(obj, key, value) {
10
+ if (key in obj) {
11
+ Object.defineProperty(obj, key, {
12
+ value: value,
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true
16
+ });
17
+ } else {
18
+ obj[key] = value;
19
+ }
20
+ return obj;
21
+ }
22
+ function _object_spread$2(target) {
23
+ for(var i = 1; i < arguments.length; i++){
24
+ var source = arguments[i] != null ? arguments[i] : {};
25
+ var ownKeys = Object.keys(source);
26
+ if (typeof Object.getOwnPropertySymbols === "function") {
27
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
28
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
29
+ }));
30
+ }
31
+ ownKeys.forEach(function(key) {
32
+ _define_property$2(target, key, source[key]);
33
+ });
34
+ }
35
+ return target;
36
+ }
37
+ const useInputMask = (props)=>{
38
+ const { mask , register , options } = props;
39
+ const ref = useRef(null);
40
+ if (isServer) return ref;
41
+ useEffect(()=>{
42
+ if (!isServer) {
43
+ if (!ref.current) return;
44
+ const maskInput = Inputmask(_object_spread$2({
45
+ mask
46
+ }, options));
47
+ maskInput.mask(ref.current);
48
+ if (register && ref.current) {
49
+ register(ref.current);
50
+ }
51
+ }
52
+ }, [
53
+ mask,
54
+ register,
55
+ options
56
+ ]);
57
+ return ref;
58
+ };
59
+
60
+ function _define_property$1(obj, key, value) {
61
+ if (key in obj) {
62
+ Object.defineProperty(obj, key, {
63
+ value: value,
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true
67
+ });
68
+ } else {
69
+ obj[key] = value;
70
+ }
71
+ return obj;
72
+ }
73
+ function _object_spread$1(target) {
74
+ for(var i = 1; i < arguments.length; i++){
75
+ var source = arguments[i] != null ? arguments[i] : {};
76
+ var ownKeys = Object.keys(source);
77
+ if (typeof Object.getOwnPropertySymbols === "function") {
78
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
79
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
80
+ }));
81
+ }
82
+ ownKeys.forEach(function(key) {
83
+ _define_property$1(target, key, source[key]);
84
+ });
85
+ }
86
+ return target;
87
+ }
88
+ function ownKeys(object, enumerableOnly) {
89
+ var keys = Object.keys(object);
90
+ if (Object.getOwnPropertySymbols) {
91
+ var symbols = Object.getOwnPropertySymbols(object);
92
+ if (enumerableOnly) {
93
+ symbols = symbols.filter(function(sym) {
94
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
95
+ });
96
+ }
97
+ keys.push.apply(keys, symbols);
98
+ }
99
+ return keys;
100
+ }
101
+ function _object_spread_props(target, source) {
102
+ source = source != null ? source : {};
103
+ if (Object.getOwnPropertyDescriptors) {
104
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
105
+ } else {
106
+ ownKeys(Object(source)).forEach(function(key) {
107
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
108
+ });
109
+ }
110
+ return target;
111
+ }
112
+ const withHookFormMask = (register, mask, options)=>{
113
+ //
114
+ let newRef;
115
+ if (register) {
116
+ const { ref } = register;
117
+ const maskInput = Inputmask(_object_spread$1({
118
+ mask,
119
+ jitMasking: true
120
+ }, options));
121
+ newRef = compose((_ref)=>{
122
+ if (_ref) maskInput.mask(_ref);
123
+ return _ref;
124
+ }, ref);
125
+ }
126
+ return _object_spread_props(_object_spread$1({}, register), {
127
+ ref: newRef
128
+ });
129
+ };
130
+
131
+ function _define_property(obj, key, value) {
132
+ if (key in obj) {
133
+ Object.defineProperty(obj, key, {
134
+ value: value,
135
+ enumerable: true,
136
+ configurable: true,
137
+ writable: true
138
+ });
139
+ } else {
140
+ obj[key] = value;
141
+ }
142
+ return obj;
143
+ }
144
+ function _object_spread(target) {
145
+ for(var i = 1; i < arguments.length; i++){
146
+ var source = arguments[i] != null ? arguments[i] : {};
147
+ var ownKeys = Object.keys(source);
148
+ if (typeof Object.getOwnPropertySymbols === "function") {
149
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
150
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
151
+ }));
152
+ }
153
+ ownKeys.forEach(function(key) {
154
+ _define_property(target, key, source[key]);
155
+ });
156
+ }
157
+ return target;
158
+ }
159
+ const withMask = (mask, options)=>(input)=>{
160
+ //
161
+ if (isServer) return input;
162
+ const maskInput = Inputmask(_object_spread({
163
+ mask
164
+ }, options));
165
+ if (input) {
166
+ maskInput.mask(input);
167
+ }
168
+ return input;
169
+ };
170
+
171
+ export { useInputMask as default, withHookFormMask, withMask };
2
172
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.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":"2YASqB,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,gCCrBG,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,sBC7BiB,SACxBV,EACAE,mBACIY,GAEJ,MAAkBP,KAChBP,KAAAA,GACGE,IAOL,OAJIY,GACFD,EAAUb,KAAKc"}
1
+ {"version":3,"file":"index.js","sources":["../src/utils.ts","../src/useMaskInput.ts","../src/withHookFormMask.ts","../src/withMask.ts"],"sourcesContent":["export const isServer = !(\n typeof window !== 'undefined'\n && window.document\n && window.document.createElement\n);\n\nexport const pipe = <T extends any[], R>(\n fn1: (...args: T) => R,\n ...fns: Array<(a: R) => R>\n) => {\n const piped = fns.reduce(\n (prevFn, nextFn) => (value: R) => nextFn(prevFn(value)),\n (value) => value,\n );\n return (...args: T) => piped(fn1(...args));\n};\n\nexport const compose = <R>(\n fn1: (a: R) => R, ...fns: Array<(a: R) => R>\n) => fns.reduce((prevFn, nextFn) => (value) => prevFn(nextFn(value)), fn1);\n\nconst sum = compose(\n (x: number) => x + 1,\n (x: number) => x + 1,\n);\n\nconsole.log(sum(1));\n","import { useEffect, useRef } from 'react';\nimport Inputmask from 'inputmask';\nimport { isServer } from './utils';\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 const ref = useRef<HTMLInputElement>(null);\n if (isServer) return ref;\n\n useEffect(() => {\n if (!isServer) {\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 }\n }, [mask, register, options]);\n\n return ref;\n};\n\nexport default useInputMask;\n","import Inputmask from 'inputmask';\n\nimport { compose } from './utils';\nimport { Mask, Options, Register } from './types';\n\nexport const withHookFormMask = (register: Register, mask: Mask, options?: Options) => {\n //\n let newRef;\n\n if (register) {\n const { ref } = register;\n\n const maskInput = Inputmask({\n mask,\n jitMasking: true,\n ...options,\n });\n\n newRef = compose((_ref: HTMLElement) => {\n if (_ref) maskInput.mask(_ref);\n return _ref;\n }, ref);\n }\n\n return {\n ...register,\n ref: newRef,\n };\n};\n","import Inputmask from 'inputmask';\nimport { isServer } from './utils';\nimport { Input, Mask, Options } from './types';\n\nexport const withMask = (mask: Mask, options?: Options) => (input: Input) => {\n //\n if (isServer) return input;\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"],"names":["isServer","window","document","createElement","compose","fn1","fns","reduce","prevFn","nextFn","value","sum","x","console","log","useInputMask","props","mask","register","options","ref","useRef","useEffect","current","maskInput","Inputmask","_object_spread","withHookFormMask","newRef","jitMasking","_ref","withMask","input"],"mappings":";;;AAAO,MAAMA,QAAAA,GAAW,EACtB,OAAOC,MAAW,KAAA,WAAA,IACfA,MAAOC,CAAAA,QAAQ,IACfD,MAAOC,CAAAA,QAAQ,CAACC,aAAa,CAChC,CAAA;AAaK,MAAMC,OAAU,GAAA,CACrBC,GAAkB,EAAA,GAAGC,MAClBA,GAAIC,CAAAA,MAAM,CAAC,CAACC,QAAQC,MAAW,GAAA,CAACC,QAAUF,MAAOC,CAAAA,MAAAA,CAAOC,SAASL,GAAK,CAAA,CAAA;AAE3E,MAAMM,GAAAA,GAAMP,QACV,CAACQ,CAAAA,GAAcA,IAAI,CACnB,EAAA,CAACA,IAAcA,CAAI,GAAA,CAAA,CAAA,CAAA;AAGrBC,OAAQC,CAAAA,GAAG,CAACH,GAAI,CAAA,CAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AChBVI,MAAAA,YAAAA,GAAe,CAACC,KAA+B,GAAA;AACnD,IAAA,MAAM,EAAEC,IAAI,GAAEC,WAAUC,OAAAA,GAAS,GAAGH,KAAAA,CAAAA;IACpC,MAAMI,GAAAA,GAAMC,OAAyB,IAAI,CAAA,CAAA;AACzC,IAAA,IAAIrB,UAAU,OAAOoB,GAAAA,CAAAA;AAErBE,IAAAA,SAAAA,CAAU,IAAM;AACd,QAAA,IAAI,CAACtB,QAAU,EAAA;YACb,IAAI,CAACoB,GAAIG,CAAAA,OAAO,EAAE,OAAA;AAElB,YAAA,MAAMC,YAAYC,SAAU,CAAAC,gBAAA,CAAA;AAC1BT,gBAAAA,IAAAA;AACGE,aAAAA,EAAAA,OAAAA,CAAAA,CAAAA,CAAAA;YAGLK,SAAUP,CAAAA,IAAI,CAACG,GAAAA,CAAIG,OAAO,CAAA,CAAA;YAE1B,IAAIL,QAAAA,IAAYE,GAAIG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A;AAGL,QAAA,IAAIa,KAAO,EAAA;AACTR,YAAAA,SAAAA,CAAUP,IAAI,CAACe,KAAAA,CAAAA,CAAAA;SAChB;QAED,OAAOA,KAAAA,CAAAA;;;;;"}
package/package.json CHANGED
@@ -1,71 +1,71 @@
1
1
  {
2
2
  "name": "use-mask-input",
3
- "version": "3.0.6",
3
+ "version": "3.1.0",
4
4
  "description": "A react Hook for build elegant input masks. Compatible with React Hook Form",
5
5
  "author": "eduardoborges",
6
6
  "license": "MIT",
7
7
  "repository": "https://github.com/eduardoborges/use-mask-input",
8
8
  "source": "src/index.tsx",
9
9
  "main": "dist/index.js",
10
- "module": "dist/index.modern.js",
11
- "unpkg": "dist/index.umd.js",
10
+ "module": "dist/index.js",
12
11
  "types": "dist/index.d.ts",
12
+ "exports": {
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs",
15
+ "types": "./dist/index.d.ts"
16
+ },
13
17
  "engines": {
14
- "node": ">=16"
18
+ "node": ">=18",
19
+ "npm": ">=7"
15
20
  },
16
21
  "scripts": {
17
- "build": "microbundle-crl --format modern,cjs,umd",
18
- "start": "vite",
19
- "prepare": "npm run build",
20
- "lint": "eslint src"
22
+ "build": "./scripts.sh build",
23
+ "lint": "./scripts.sh lint",
24
+ "test": "./scripts.sh test",
25
+ "prepare": "./scripts.sh prepare"
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "src"
30
+ ],
31
+ "dependencies": {
32
+ "inputmask": "5.0.8",
33
+ "react-hook-form": "^7"
21
34
  },
22
35
  "peerDependencies": {
23
- "react": ">=17",
24
- "react-dom": ">=17"
36
+ "react": ">=16.4 || ^17.0.0 || ^18.0.0",
37
+ "react-dom": ">=16.4 || ^17.0.0 || ^18.0.0"
25
38
  },
26
39
  "devDependencies": {
27
- "@semantic-release/changelog": "6.0.2",
40
+ "@semantic-release/changelog": "6.0.3",
28
41
  "@semantic-release/commit-analyzer": "9.0.2",
29
42
  "@semantic-release/git": "10.0.1",
30
43
  "@semantic-release/github": "8.0.7",
31
- "@semantic-release/npm": "9.0.2",
32
- "@semantic-release/release-notes-generator": "10.0.3",
44
+ "@semantic-release/npm": "10.0.3",
45
+ "@semantic-release/release-notes-generator": "11.0.1",
33
46
  "@types/inputmask": "^5.0.3",
34
- "@types/jest": "29.4.0",
35
- "@types/lodash.flowright": "^3.5.7",
36
47
  "@types/node": "18",
37
- "@types/react": ">=17",
38
- "@types/react-dom": ">=17",
39
- "@typescript-eslint/eslint-plugin": "5.50.0",
40
- "@typescript-eslint/parser": "5.50.0",
41
- "@vitejs/plugin-react": "3.0.1",
42
- "concurrently": "7.6.0",
43
- "cross-env": "7.0.3",
44
- "eslint": "8.33.0",
48
+ "@types/react": ">=16.4 || ^17.0.0 || ^18.0.0",
49
+ "@types/react-dom": ">=16.4 || ^17.0.0 || ^18.0.0",
50
+ "@typescript-eslint/eslint-plugin": "5.59.2",
51
+ "@typescript-eslint/parser": "5.59.2",
52
+ "eslint": "8.39.0",
45
53
  "eslint-config-airbnb": "19.0.4",
46
54
  "eslint-config-airbnb-typescript": "^17.0.0",
47
55
  "eslint-plugin-import": "2.27.5",
48
56
  "eslint-plugin-jsx-a11y": "6.7.1",
49
- "eslint-plugin-react": "7.32.1",
57
+ "eslint-plugin-react": "7.32.2",
50
58
  "eslint-plugin-react-hooks": "^4.6.0",
51
- "final-form": "4.20.9",
52
- "microbundle": "0.15.1",
53
- "microbundle-crl": "^0.13.11",
54
- "react-final-form": "6.5.9",
55
- "react-hook-form": "^7.42.1",
56
- "semantic-release": "20.1.0",
57
- "typescript": "4.9.5",
58
- "vite": "4.1.1"
59
- },
60
- "files": [
61
- "dist",
62
- "src"
63
- ],
64
- "dependencies": {
65
- "inputmask": "5.0.7",
66
- "lodash.flowright": "3.5.0"
59
+ "read-pkg": "^8.0.0",
60
+ "rollup": "^3.21.4",
61
+ "rollup-plugin-dts": "^5.3.0",
62
+ "rollup-plugin-swc3": "^0.8.1",
63
+ "semantic-release": "21.0.2",
64
+ "simple-git-hooks": "^2.8.1",
65
+ "typescript": "4.9",
66
+ "vitest": "^0.31.0"
67
67
  },
68
- "bundleDependencies": [
69
- "inputmask"
70
- ]
68
+ "simple-git-hooks": {
69
+ "pre-commit": "npm run lint && npm run test && npm run build"
70
+ }
71
71
  }
package/src/index.tsx CHANGED
@@ -1,3 +1,4 @@
1
1
  export { default } from './useMaskInput';
2
- export { default as withHookFormMask } from './withHookFormMask';
3
- export { default as withMask } from './withMask';
2
+
3
+ export * from './withHookFormMask';
4
+ export * from './withMask';
package/src/types.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { UseFormRegisterReturn } from 'react-hook-form';
2
+
3
+ export type Register = UseFormRegisterReturn;
4
+ export type Mask = Inputmask.Options['mask'];
5
+ export type Options = Inputmask.Options;
6
+ export type Input = HTMLInputElement | HTMLTextAreaElement | HTMLElement | HTMLInputElement | null;
@@ -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,13 @@
1
+ /* eslint-disable import/no-extraneous-dependencies */
2
+ import { describe } from 'vitest';
3
+ import { compose } from './utils';
4
+
5
+ describe('test use_mask_input', (test) => {
6
+ test('test use-mask-input.flow', ({ expect }) => {
7
+ const sum = compose(
8
+ (x: number) => x + 1,
9
+ (x: number) => x + 1,
10
+ );
11
+ expect(sum(1)).toBe(3);
12
+ });
13
+ });
package/src/utils.ts ADDED
@@ -0,0 +1,27 @@
1
+ export const isServer = !(
2
+ typeof window !== 'undefined'
3
+ && window.document
4
+ && window.document.createElement
5
+ );
6
+
7
+ export const pipe = <T extends any[], R>(
8
+ fn1: (...args: T) => R,
9
+ ...fns: Array<(a: R) => R>
10
+ ) => {
11
+ const piped = fns.reduce(
12
+ (prevFn, nextFn) => (value: R) => nextFn(prevFn(value)),
13
+ (value) => value,
14
+ );
15
+ return (...args: T) => piped(fn1(...args));
16
+ };
17
+
18
+ export const compose = <R>(
19
+ fn1: (a: R) => R, ...fns: Array<(a: R) => R>
20
+ ) => fns.reduce((prevFn, nextFn) => (value) => prevFn(nextFn(value)), fn1);
21
+
22
+ const sum = compose(
23
+ (x: number) => x + 1,
24
+ (x: number) => x + 1,
25
+ );
26
+
27
+ console.log(sum(1));