use-mask-input 3.10.1 → 3.10.2

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 (46) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/dist/antd.cjs +1 -65
  3. package/dist/antd.cjs.map +1 -1
  4. package/dist/antd.d.cts +12 -10
  5. package/dist/{antd.d.ts → antd.d.mts} +12 -10
  6. package/dist/antd.mjs +2 -0
  7. package/dist/antd.mjs.map +1 -0
  8. package/dist/index-BmKzoe0X.d.cts +836 -0
  9. package/dist/index-BmKzoe0X.d.mts +836 -0
  10. package/dist/index.cjs +1 -173
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +18 -15
  13. package/dist/{index.d.ts → index.d.mts} +18 -15
  14. package/dist/index.mjs +2 -0
  15. package/dist/index.mjs.map +1 -0
  16. package/dist/withMask-VWeBqi_u.cjs +2 -0
  17. package/dist/withMask-VWeBqi_u.cjs.map +1 -0
  18. package/dist/withMask-jrErtLYS.mjs +2 -0
  19. package/dist/withMask-jrErtLYS.mjs.map +1 -0
  20. package/package.json +42 -22
  21. package/dist/antd.js +0 -63
  22. package/dist/antd.js.map +0 -1
  23. package/dist/chunk-PMBRAXS4.cjs +0 -5876
  24. package/dist/chunk-PMBRAXS4.cjs.map +0 -1
  25. package/dist/chunk-XSTQDKDU.js +0 -5866
  26. package/dist/chunk-XSTQDKDU.js.map +0 -1
  27. package/dist/index-D8KkaDbQ.d.cts +0 -596
  28. package/dist/index-D8KkaDbQ.d.ts +0 -596
  29. package/dist/index.js +0 -165
  30. package/dist/index.js.map +0 -1
  31. package/src/antd/useHookFormMaskAntd.spec.ts +0 -181
  32. package/src/antd/useMaskInputAntd-server.spec.tsx +0 -37
  33. package/src/antd/useMaskInputAntd.spec.tsx +0 -131
  34. package/src/api/useHookFormMask.spec.ts +0 -259
  35. package/src/api/useMaskInput-server.spec.tsx +0 -30
  36. package/src/api/useMaskInput.spec.tsx +0 -238
  37. package/src/api/withHookFormMask.spec.ts +0 -179
  38. package/src/api/withMask.spec.ts +0 -137
  39. package/src/api/withTanStackFormMask.spec.ts +0 -76
  40. package/src/core/elementResolver.spec.ts +0 -175
  41. package/src/core/inputmask.spec.ts +0 -21
  42. package/src/core/maskConfig.spec.ts +0 -208
  43. package/src/core/maskEngine.spec.ts +0 -114
  44. package/src/utils/flow.spec.ts +0 -57
  45. package/src/utils/isServer.spec.ts +0 -15
  46. package/src/utils/moduleInterop.spec.ts +0 -37
