use-mask-input 3.6.0 → 3.6.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 (39) hide show
  1. package/CHANGELOG.md +47 -76
  2. package/README.md +2 -251
  3. package/dist/index.cjs +157 -84
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +52 -11
  6. package/dist/index.d.ts +52 -11
  7. package/dist/index.js +158 -85
  8. package/dist/index.js.map +1 -1
  9. package/package.json +21 -21
  10. package/src/api/index.ts +4 -0
  11. package/src/api/useHookFormMask.spec.ts +146 -0
  12. package/src/api/useHookFormMask.ts +56 -0
  13. package/src/api/useMaskInput-server.spec.tsx +30 -0
  14. package/src/api/useMaskInput.spec.tsx +220 -0
  15. package/src/api/useMaskInput.ts +64 -0
  16. package/src/api/withHookFormMask.spec.ts +155 -0
  17. package/src/api/withHookFormMask.ts +54 -0
  18. package/src/api/withMask.spec.ts +93 -0
  19. package/src/api/withMask.ts +25 -0
  20. package/src/core/elementResolver.spec.ts +175 -0
  21. package/src/core/elementResolver.ts +84 -0
  22. package/src/core/index.ts +3 -0
  23. package/src/core/maskConfig.spec.ts +183 -0
  24. package/src/{utils/getMaskOptions.ts → core/maskConfig.ts} +12 -3
  25. package/src/core/maskEngine.spec.ts +108 -0
  26. package/src/core/maskEngine.ts +47 -0
  27. package/src/index.tsx +12 -5
  28. package/src/{types.ts → types/index.ts} +13 -0
  29. package/src/utils/flow.spec.ts +27 -30
  30. package/src/utils/flow.ts +2 -2
  31. package/src/utils/index.ts +1 -1
  32. package/src/utils/isServer.spec.ts +15 -0
  33. package/src/utils/moduleInterop.spec.ts +37 -0
  34. package/src/useHookFormMask.ts +0 -47
  35. package/src/useMaskInput.ts +0 -41
  36. package/src/utils/getMaskOptions.spec.ts +0 -126
  37. package/src/withHookFormMask.ts +0 -34
  38. package/src/withMask.ts +0 -18
  39. /package/src/{inputmask.types.ts → types/inputmask.types.ts} +0 -0
