use-mask-input 3.7.4 → 3.8.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 CHANGED
@@ -1,5 +1,33 @@
1
1
  ## [3.6.0](https://github.com/eduardoborges/use-mask-input/compare/3.5.2...3.6.0) (2026-01-13)
2
2
 
3
+ ## 3.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - eacce0f: feat: add Brazilian banking masks (br-bank-account and br-bank-agency)
8
+
9
+ Added two new mask aliases for Brazilian banking information:
10
+
11
+ - `br-bank-account`: Supports multiple Brazilian bank account formats including Bradesco, Itaú, Banco do Brasil, Caixa Econômica, Nubank, and more
12
+ - `br-bank-agency`: Handles Brazilian bank agency numbers with optional check digits
13
+
14
+ These masks automatically adapt to different account number formats used by major Brazilian banks, making it easier to handle banking data in forms.
15
+
16
+ Example usage:
17
+
18
+ ```tsx
19
+ const accountMask = useMaskInput({ mask: "br-bank-account" });
20
+ const agencyMask = useMaskInput({ mask: "br-bank-agency" });
21
+ ```
22
+
23
+ ### Patch Changes
24
+
25
+ - a614d93: fix: sync DOM value after react-hook-form `reset()` in `useHookFormMask`
26
+
27
+ `reset()` in react-hook-form clears its internal field registry before re-rendering. On the subsequent render it returns a new ref callback that, when called, syncs the DOM to the reset value. Because `useHookFormMask` caches a stable ref, React never calls that new callback — leaving masked inputs stale after `reset()`.
28
+
29
+ Fixed by using a `useLayoutEffect` queue that replays the latest RHF ref callback against the stored element after each render. RHF's own guard makes this a no-op on normal re-renders; it only does real work after `reset()` clears the registry.
30
+
3
31
  ## 3.7.4
4
32
 
5
33
  ### Patch Changes
package/README.md CHANGED
@@ -1,62 +1,90 @@
1
1
  <div align="center">