@@ -1,114 +0,0 @@
1
- import inputmask from './inputmask';
2
- import {
3
- beforeEach, describe, expect, it, vi,
4
- } from 'vitest';
5
-
6
- import { applyMaskToElement, createMaskInstance } from './maskEngine';
7
-
8
- type MaskInstance = ReturnType<typeof createMaskInstance>;
9
-
10
- function stubMaskInstance(maskFn: ReturnType<typeof vi.fn>): MaskInstance {
11
- return { mask: maskFn } as unknown as MaskInstance;
12
- }
13
-
14
- vi.mock('./inputmask', () => ({
15
- default: vi.fn((options) => ({
16
- mask: vi.fn(),
17
- options,
18
- })),
19
- }));
20
-
21
- describe('maskEngine', () => {
22
- beforeEach(() => {
23
- vi.clearAllMocks();
24
- });
25
-
26
- describe('createMaskInstance', () => {
27
- it('creates mask instance with string mask', () => {
28
- const instance = createMaskInstance('999-999');
29
- expect(inputmask).toHaveBeenCalled();
30
- expect(instance).toBeDefined();
31
- });
32
-
33
- it('creates mask instance with alias', () => {
34
- const instance = createMaskInstance('cpf');
35
- expect(inputmask).toHaveBeenCalled();
36
- expect(instance).toBeDefined();
37
- });
38
-
39
- it('creates mask instance with options', () => {
40
- const instance = createMaskInstance('999-999', { placeholder: '_' });
41
- expect(inputmask).toHaveBeenCalled();
42
- expect(instance).toBeDefined();
43
- });
44
-
45
- it('creates mask instance with array mask', () => {
46
- const instance = createMaskInstance(['999-999', '9999-9999']);
47
- expect(inputmask).toHaveBeenCalled();
48
- expect(instance).toBeDefined();
49
- });
50
- });
51
-
52
- describe('applyMaskToElement', () => {
53
- it('applies mask to input element', () => {
54
- const input = document.createElement('input');
55
- const maskFn = vi.fn();
56
- vi.mocked(inputmask).mockImplementation(() => stubMaskInstance(maskFn));
57
-
58
- applyMaskToElement(input, '999-999');
59
-
60
- expect(maskFn).toHaveBeenCalledWith(input);
61
- });
62
-
63
- it('applies mask to textarea element', () => {
64
- const textarea = document.createElement('textarea');
65
- const maskFn = vi.fn();
66
- vi.mocked(inputmask).mockImplementation(() => stubMaskInstance(maskFn));
67
-
68
- applyMaskToElement(textarea, '999-999');
69
-
70
- expect(maskFn).toHaveBeenCalledWith(textarea);
71
- });
72
-
73
- it('finds and applies mask to input inside wrapper', () => {
74
- const wrapper = document.createElement('div');
75
- const input = document.createElement('input');
76
- wrapper.appendChild(input);
77
- const maskFn = vi.fn();
78
- vi.mocked(inputmask).mockImplementation(() => stubMaskInstance(maskFn));
79
-
80
- applyMaskToElement(wrapper, '999-999');
81
-
82
- expect(maskFn).toHaveBeenCalledWith(input);
83
- });
84
-
85
- it('applies mask to wrapper if no input found inside', () => {
86
- const wrapper = document.createElement('div');
87
- const maskFn = vi.fn();
88
- vi.mocked(inputmask).mockImplementation(() => stubMaskInstance(maskFn));
89
-
90
- applyMaskToElement(wrapper, '999-999');
91
-
92
- expect(maskFn).toHaveBeenCalledWith(wrapper);
93
- });
94
-
95
- it('does nothing if element is null', () => {
96
- const maskFn = vi.fn();
97
- vi.mocked(inputmask).mockImplementation(() => stubMaskInstance(maskFn));
98
-
99
- applyMaskToElement(null as unknown as HTMLElement, '999-999');
100
-
101
- expect(maskFn).not.toHaveBeenCalled();
102
- });
103
-
104
- it('applies mask with custom options', () => {
105
- const input = document.createElement('input');
106
- const maskFn = vi.fn();
107
- vi.mocked(inputmask).mockImplementation(() => stubMaskInstance(maskFn));
108
-
109
- applyMaskToElement(input, '999-999', { placeholder: '_' });
110
-
111
- expect(maskFn).toHaveBeenCalledWith(input);
112
- });
113
- });
114
- });
@@ -1,57 +0,0 @@
1
- import {
2
- describe, expect, it,
3
- } from 'vitest';
4
-
5
- import flow from './flow';
6
-
7
- describe('flow', () => {
8
- it('returns a function', () => {
9
- const result = flow();
10
- expect(typeof result).toBe('function');
11
- });
12
-
13
- it('returns undefined value if no return function provided', () => {
14
- const result = flow(() => { });
15
- expect(result(42)).toBe(undefined);
16
- });
17
-
18
- it('throws an error if any argument is not a function', () => {
19
- // @ts-expect-error - null is not a function
20
- expect(() => flow(null)).toThrow(TypeError);
21
- // @ts-expect-error - null is not a function
22
- expect(() => flow(() => { }, null)).toThrow(TypeError);
23
- expect(() => {
24
- flow(1 as unknown as () => void, () => { });
25
- }).toThrow(TypeError);
26
- });
27
-
28
- it('returns the original value if no functions are provided', () => {
29
- const result = flow();
30
- expect(result(42)).toBe(42);
31
- expect(result('test')).toBe('test');
32
- });
33
-
34
- it('composes functions correctly', () => {
35
- const addOne = (x: number) => x + 1;
36
- const multiplyByTwo = (x: number) => x * 2;
37
- const subtractThree = (x: number) => x - 3;
38
-
39
- const composed = flow(addOne, multiplyByTwo, subtractThree);
40
- expect(composed(5)).toBe(9); // (5 + 1) * 2 - 3 = 9
41
- });
42
-
43
- it('works with single function', () => {
44
- const double = (x: number) => x * 2;
45
- const fn = flow(double);
46
- expect(fn(5)).toBe(10);
47
- });
48
-
49
- it('works with multiple functions', () => {
50
- const fn1 = (n: number) => n + 1;
51
- const fn2 = (n: number) => n * 2;
52
- const fn3 = (n: number) => n - 1;
53
-
54
- const composed = flow(fn1, fn2, fn3);
55
- expect(composed(5)).toBe(11); // ((5 + 1) * 2) - 1 = 11
56
- });
57
- });
@@ -1,15 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
- describe('isServer', () => {
4
- it('returns boolean value', async () => {
5
- const { default: isServer } = await import('./isServer');
6
- expect(typeof isServer).toBe('boolean');
7
- });
8
-
9
- it('returns false in browser environment', async () => {
10
- // in jsdom environment, window and document exist
11
- const { default: isServer } = await import('./isServer');
12
- // in test environment with jsdom, it should be false
13
- expect(isServer).toBe(false);
14
- });
15
- });
@@ -1,37 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
- import interopDefaultSync from './moduleInterop';
4
-
5
- describe('interopDefaultSync', () => {
6
- it('returns module with default export', () => {
7
- const module = { default: 'test' };
8
- expect(interopDefaultSync(module)).toBe('test');
9
- });
10
-
11
- it('returns module without default export', () => {
12
- const module = { foo: 'bar' };
13
- expect(interopDefaultSync(module)).toBe(module);
14
- });
15
-
16
- it('returns non-object values as-is', () => {
17
- expect(interopDefaultSync('string')).toBe('string');
18
- expect(interopDefaultSync(123)).toBe(123);
19
- expect(interopDefaultSync(null)).toBe(null);
20
- // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
21
- expect(interopDefaultSync(undefined)).toBe(undefined);
22
- });
23
-
24
- it('handles null module', () => {
25
- expect(interopDefaultSync(null)).toBe(null);
26
- });
27
-
28
- it('handles module with null default', () => {
29
- const module = { default: null };
30
- expect(interopDefaultSync(module)).toBe(null);
31
- });
32
-
33
- it('handles module with undefined default', () => {
34
- const module = { default: undefined };
35
- expect(interopDefaultSync(module)).toBe(undefined);
36
- });
37
- });