use-mask-input 3.1.2 → 3.3.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,130 @@
1
+ # [3.3.0](https://github.com/eduardoborges/use-mask-input/compare/3.2.0...3.3.0) (2023-06-30)
2
+
3
+
4
+ ### Features
5
+
6
+ * new useHookFormMask API ([#35](https://github.com/eduardoborges/use-mask-input/issues/35)) ([52609eb](https://github.com/eduardoborges/use-mask-input/commit/52609eb57d77f4cd95a8ccbe868f9e4cbcdc2e47))
7
+
8
+ # [3.2.0](https://github.com/eduardoborges/use-mask-input/compare/3.1.2...3.2.0) (2023-06-14)
9
+
10
+
11
+ ### Features
12
+
13
+ * now works with Next! ([7730de2](https://github.com/eduardoborges/use-mask-input/commit/7730de24237f8df0eede8cf464620b6d1c87c558))
14
+
15
+ ## [3.1.2](https://github.com/eduardoborges/use-mask-input/compare/3.1.1...3.1.2) (2023-05-10)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * add inputmask extension support ([eecc00a](https://github.com/eduardoborges/use-mask-input/commit/eecc00a0601ff5bc340c50886a6ab35174006096))
21
+
22
+ ## [3.1.1](https://github.com/eduardoborges/use-mask-input/compare/3.1.0...3.1.1) (2023-05-10)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * change dependency type ([#13](https://github.com/eduardoborges/use-mask-input/issues/13)) ([1c87dc7](https://github.com/eduardoborges/use-mask-input/commit/1c87dc723540cd51e1dc40f1a162611aa53e9c11))
28
+ * downgrade required node to 16 ([#11](https://github.com/eduardoborges/use-mask-input/issues/11)) ([d829d2f](https://github.com/eduardoborges/use-mask-input/commit/d829d2f5c34aa0b30ab6f68d42fbc5a068b53b70))
29
+ * regression issue with react hook form and ci ([#31](https://github.com/eduardoborges/use-mask-input/issues/31)) ([bf104b2](https://github.com/eduardoborges/use-mask-input/commit/bf104b2a1ca7ccb0b7a1d573ba07bdfe95dd8949)), closes [#11](https://github.com/eduardoborges/use-mask-input/issues/11) [#13](https://github.com/eduardoborges/use-mask-input/issues/13)
30
+
31
+ # [3.1.0](https://github.com/eduardoborges/use-mask-input/compare/3.0.6...3.1.0) (2023-05-04)
32
+
33
+
34
+ ### Bug Fixes
35
+
36
+ * refactor code and add compose function to `utils.ts` ([49a7459](https://github.com/eduardoborges/use-mask-input/commit/49a7459c0976443f04426c2cc14d29172fe413ad))
37
+ * refactor withHookFormMask to use compose instead of flow. ([85b8bc5](https://github.com/eduardoborges/use-mask-input/commit/85b8bc59b112341ad76b09d7acc167c98d8bd352))
38
+ * small refactors, remove lodash dep and add exports suggar ([95286a8](https://github.com/eduardoborges/use-mask-input/commit/95286a87c4ea3c2bf0f25a418413078da9d17c7b))
39
+
40
+
41
+ ### Features
42
+
43
+ * Add React Hook Form to dependencies and install git hooks ([f7496c2](https://github.com/eduardoborges/use-mask-input/commit/f7496c23a429363bc47e03f18c9ce8eb3be41ab0))
44
+
45
+ ## [3.0.6](https://github.com/eduardoborges/use-mask-input/compare/3.0.5...3.0.6) (2023-02-10)
46
+
47
+
48
+ ### Bug Fixes
49
+
50
+ * fix regression for cra exports ([b149d78](https://github.com/eduardoborges/use-mask-input/commit/b149d7822dac99db3f308671a13b8fbbe148010c))
51
+
52
+ ## [3.0.5](https://github.com/eduardoborges/use-mask-input/compare/3.0.4...3.0.5) (2023-02-09)
53
+
54
+
55
+ ### Bug Fixes
56
+
57
+ * fix module resolution ([ab8a464](https://github.com/eduardoborges/use-mask-input/commit/ab8a464a4cb6fe529d1ff3decc56de925efa68fc))
58
+
59
+ ## [3.0.4](https://github.com/eduardoborges/use-mask-input/compare/3.0.3...3.0.4) (2023-02-09)
60
+
61
+
62
+ ### Bug Fixes
63
+
64
+ * fix invalid resolve entry for package fix [#8](https://github.com/eduardoborges/use-mask-input/issues/8) ([91e3fc2](https://github.com/eduardoborges/use-mask-input/commit/91e3fc28b7180bbc6c608dd33eefd92d1c21da78))
65
+
66
+ ## [3.0.3](https://github.com/eduardoborges/use-mask-input/compare/3.0.2...3.0.3) (2023-02-09)
67
+
68
+
69
+ ### Bug Fixes
70
+
71
+ * can access nodeName on component unmount fix [#7](https://github.com/eduardoborges/use-mask-input/issues/7) ([a881272](https://github.com/eduardoborges/use-mask-input/commit/a881272be60b77287d68208472280c52331d82e7))
72
+
73
+ ## [3.0.2](https://github.com/eduardoborges/use-mask-input/compare/3.0.1...3.0.2) (2023-02-06)
74
+
75
+
76
+ ### Bug Fixes
77
+
78
+ * remove unused deps and fix vulnerabilities ([a49c5d5](https://github.com/eduardoborges/use-mask-input/commit/a49c5d55b485553fe9a79c38af900fc4def24774))
79
+
80
+ ## [3.0.1](https://github.com/eduardoborges/use-mask-input/compare/3.0.0...3.0.1) (2023-01-23)
81
+
82
+
83
+ ### Bug Fixes
84
+
85
+ * security fixes ([aad0816](https://github.com/eduardoborges/use-mask-input/commit/aad08168b9349a6199a3bfa0d1340a5f20cae732))
86
+
87
+ # [3.0.0](https://github.com/eduardoborges/use-mask-input/compare/2.1.0...3.0.0) (2022-10-11)
88
+
89
+
90
+ ### Features
91
+
92
+ * simplify API & add react-final-form support. ([981588d](https://github.com/eduardoborges/use-mask-input/commit/981588d54121e66d550eb5df9fe64b5de01d70c6))
93
+
94
+
95
+ ### BREAKING CHANGES
96
+
97
+ * update api
98
+
99
+ # [2.1.0](https://github.com/eduardoborges/use-mask-input/compare/2.0.1...2.1.0) (2022-09-27)
100
+
101
+
102
+ ### Features
103
+
104
+ * add react-hook-form 7 integration ([0fd5bfc](https://github.com/eduardoborges/use-mask-input/commit/0fd5bfca4f8a686b9d89eba1f319c055073f51ed))
105
+
106
+ ## [2.0.1](https://github.com/eduardoborges/use-mask-input/compare/2.0.0...2.0.1) (2022-09-27)
107
+
108
+
109
+ ### Bug Fixes
110
+
111
+ * enhance actions time ([6ea226c](https://github.com/eduardoborges/use-mask-input/commit/6ea226cf1e49f46ff476ad7c1619c136a54a1954))
112
+
113
+ # [2.0.0](https://github.com/eduardoborges/use-mask-input/compare/1.1.0...2.0.0) (2022-09-27)
114
+
115
+
116
+ ### Bug Fixes
117
+
118
+ * Bump version ([4485125](https://github.com/eduardoborges/use-mask-input/commit/44851258e0b9f767be53d77e279b3604578b8aaa))
119
+
120
+
121
+ ### BREAKING CHANGES
122
+
123
+ * update libs to suport new react-hook-form
124
+
125
+ # [1.1.0](https://github.com/eduardoborges/use-mask-input/compare/1.0.2...1.1.0) (2022-09-27)
126
+
127
+
128
+ ### Features
129
+
130
+ * force release ([61d23d3](https://github.com/eduardoborges/use-mask-input/commit/61d23d3f588abe095ec0a81de8249801c39a31bd))
package/README.md CHANGED
@@ -6,15 +6,23 @@ A React Hook for build elegant and simple input masks.
6
6
 
7
7
  ---
8
8
 
9
+ ## Table of Contents
10
+
11
+ - [Installation](#install)
12
+ - [Usage](#quickstart)
13
+ - [Masking Types](#masking-types)
14
+ - [Static Masking Type](#static-masking-type)
15
+ - [Optional Masking Type](#optional-masking-type)
16
+ - [Dynamic Masking Type](#dynamic-masking-type)
17
+ - [Alias Masking Type](#alias-masking-type)
18
+ - [Alternator Masking Type](#alias-masking-type)
19
+ - [Preprocessing Masking Type](#preprocessing-masking-type)
20
+
9
21
  ## Features
10
22
  - 🎯 Simple API
23
+ - 💎 Works like a charm with *Next.js*
11
24
  - ✨ Compatible with [React Hook Form](https://github.com/react-hook-form/react-hook-form)
12
25
  - 🏁 Compatible with [React Final Form](https://github.com/final-form/react-final-form)
13
-
14
- ## Know Issues
15
-
16
- - Not compatible with Next.js, but we are working on it
17
-
18
26
  ## Install
19
27
 
20
28
  ```sh
@@ -34,7 +42,7 @@ const App = () => {
34
42
  }
35
43
  ```
36
44
 
37
- ## Usage with React Hook Forms
45
+ ### Usage with React Hook Forms
38
46
 
39
47
  ```jsx
40
48
  import React from 'react';
@@ -43,14 +51,17 @@ import { withHookFormMask } from 'use-mask-input';
43
51
 
44
52
  function App() {
45
53
  const { register, handleSubmit } = useForm();
54
+ const registerWithMask = useHookFormMask(register);
46
55
 
47
56
  ...
48
57
 
49
58
  return (
50
59
  <form onSubmit={onSubmit}>
51
60
  <input
61
+ {...registerWithMask("phone", ['99 9999-9999', '99999-9999'], {
62
+ required: true
63
+ })}
52
64
  type="text"
53
- {...withHookFormMask(register('phone'), ['(99) 9999 9999', '(99) 9 9999 9999'])}
54
65
  />
55
66
  <button type="submit">Submit</button>
56
67
  </form>
@@ -58,7 +69,7 @@ function App() {
58
69
  }
59
70
  ```
60
71
 
61
- ## Usage with React Final Form
72
+ ### Usage with React Final Form
62
73
 
63
74
  Just use `withMask` normaly.
64
75
 
@@ -87,3 +98,133 @@ function App() {
87
98
  );
88
99
  }
89
100
  ```
101
+
102
+ ## Masking types
103
+
104
+ The `mask` params cabe be
105
+
106
+ ### Static Masking Type
107
+
108
+ These are the very basics of masking. The mask is defined and will not change during the input.
109
+
110
+ ```tsx
111
+ <input
112
+ {...registerWithMask("phone", '99 9999-9999')}
113
+ type="text"
114
+ />
115
+ ```
116
+
117
+ ### Optional Masking Type
118
+
119
+ It is possible to define some parts in the mask as optional. This is done by using `[ ]`. By example:
120
+
121
+ ```tsx
122
+ <input
123
+ {...registerWithMask("phone", '99 [9]9999-9999')}
124
+ type="text"
125
+ />
126
+ ```
127
+ This mask will allow input like (99) 99999-9999 or (99) 9999-9999.
128
+
129
+ ### Dynamic Masking Type
130
+
131
+ Dynamic masks can change during input. To define a dynamic part use { }.
132
+
133
+ {n} => n repeats {n|j} => n repeats, with j jitmasking {n,m} => from n to m repeats {n,m|j} => from n to m repeats, with j jitmasking
134
+
135
+ Also {+} and {} is allowed. + start from 1 and start from 0.
136
+
137
+ By example:
138
+
139
+ ```tsx
140
+ //static mask with dynamic syntax
141
+ <input
142
+ {...registerWithMask("phone", "aa-9{4}")}
143
+ type="text"
144
+ />
145
+
146
+ // dynamic mask ~ the 9 def can be occur 1 to 4 times
147
+ <input
148
+ {...registerWithMask("phone", "aa-9{4}")}
149
+ type="text"
150
+ />
151
+
152
+ // dynamic mask ~ email
153
+ <input
154
+ {...registerWithMask("phone", "*{1,20}[.*{1,20}][.*{1,20}][.*{1,20}]@*{1,20}[.*{2,6}][.*{1,2}]")}
155
+ type="text"
156
+ />
157
+
158
+ ```
159
+ ### Alias Masking Type
160
+
161
+ A Lot of common default "alises" presets, you can use like that:
162
+ ```tsx
163
+ <input // the alias
164
+ {...registerWithMask("date", "datetime", {
165
+ inputFormat: "yyyy-mm-dd",
166
+ })}
167
+ type="text"
168
+ />
169
+ ```
170
+
171
+ You can use together with options like `inputFormat`, `prefix`, `sufix`, etc. Checkout [API docs](#api)
172
+
173
+ The avaliable ones is:
174
+
175
+ - `datetime`
176
+ - `email`
177
+ - `ip`
178
+ - `datetime`
179
+ - `cpf`
180
+ - `email`
181
+ - `numeric`
182
+ - `currency`
183
+ - `decimal`
184
+ - `integer`
185
+ - `percentage`
186
+ - `url`
187
+ - `ip`
188
+ - `mac`
189
+ - `ssn`
190
+
191
+ ### Alternator Masking Type
192
+
193
+ The alternator syntax is like an OR statement. The mask can be one of the 3 choices specified in the alternator.
194
+
195
+ To define an alternator use the |. ex: "a|9" => a or 9 "(aaa)|(999)" => aaa or 999 "(aaa|999|9AA)" => aaa or 999 or 9AA
196
+ "aaaa|9999" => aaa a or 9 999
197
+
198
+ ```tsx
199
+ <input
200
+ {...registerWithMask("phone", "9999-9999|99999-9999")}
201
+ type="text"
202
+ />
203
+
204
+ // or just passing an array
205
+ <input
206
+ {...registerWithMask("phone", ["9999-9999", "99999-9999"])}
207
+ type="text"
208
+ />
209
+
210
+ ```
211
+
212
+
213
+ ### Preprocessing Masking Type
214
+
215
+ You can define the mask as a function that can allow you to preprocess the resulting mask. Example sorting for multiple masks or retrieving mask definitions dynamically through ajax. The preprocessing fn should return a valid mask definition.
216
+
217
+ ```tsx
218
+ <input
219
+ {...registerWithMask("phone", function () {
220
+ /* do stuff */ return ["[1-]AAA-999", "[1-]999-AAA"];
221
+ })}
222
+ type="text"
223
+ />
224
+
225
+ ```
226
+
227
+
228
+ ## API
229
+
230
+ (TODO)
package/dist/index.cjs CHANGED
@@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var react = require('react');
6
6
  var Inputmask = require('inputmask');
7
7
 
8
- const isServer = !(typeof window !== 'undefined' && window.document && window.document.createElement);
9
8
  function flow(...funcs) {
10
9
  const { length } = funcs;
11
10
  let index = length;
@@ -24,6 +23,8 @@ function flow(...funcs) {
24
23
  };
25
24
  }
26
25
 
26
+ const isServer = !(typeof window !== 'undefined' && window.document && window.document.createElement);
27
+
27
28
  function _define_property$2(obj, key, value) {
28
29
  if (key in obj) {
29
30
  Object.defineProperty(obj, key, {
@@ -52,6 +53,99 @@ function _object_spread$2(target) {
52
53
  }
53
54
  return target;
54
55
  }
56
+ function ownKeys$2(object, enumerableOnly) {
57
+ var keys = Object.keys(object);
58
+ if (Object.getOwnPropertySymbols) {
59
+ var symbols = Object.getOwnPropertySymbols(object);
60
+ if (enumerableOnly) {
61
+ symbols = symbols.filter(function(sym) {
62
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
63
+ });
64
+ }
65
+ keys.push.apply(keys, symbols);
66
+ }
67
+ return keys;
68
+ }
69
+ function _object_spread_props$2(target, source) {
70
+ source = source != null ? source : {};
71
+ if (Object.getOwnPropertyDescriptors) {
72
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
73
+ } else {
74
+ ownKeys$2(Object(source)).forEach(function(key) {
75
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
76
+ });
77
+ }
78
+ return target;
79
+ }
80
+ const getMaskOptions = (mask, _options)=>{
81
+ const options = _object_spread_props$2(_object_spread$2({}, _options), {
82
+ jitMasking: false
83
+ });
84
+ if (!mask) return options;
85
+ const masks = {
86
+ datetime: _object_spread$2({
87
+ alias: 'datetime',
88
+ inputFormat: 'dd/mm/yyyy',
89
+ placeholder: 'dd/mm/yyyy'
90
+ }, options),
91
+ cpf: _object_spread$2({
92
+ mask: '999.999.999-99',
93
+ placeholder: '___.___.___-__'
94
+ }, options),
95
+ cnpj: _object_spread$2({
96
+ mask: '99.999.999/9999-99',
97
+ placeholder: '__.___.___/____-__'
98
+ }, options),
99
+ email: _object_spread$2({
100
+ alias: 'email',
101
+ placeholder: ''
102
+ }, options),
103
+ numeric: _object_spread$2({
104
+ alias: 'numeric',
105
+ placeholder: ''
106
+ }, options),
107
+ currency: _object_spread$2({
108
+ alias: 'currency',
109
+ prefix: '$ ',
110
+ placeholder: ''
111
+ }, options),
112
+ decimal: _object_spread$2({
113
+ alias: 'decimal',
114
+ placeholder: ''
115
+ }, options),
116
+ integer: _object_spread$2({
117
+ alias: 'integer',
118
+ placeholder: ''
119
+ }, options),
120
+ percentage: _object_spread$2({
121
+ alias: 'percentage',
122
+ placeholder: ' %',
123
+ suffix: ' %'
124
+ }, options),
125
+ url: _object_spread$2({
126
+ alias: 'url',
127
+ placeholder: 'https://'
128
+ }, options),
129
+ ip: _object_spread$2({
130
+ alias: 'ip'
131
+ }, options),
132
+ mac: _object_spread$2({
133
+ alias: 'mac'
134
+ }, options),
135
+ ssn: _object_spread$2({
136
+ alias: 'ssn'
137
+ }, options)
138
+ };
139
+ if (typeof mask === 'string') {
140
+ if (masks[mask]) return masks[mask];
141
+ } else if (typeof mask === 'object') {
142
+ return _object_spread$2({}, mask, options);
143
+ }
144
+ return _object_spread$2({
145
+ mask
146
+ }, options);
147
+ };
148
+
55
149
  const useInputMask = (props)=>{
56
150
  const { mask , register , options } = props;
57
151
  const ref = react.useRef(null);
@@ -59,9 +153,7 @@ const useInputMask = (props)=>{
59
153
  react.useEffect(()=>{
60
154
  if (!isServer) {
61
155
  if (!ref.current) return;
62
- const maskInput = Inputmask(_object_spread$2({
63
- mask
64
- }, options));
156
+ const maskInput = Inputmask(getMaskOptions(mask, options));
65
157
  maskInput.mask(ref.current);
66
158
  if (register && ref.current) {
67
159
  register(ref.current);
@@ -103,7 +195,7 @@ function _object_spread$1(target) {
103
195
  }
104
196
  return target;
105
197
  }
106
- function ownKeys(object, enumerableOnly) {
198
+ function ownKeys$1(object, enumerableOnly) {
107
199
  var keys = Object.keys(object);
108
200
  if (Object.getOwnPropertySymbols) {
109
201
  var symbols = Object.getOwnPropertySymbols(object);
@@ -116,12 +208,12 @@ function ownKeys(object, enumerableOnly) {
116
208
  }
117
209
  return keys;
118
210
  }
119
- function _object_spread_props(target, source) {
211
+ function _object_spread_props$1(target, source) {
120
212
  source = source != null ? source : {};
121
213
  if (Object.getOwnPropertyDescriptors) {
122
214
  Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
123
215
  } else {
124
- ownKeys(Object(source)).forEach(function(key) {
216
+ ownKeys$1(Object(source)).forEach(function(key) {
125
217
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
126
218
  });
127
219
  }
@@ -132,19 +224,28 @@ const withHookFormMask = (register, mask, options)=>{
132
224
  let newRef;
133
225
  if (register) {
134
226
  const { ref } = register;
135
- const maskInput = Inputmask(_object_spread$1({
136
- mask: mask || undefined
137
- }, options));
227
+ const maskInput = Inputmask(getMaskOptions(mask, options));
138
228
  newRef = flow((_ref)=>{
139
229
  if (_ref) maskInput.mask(_ref);
140
230
  return _ref;
141
231
  }, ref);
142
232
  }
143
- return _object_spread_props(_object_spread$1({}, register), {
233
+ return _object_spread_props$1(_object_spread$1({}, register), {
144
234
  ref: newRef
145
235
  });
146
236
  };
147
237
 
238
+ const withMask = (mask, options)=>(input)=>{
239
+ //
240
+ if (isServer) return input;
241
+ if (mask === null) return input;
242
+ const maskInput = Inputmask(getMaskOptions(mask, options));
243
+ if (input) {
244
+ maskInput.mask(input);
245
+ }
246
+ return input;
247
+ };
248
+
148
249
  function _define_property(obj, key, value) {
149
250
  if (key in obj) {
150
251
  Object.defineProperty(obj, key, {
@@ -173,19 +274,76 @@ function _object_spread(target) {
173
274
  }
174
275
  return target;
175
276
  }
176
- const withMask = (mask, options)=>(input)=>{
177
- //
178
- if (isServer) return input;
179
- const maskInput = Inputmask(_object_spread({
180
- mask: mask || undefined
181
- }, options));
182
- if (input) {
183
- maskInput.mask(input);
277
+ function ownKeys(object, enumerableOnly) {
278
+ var keys = Object.keys(object);
279
+ if (Object.getOwnPropertySymbols) {
280
+ var symbols = Object.getOwnPropertySymbols(object);
281
+ if (enumerableOnly) {
282
+ symbols = symbols.filter(function(sym) {
283
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
284
+ });
184
285
  }
185
- return input;
286
+ keys.push.apply(keys, symbols);
287
+ }
288
+ return keys;
289
+ }
290
+ function _object_spread_props(target, source) {
291
+ source = source != null ? source : {};
292
+ if (Object.getOwnPropertyDescriptors) {
293
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
294
+ } else {
295
+ ownKeys(Object(source)).forEach(function(key) {
296
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
297
+ });
298
+ }
299
+ return target;
300
+ }
301
+ function _object_without_properties(source, excluded) {
302
+ if (source == null) return {};
303
+ var target = _object_without_properties_loose(source, excluded);
304
+ var key, i;
305
+ if (Object.getOwnPropertySymbols) {
306
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
307
+ for(i = 0; i < sourceSymbolKeys.length; i++){
308
+ key = sourceSymbolKeys[i];
309
+ if (excluded.indexOf(key) >= 0) continue;
310
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
311
+ target[key] = source[key];
312
+ }
313
+ }
314
+ return target;
315
+ }
316
+ function _object_without_properties_loose(source, excluded) {
317
+ if (source == null) return {};
318
+ var target = {};
319
+ var sourceKeys = Object.keys(source);
320
+ var key, i;
321
+ for(i = 0; i < sourceKeys.length; i++){
322
+ key = sourceKeys[i];
323
+ if (excluded.indexOf(key) >= 0) continue;
324
+ target[key] = source[key];
325
+ }
326
+ return target;
327
+ }
328
+ function useHookFormMask(registerFn) {
329
+ return (fieldName, mask, options)=>{
330
+ if (!registerFn) throw new Error('registerFn is required');
331
+ const _registerFn = registerFn(fieldName), { ref } = _registerFn, restRegister = _object_without_properties(_registerFn, [
332
+ "ref"
333
+ ]);
334
+ const maskInput = Inputmask(getMaskOptions(mask, options));
335
+ const newRef = flow((_ref)=>{
336
+ if (_ref) maskInput.mask(_ref);
337
+ return _ref;
338
+ }, ref);
339
+ return _object_spread_props(_object_spread({}, restRegister), {
340
+ ref: newRef
341
+ });
186
342
  };
343
+ }
187
344
 
188
345
  exports.default = useInputMask;
346
+ exports.useHookFormMask = useHookFormMask;
189
347
  exports.withHookFormMask = withHookFormMask;
190
348
  exports.withMask = withMask;
191
349
  //# sourceMappingURL=index.cjs.map
@@ -1 +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 function flow(...funcs: Array<Function>) : Function {\n const { length } = funcs;\n let index = length;\n while (index--) {\n if (typeof funcs[index] !== 'function') {\n throw new TypeError('Expected a function');\n }\n }\n return (...args: Array<Function>) => {\n let i = 0;\n let result = length ? funcs[i].apply(this, args) : args[0];\n while (++i < length) {\n result = funcs[i].call(this, result);\n }\n return result;\n };\n}\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';\nimport { RefCallback } from 'react';\nimport { flow } from './utils';\nimport { Mask, Options, Register } from './types';\n\nexport const withHookFormMask = (register: Register, mask: Mask, options?: Options): Register => {\n //\n let newRef;\n\n if (register) {\n const { ref } = register;\n\n const maskInput = Inputmask({\n mask: mask || undefined,\n ...options,\n });\n\n newRef = flow((_ref: HTMLElement) => {\n if (_ref) maskInput.mask(_ref);\n return _ref;\n }, ref) as RefCallback<HTMLElement>;\n }\n\n return {\n ...register,\n ref: newRef as RefCallback<HTMLElement>,\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: mask || undefined,\n ...options,\n });\n\n if (input) {\n maskInput.mask(input);\n }\n\n return input;\n};\n"],"names":["isServer","window","document","createElement","flow","funcs","length","index","TypeError","args","i","result","apply","call","useInputMask","props","mask","register","options","ref","useRef","useEffect","current","maskInput","Inputmask","_object_spread","withHookFormMask","newRef","undefined","_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;AAEK,SAASC,IAAAA,CAAK,GAAGC,KAAsB,EAAa;IACzD,MAAM,EAAEC,MAAM,GAAE,GAAGD,KAAAA,CAAAA;AACnB,IAAA,IAAIE,KAAQD,GAAAA,MAAAA,CAAAA;AACZ,IAAA,MAAOC,KAAS,EAAA,CAAA;AACd,QAAA,IAAI,OAAOF,KAAK,CAACE,KAAAA,CAAM,KAAK,UAAY,EAAA;YACtC,MAAM,IAAIC,UAAU,qBAAuB,CAAA,CAAA;SAC5C;AACH,KAAA;IACA,OAAO,CAAC,GAAGC,IAA0B,GAAA;AACnC,QAAA,IAAIC,CAAI,GAAA,CAAA,CAAA;AACR,QAAA,IAAIC,MAASL,GAAAA,MAAAA,GAASD,KAAK,CAACK,CAAE,CAAA,CAAC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AoBD,MAAYE,OAAgC,GAAA;;IAE/F,IAAIS,MAAAA,CAAAA;AAEJ,IAAA,IAAIV,QAAU,EAAA;QACZ,MAAM,EAAEE,GAAG,GAAE,GAAGF,QAAAA,CAAAA;AAEhB,QAAA,MAAMM,YAAYC,SAAU,CAAAC,gBAAA,CAAA;AAC1BT,YAAAA,IAAAA,EAAMA,IAAQY,IAAAA,SAAAA;AACXV,SAAAA,EAAAA,OAAAA,CAAAA,CAAAA,CAAAA;QAGLS,MAASvB,GAAAA,IAAAA,CAAK,CAACyB,IAAsB,GAAA;YACnC,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MCvBaG,QAAW,GAAA,CAACd,IAAaE,EAAAA,OAAAA,GAAsB,CAACa,KAAiB,GAAA;;AAE5E,QAAA,IAAI/B,UAAU,OAAO+B,KAAAA,CAAAA;AAErB,QAAA,MAAMR,YAAYC,SAAU,CAAA,cAAA,CAAA;AAC1BR,YAAAA,IAAAA,EAAMA,IAAQY,IAAAA,SAAAA;AACXV,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;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/utils/flow.ts","../src/utils/isServer.ts","../src/utils/getMaskOptions.ts","../src/useMaskInput.ts","../src/withHookFormMask.ts","../src/withMask.ts","../src/useHookFormMask.ts"],"sourcesContent":["export function flow(...funcs: Array<Function>) : Function {\n const { length } = funcs;\n let index = length;\n while (index--) {\n if (typeof funcs[index] !== 'function') {\n throw new TypeError('Expected a function');\n }\n }\n return (...args: Array<Function>) => {\n let i = 0;\n let result = length ? funcs[i].apply(this, args) : args[0];\n while (++i < length) {\n result = funcs[i].call(this, result);\n }\n return result;\n };\n}\n","export const isServer = !(\n typeof window !== 'undefined'\n && window.document\n && window.document.createElement\n);\n","import { Mask, Options } from '../types';\n\nexport const getMaskOptions = (mask?: Mask, _options?: Options): Options => {\n const options: Options = {\n ..._options,\n jitMasking: false,\n };\n if (!mask) return options;\n\n const masks: Record<string, Inputmask.Options> = {\n datetime: {\n alias: 'datetime',\n inputFormat: 'dd/mm/yyyy',\n placeholder: 'dd/mm/yyyy',\n ...options,\n },\n cpf: {\n mask: '999.999.999-99',\n placeholder: '___.___.___-__',\n ...options,\n },\n cnpj: {\n mask: '99.999.999/9999-99',\n placeholder: '__.___.___/____-__',\n ...options,\n },\n email: {\n alias: 'email',\n placeholder: '',\n ...options,\n },\n numeric: {\n alias: 'numeric',\n placeholder: '',\n ...options,\n },\n currency: {\n alias: 'currency',\n prefix: '$ ',\n placeholder: '',\n ...options,\n },\n decimal: {\n alias: 'decimal',\n placeholder: '',\n ...options,\n },\n integer: {\n alias: 'integer',\n placeholder: '',\n ...options,\n },\n percentage: {\n alias: 'percentage',\n placeholder: ' %',\n suffix: ' %',\n ...options,\n },\n url: {\n alias: 'url',\n placeholder: 'https://',\n ...options,\n },\n ip: {\n alias: 'ip',\n ...options,\n },\n mac: {\n alias: 'mac',\n ...options,\n },\n ssn: {\n alias: 'ssn',\n ...options,\n },\n\n };\n\n if (typeof mask === 'string') {\n if (masks[mask]) return masks[mask];\n } else if (typeof mask === 'object') {\n return {\n ...mask,\n ...options,\n };\n }\n\n return {\n mask,\n ...options,\n };\n};\n","import { useEffect, useRef } from 'react';\nimport Inputmask from 'inputmask';\nimport { getMaskOptions, isServer } from './utils';\nimport { Mask, Options } from './types';\n\ninterface UseInputMaskOptions {\n mask: Mask,\n register?(element: HTMLElement): void\n options?: 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(getMaskOptions(mask, options));\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';\nimport { RefCallback } from 'react';\nimport { flow, getMaskOptions } from './utils';\nimport { Mask, Options, UseFormRegisterReturn } from './types';\n\nexport const withHookFormMask = (\n register: UseFormRegisterReturn,\n mask: Mask,\n options?: Options,\n): UseFormRegisterReturn => {\n //\n let newRef;\n\n if (register) {\n const { ref } = register;\n\n const maskInput = Inputmask(getMaskOptions(mask, options));\n\n newRef = flow((_ref: HTMLElement) => {\n if (_ref) maskInput.mask(_ref);\n return _ref;\n }, ref) as RefCallback<HTMLElement>;\n }\n\n return {\n ...register,\n ref: newRef as RefCallback<HTMLElement>,\n };\n};\n","import Inputmask from 'inputmask';\nimport { getMaskOptions, 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 if (mask === null) return input;\n\n const maskInput = Inputmask(getMaskOptions(mask, options));\n\n if (input) {\n maskInput.mask(input);\n }\n\n return input;\n};\n","import Inputmask from 'inputmask';\nimport { RefCallback } from 'react';\nimport {\n FieldValues, Path, UseFormRegister, RegisterOptions,\n} from 'react-hook-form';\nimport { flow, getMaskOptions } from './utils';\nimport { Mask, Options } from './types';\n\nexport function useHookFormMask<\n T extends FieldValues, D extends RegisterOptions,\n>(registerFn: UseFormRegister<T>) {\n return (fieldName: Path<T>, mask: Mask, options?: Options & D) => {\n if (!registerFn) throw new Error('registerFn is required');\n\n const { ref, ...restRegister } = registerFn(fieldName);\n\n const maskInput = Inputmask(getMaskOptions(mask, options));\n\n const newRef = flow((_ref: HTMLElement) => {\n if (_ref) maskInput.mask(_ref);\n return _ref;\n }, ref) as RefCallback<HTMLElement>;\n\n return {\n ...restRegister,\n ref: newRef as RefCallback<HTMLElement>,\n };\n };\n}\n"],"names":["flow","funcs","length","index","TypeError","args","i","result","apply","call","isServer","window","document","createElement","getMaskOptions","mask","_options","options","_object_spread_props","jitMasking","masks","datetime","_object_spread","alias","inputFormat","placeholder","cpf","cnpj","email","numeric","currency","prefix","decimal","integer","percentage","suffix","url","ip","mac","ssn","useInputMask","props","register","ref","useRef","useEffect","current","maskInput","Inputmask","withHookFormMask","newRef","_ref","withMask","input","useHookFormMask","registerFn","fieldName","Error","restRegister"],"mappings":";;;;;;;AAAO,SAASA,IAAAA,CAAK,GAAGC,KAAsB,EAAa;IACzD,MAAM,EAAEC,MAAM,GAAE,GAAGD,KAAAA,CAAAA;AACnB,IAAA,IAAIE,KAAQD,GAAAA,MAAAA,CAAAA;AACZ,IAAA,MAAOC,KAAS,EAAA,CAAA;AACd,QAAA,IAAI,OAAOF,KAAK,CAACE,KAAAA,CAAM,KAAK,UAAY,EAAA;YACtC,MAAM,IAAIC,UAAU,qBAAuB,CAAA,CAAA;SAC5C;AACH,KAAA;IACA,OAAO,CAAC,GAAGC,IAA0B,GAAA;AACnC,QAAA,IAAIC,CAAI,GAAA,CAAA,CAAA;AACR,QAAA,IAAIC,MAASL,GAAAA,MAAAA,GAASD,KAAK,CAACK,CAAE,CAAA,CAACE,KAAK,CAAC,IAAI,EAAEH,IAAQA,CAAAA,GAAAA,IAAI,CAAC,CAAE,CAAA,CAAA;QAC1D,MAAO,EAAEC,IAAIJ,MAAQ,CAAA;AACnBK,YAAAA,MAAAA,GAASN,KAAK,CAACK,CAAAA,CAAE,CAACG,IAAI,CAAC,IAAI,EAAEF,MAAAA,CAAAA,CAAAA;AAC/B,SAAA;QACA,OAAOA,MAAAA,CAAAA;AACT,KAAA,CAAA;AACF;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YACzB,OAAOA,IAAAA,CAAAA;SACNR,EAAAA,GAAAA,CAAAA,CAAAA;AAEH,QAAA,OAAO,oBACFe,CAAAA,cAAAA,CAAAA,EAAAA,EAAAA,YAAAA,CAAAA,EAAAA;YACHf,GAAKO,EAAAA,MAAAA;;AAET,KAAA,CAAA;AACF;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,21 +1,34 @@
1
1
  import * as react from 'react';
2
- import Inputmask$1 from 'inputmask';
3
- import { UseFormRegisterReturn } from 'react-hook-form';
2
+ import * as react_hook_form from 'react-hook-form';
3
+ import { UseFormRegisterReturn, FieldValues, RegisterOptions, UseFormRegister, Path } from 'react-hook-form';
4
+
5
+ type Mask = 'email' | 'cpf' | 'datetime' | 'numeric' | 'currency' | 'decimal' | 'integer' | (string & {}) | (string[] & {}) | null;
6
+ type Options = Inputmask.Options;
7
+ type Input = HTMLInputElement | HTMLTextAreaElement | HTMLElement | HTMLInputElement | null;
4
8
 
5
9
  interface UseInputMaskOptions {
6
- mask: Inputmask$1.Options['mask'];
10
+ mask: Mask;
7
11
  register?(element: HTMLElement): void;
8
- options?: Inputmask$1.Options;
12
+ options?: Options;
9
13
  }
10
14
  declare const useInputMask: (props: UseInputMaskOptions) => react.RefObject<HTMLInputElement>;
11
15
 
12
- type Register = UseFormRegisterReturn;
13
- type Mask = Inputmask.Options['mask'];
14
- type Options = Inputmask.Options;
15
- type Input = HTMLInputElement | HTMLTextAreaElement | HTMLElement | HTMLInputElement | null;
16
+ declare const withHookFormMask: (register: UseFormRegisterReturn, mask: Mask, options?: Options) => UseFormRegisterReturn;
16
17
 
17
- declare const withHookFormMask: (register: Register, mask: Mask, options?: Options) => Register;
18
+ declare const withMask: (mask: Mask, options?: Options) => (input: Input) => Input;
18
19
 
19
- declare const withMask: (mask?: Mask, options?: Options) => (input: Input) => Input;
20
+ declare function useHookFormMask<T extends FieldValues, D extends RegisterOptions>(registerFn: UseFormRegister<T>): (fieldName: Path<T>, mask: Mask, options?: Options & D) => {
21
+ ref: (instance: HTMLElement | null) => void;
22
+ onChange: react_hook_form.ChangeHandler;
23
+ onBlur: react_hook_form.ChangeHandler;
24
+ name: Path<T>;
25
+ min?: string | number | undefined;
26
+ max?: string | number | undefined;
27
+ maxLength?: number | undefined;
28
+ minLength?: number | undefined;
29
+ pattern?: string | undefined;
30
+ required?: boolean | undefined;
31
+ disabled?: boolean | undefined;
32
+ };
20
33
 
21
- export { useInputMask as default, withHookFormMask, withMask };
34
+ export { useInputMask as default, useHookFormMask, withHookFormMask, withMask };