2
- <h1>🥸 use-mask-input</h1>
3
- <h4>A React Hook for building elegant and simple input masks.</h4>
2
+ <h1>use-mask-input</h1>
3
+ <p>Input masks for React. Simple, lightweight, and framework-friendly.</p>
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/use-mask-input)](https://www.npmjs.com/package/use-mask-input)
6
6
  [![npm downloads](https://img.shields.io/npm/dw/use-mask-input)](https://www.npmjs.com/package/use-mask-input)
7
- [![npm package minimized gzipped size (select exports)](https://img.shields.io/bundlejs/size/use-mask-input?color=green-light)](https://bundlejs.com/?q=use-mask-input)
7
+ [![bundle size](https://img.shields.io/bundlejs/size/use-mask-input?color=green-light)](https://bundlejs.com/?q=use-mask-input)
8
8
  [![codecov](https://codecov.io/gh/eduardoborges/use-mask-input/branch/main/graph/badge.svg?token=8ORAOAUZTP)](https://codecov.io/gh/eduardoborges/use-mask-input)
9
+
10
+ [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/E1E71VQENQ)
9
11
  </div>
10
12
 
11
- ## [Full Documentation](http://use-mask-input.eduardoborges.dev) | [Sponsor this project](https://github.com/eduardoborges?tab=sponsors)
13
+ ---
14
+
15
+ **[Documentation](http://use-mask-input.eduardoborges.dev)** · **[API Reference](http://use-mask-input.eduardoborges.dev/api-reference)** · **[Sponsor](https://ko-fi.com/E1E71VQENQ)**
12
16
 
13
- ## Features
14
- - 🎯 Simple API
15
- - 💎 Works like a charm with *Next.js*
16
- - ✨ Compatible with [React Hook Form](https://github.com/react-hook-form/react-hook-form)
17
- - 🏁 Compatible with [React Final Form](https://github.com/final-form/react-final-form)
18
17
  ## Install
19
18
 
20
19
  ```sh
21
- npm i use-mask-input
20
+ npm install use-mask-input
22
21
  ```
23
22
 
24
- ## Quickstart
23
+ ## Usage
25
24
 
26
- ```jsx
27
- import React from 'react'
25
+ ```tsx
28
26
  import { useMaskInput } from 'use-mask-input';
29
27
 
30
- const App = () => {
31
- return (
32
- <input type="text" ref={withMask('9999-9999')} />
33
- )
28
+ function PhoneInput() {
29
+ const ref = useMaskInput({ mask: '(99) 99999-9999' });
30
+ return <input ref={ref} />;
34
31
  }
35
32
  ```
36
33
 
37
- ### Usage with React Hook Forms
34
+ ### With React Hook Form
38
35
 
39
- ```jsx
40
- import React from 'react';
36
+ ```tsx
41
37
  import { useForm } from 'react-hook-form';
42
38
  import { useHookFormMask } from 'use-mask-input';
43
39
 
44
- function App() {
40
+ function MyForm() {
45
41
  const { register, handleSubmit } = useForm();
46
42
  const registerWithMask = useHookFormMask(register);
47
43
 
48
- ...
49
-
50
44
  return (
51
- <form onSubmit={onSubmit}>
52
- <input
53
- {...registerWithMask("phone", ['99 9999-9999', '99999-9999'], {
54
- required: true
55
- })}
56
- type="text"
57
- />
45
+ <form onSubmit={handleSubmit(console.log)}>
46
+ <input {...registerWithMask('phone', '(99) 99999-9999')} />
47
+ <input {...registerWithMask('cpf', 'cpf')} />
58
48
  <button type="submit">Submit</button>
59
49
  </form>
60
50
  );
61
51
  }
62
52
  ```
53
+
54
+ ### With Ant Design
55
+
56
+ ```tsx
57
+ import { Input } from 'antd';
58
+ import { useMaskInputAntd } from 'use-mask-input/antd';
59
+
60
+ function CPFInput() {
61
+ const ref = useMaskInputAntd({ mask: 'cpf' });
62
+ return <Input ref={ref} />;
63
+ }
64
+ ```
65
+
66
+ ## APIs
67
+
68
+ | API | Description |
69
+ |-----|-------------|
70
+ | `useMaskInput` | Hook. Returns a ref callback. Default choice. |
71
+ | `useHookFormMask` | Hook. Wraps React Hook Form's `register`. |
72
+ | `withMask` | Function. Ref callback. Requires `React.memo`. |
73
+ | `withHookFormMask` | Function. Mask for registered fields. Requires `React.memo`. |
74
+ | `useMaskInputAntd` | Hook. `useMaskInput` for Ant Design. |
75
+ | `useHookFormMaskAntd` | Hook. `useHookFormMask` for Ant Design. |
76
+
77
+ ## Built-in Aliases
78
+
79
+ `cpf` · `cnpj` · `br-bank-account` · `br-bank-agency` · `currency` · `brl-currency` · `datetime` · `email` · `numeric` · `decimal` · `integer` · `percentage` · `url` · `ip` · `mac` · `ssn`
80
+
81
+ ## Works With
82
+
83
+ - React Hook Form
84
+ - Ant Design
85
+ - React Final Form
86
+ - Next.js / SSR
87
+
88
+ ## License
89
+
90
+ MIT
package/dist/antd.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkVK6LQ75W_cjs = require('./chunk-VK6LQ75W.cjs');
3
+ var chunkX5SEJVSB_cjs = require('./chunk-X5SEJVSB.cjs');
4
4
  var react = require('react');
5
5
 
6
6
  function useHookFormMaskAntd(registerFn) {
@@ -10,11 +10,11 @@ function useHookFormMaskAntd(registerFn) {
10
10
  if (!registerFn) throw new Error("registerFn is required");
11
11
  const registerReturn = registerFn(fieldName, options);
12
12
  const { ref } = registerReturn;
13
- const cacheKey = chunkVK6LQ75W_cjs.makeMaskCacheKey(fieldName, mask);
13
+ const cacheKey = chunkX5SEJVSB_cjs.makeMaskCacheKey(fieldName, mask);
14
14
  if (!refCache.has(cacheKey)) {
15
15
  const refWithMask = (inputRef) => {
16
- const element = inputRef ? chunkVK6LQ75W_cjs.resolveInputRef(inputRef.input) : null;
17
- if (element) chunkVK6LQ75W_cjs.applyMaskToElement(element, mask, options);
16
+ const element = inputRef ? chunkX5SEJVSB_cjs.resolveInputRef(inputRef.input) : null;
17
+ if (element) chunkX5SEJVSB_cjs.applyMaskToElement(element, mask, options);
18
18
  if (ref) ref(element);
19
19
  };
20
20
  refCache.set(cacheKey, refWithMask);
@@ -23,7 +23,7 @@ function useHookFormMaskAntd(registerFn) {
23
23
  ...registerReturn,
24
24
  ref: refCache.get(cacheKey)
25
25
  };
26
- chunkVK6LQ75W_cjs.setPrevRef(result, ref);
26
+ chunkX5SEJVSB_cjs.setPrevRef(result, ref);
27
27
  return result;
28
28
  };
29
29
  }, [registerFn]);
@@ -41,17 +41,17 @@ function useMaskInputAntd(props) {
41
41
  ref.current = null;
42
42
  return;
43
43
  }
44
- ref.current = chunkVK6LQ75W_cjs.resolveInputRef(input.input);
44
+ ref.current = chunkX5SEJVSB_cjs.resolveInputRef(input.input);
45
45
  if (ref.current && ref.current !== maskedElementRef.current) {
46
- chunkVK6LQ75W_cjs.withMask(maskRef.current, optionsRef.current)(ref.current);
46
+ chunkX5SEJVSB_cjs.withMask(maskRef.current, optionsRef.current)(ref.current);
47
47
  maskedElementRef.current = ref.current;
48
48
  }
49
49
  }, []);
50
50
  react.useEffect(() => {
51
- if (chunkVK6LQ75W_cjs.isServer_default || !ref.current || !register) return;
51
+ if (chunkX5SEJVSB_cjs.isServer_default || !ref.current || !register) return;
52
52
  register(ref.current);
53
53
  }, [register]);
54
- if (chunkVK6LQ75W_cjs.isServer_default) {
54
+ if (chunkX5SEJVSB_cjs.isServer_default) {
55
55
  return () => {
56
56
  };
57
57
  }
package/dist/antd.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { InputRef } from 'antd';
2
2
  import { RefCallback } from 'react';
3
3
  import { FieldValues, RegisterOptions, UseFormRegister, Path } from 'react-hook-form';
4
- import { U as UseHookFormMaskReturn, M as Mask, O as Options } from './index-F3rlTTTe.cjs';
4
+ import { U as UseHookFormMaskReturn, M as Mask, O as Options } from './index-S8txl6uK.cjs';
5
5
 
6
6
  type UseHookFormMaskAntdReturn<T extends FieldValues> = Omit<UseHookFormMaskReturn<T>, 'ref'> & {
7
7
  ref: RefCallback<InputRef | null>;
package/dist/antd.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { InputRef } from 'antd';
2
2
  import { RefCallback } from 'react';
3
3
  import { FieldValues, RegisterOptions, UseFormRegister, Path } from 'react-hook-form';
4
- import { U as UseHookFormMaskReturn, M as Mask, O as Options } from './index-F3rlTTTe.js';
4
+ import { U as UseHookFormMaskReturn, M as Mask, O as Options } from './index-S8txl6uK.js';
5
5
 
6
6
  type UseHookFormMaskAntdReturn<T extends FieldValues> = Omit<UseHookFormMaskReturn<T>, 'ref'> & {
7
7
  ref: RefCallback<InputRef | null>;
package/dist/antd.js CHANGED
@@ -1,4 +1,4 @@
1
- import { makeMaskCacheKey, setPrevRef, resolveInputRef, withMask, isServer_default, applyMaskToElement } from './chunk-QCWLMMDI.js';
1
+ import { makeMaskCacheKey, setPrevRef, resolveInputRef, withMask, isServer_default, applyMaskToElement } from './chunk-ICLWBMH4.js';
2
2
  import { useMemo, useRef, useCallback, useEffect } from 'react';
3
3
 
4
4
  function useHookFormMaskAntd(registerFn) {
@@ -3704,6 +3704,25 @@ var ALIAS_MASKS = {
3704
3704
  cnpj: {
3705
3705
  mask: ["A|9{2}.A|9{3}.A|9{3}/A|9{4}-9{2}"],
3706
3706
  placeholder: "__.___.___/____-__"
3707
+ },
3708
+ "br-bank-account": {
3709
+ mask: [
3710
+ "9{4,10}[-]9",
3711
+ // Most common formats: 1234567-9, 12345678-9, 123456789-9, 1234567890-1
3712
+ "999999[-][9]",
3713
+ // Optional separator: 123456-7 or 1234567
3714
+ "[999]9{7,8}[-]9",
3715
+ // Caixa and Nu Pagamentos: (001)12345678-9 or (001)1234567-9
3716
+ "[9999]9{8}[-]9"
3717
+ // Caixa longer: (0001)12345678-9
3718
+ ],
3719
+ placeholder: "",
3720
+ greedy: false
3721
+ },
3722
+ "br-bank-agency": {
3723
+ mask: "9{1,5}[-][9]",
3724
+ // Agency numbers: 1234, 12345, 1234-5
3725
+ placeholder: ""
3707
3726
  }
3708
3727
  };
3709
3728
  function getMaskOptions(mask, _options) {
@@ -3842,5 +3861,5 @@ inputmask/dist/inputmask.js:
3842
3861
  */
3843
3862
 
3844
3863
  export { applyMaskToElement, flow, isServer_default, makeMaskCacheKey, resolveInputRef, setPrevRef, withMask };
3845
- //# sourceMappingURL=chunk-QCWLMMDI.js.map
3846
- //# sourceMappingURL=chunk-QCWLMMDI.js.map
3864
+ //# sourceMappingURL=chunk-ICLWBMH4.js.map
3865
+ //# sourceMappingURL=chunk-ICLWBMH4.js.map