@@ -1,126 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
- import getMaskOptions from './getMaskOptions';
4
-
5
- describe('getMaskOptions', () => {
6
- it('returns default options when no mask is provided', () => {
7
- const options = getMaskOptions();
8
- expect(options).toEqual({
9
- jitMasking: false,
10
- });
11
- });
12
-
13
- it('returns options for datetime mask', () => {
14
- const options = getMaskOptions('datetime');
15
- expect(options).toEqual({
16
- alias: 'datetime',
17
- jitMasking: false,
18
- });
19
- });
20
-
21
- it('returns options for cpf mask', () => {
22
- const options = getMaskOptions('cpf');
23
- expect(options).toEqual({
24
- mask: '999.999.999-99',
25
- placeholder: '___.___.___-__',
26
- jitMasking: false,
27
- });
28
- });
29
-
30
- it('returns options for email mask', () => {
31
- const options = getMaskOptions('email');
32
- expect(options).toEqual({
33
- alias: 'email',
34
- placeholder: '',
35
- jitMasking: false,
36
- });
37
- });
38
-
39
- it('returns options for numeric mask', () => {
40
- const options = getMaskOptions('numeric');
41
- expect(options).toEqual({
42
- alias: 'numeric',
43
- placeholder: '',
44
- jitMasking: false,
45
- });
46
- });
47
-
48
- it('returns options for currency mask', () => {
49
- const options = getMaskOptions('currency');
50
- expect(options).toEqual({
51
- alias: 'currency',
52
- prefix: '$ ',
53
- placeholder: '',
54
- jitMasking: false,
55
- });
56
- });
57
-
58
- it('returns options for decimal mask', () => {
59
- const options = getMaskOptions('decimal');
60
- expect(options).toEqual({
61
- alias: 'decimal',
62
- placeholder: '',
63
- jitMasking: false,
64
- });
65
- });
66
-
67
- it('returns options for integer mask', () => {
68
- const options = getMaskOptions('integer');
69
- expect(options).toEqual({
70
- alias: 'integer',
71
- placeholder: '',
72
- jitMasking: false,
73
- });
74
- });
75
-
76
- it('returns options for percentage mask', () => {
77
- const options = getMaskOptions('percentage');
78
- expect(options).toEqual({
79
- alias: 'percentage',
80
- placeholder: ' %',
81
- suffix: ' %',
82
- jitMasking: false,
83
- });
84
- });
85
-
86
- it('returns options for url mask', () => {
87
- const options = getMaskOptions('url');
88
- expect(options).toEqual({
89
- alias: 'url',
90
- placeholder: 'https://',
91
- jitMasking: false,
92
- });
93
- });
94
-
95
- it('returns options for ip mask', () => {
96
- const options = getMaskOptions('ip');
97
- expect(options).toEqual({
98
- alias: 'ip',
99
- jitMasking: false,
100
- });
101
- });
102
-
103
- it('returns options for mac mask', () => {
104
- const options = getMaskOptions('mac');
105
- expect(options).toEqual({
106
- alias: 'mac',
107
- jitMasking: false,
108
- });
109
- });
110
-
111
- it('returns options for ssn mask', () => {
112
- const options = getMaskOptions('ssn');
113
- expect(options).toEqual({
114
- alias: 'ssn',
115
- jitMasking: false,
116
- });
117
- });
118
-
119
- it('returns options for custom mask', () => {
120
- const options = getMaskOptions('999-999');
121
- expect(options).toEqual({
122
- mask: '999-999',
123
- jitMasking: false,
124
- });
125
- });
126
- });
@@ -1,34 +0,0 @@
1
- /* eslint-disable import-x/no-extraneous-dependencies */
2
- import inputmask from 'inputmask';
3
-
4
- import { flow, getMaskOptions } from './utils';
5
- import interopDefaultSync from './utils/moduleInterop';
6
-
7
- import type { RefCallback } from 'react';
8
-
9
- import type { Mask, Options, UseFormRegisterReturn } from './types';
10
-
11
- export default function withHookFormMask(
12
- register: UseFormRegisterReturn,
13
- mask: Mask,
14
- options?: Options,
15
- ): UseFormRegisterReturn {
16
- //
17
- let newRef;
18
-
19
- if (register) {
20
- const { ref } = register;
21
-
22
- const maskInput = interopDefaultSync(inputmask)(getMaskOptions(mask, options));
23
-
24
- newRef = flow((_ref: HTMLElement) => {
25
- if (_ref) maskInput.mask(_ref);
26
- return _ref;
27
- }, ref) as RefCallback<HTMLElement>;
28
- }
29
-
30
- return {
31
- ...register,
32
- ref: newRef as RefCallback<HTMLElement>,
33
- };
34
- }
package/src/withMask.ts DELETED
@@ -1,18 +0,0 @@
1
- /* eslint-disable import-x/no-extraneous-dependencies */
2
- import inputmask from 'inputmask';
3
-
4
- import { getMaskOptions } from './utils';
5
- import isServer from './utils/isServer';
6
- import interopDefaultSync from './utils/moduleInterop';
7
-
8
- import type { Input, Mask, Options } from './types';
9
-
10
- export default function withMask(mask: Mask, options?: Options) {
11
- return (input: Input | null): void => {
12
- if (isServer || mask === null || !input) return;
13
-
14
- const maskInput = interopDefaultSync(inputmask)(getMaskOptions(mask, options));
15
-
16
- maskInput.mask(input);
17
- };
18
- }