use-mask-input 3.1.0 → 3.1.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.
- package/README.md +13 -19
- package/dist/index.cjs +20 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -15
- package/dist/index.js +20 -7
- package/dist/index.js.map +1 -1
- package/package.json +17 -16
- package/src/utils.spec.ts +10 -9
- package/src/utils.ts +17 -21
- package/src/withHookFormMask.ts +7 -8
- package/src/withMask.ts +2 -2
package/README.md
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
# use-mask-input
|
|
1
|
+
# 🥸 use-mask-input
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/use-mask-input) [](https://www.npmjs.com/package/use-mask-input) [](https://bundlephobia.com/result?p=use-mask-input)
|
|
4
4
|
|
|
5
5
|
A React Hook for build elegant and simple input masks.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- [x] Add react-final-form support
|
|
9
|
-
- [x] Simplify API
|
|
10
|
-
- [ ] Make tests :P
|
|
11
|
-
- [ ] Better example page with GH pages
|
|
12
|
-
|
|
7
|
+
---
|
|
13
8
|
|
|
14
9
|
## Features
|
|
15
|
-
|
|
10
|
+
- 🎯 Simple API
|
|
16
11
|
- ✨ Compatible with [React Hook Form](https://github.com/react-hook-form/react-hook-form)
|
|
17
12
|
- 🏁 Compatible with [React Final Form](https://github.com/final-form/react-final-form)
|
|
18
|
-
|
|
13
|
+
|
|
14
|
+
## Know Issues
|
|
15
|
+
|
|
16
|
+
- Not compatible with Next.js, but we are working on it
|
|
19
17
|
|
|
20
18
|
## Install
|
|
21
19
|
|
|
22
|
-
```
|
|
23
|
-
npm
|
|
24
|
-
## or
|
|
25
|
-
yarn add use-mask-input
|
|
20
|
+
```sh
|
|
21
|
+
npm i use-mask-input
|
|
26
22
|
```
|
|
27
23
|
|
|
28
24
|
## Quickstart
|
|
@@ -64,10 +60,12 @@ function App() {
|
|
|
64
60
|
|
|
65
61
|
## Usage with React Final Form
|
|
66
62
|
|
|
63
|
+
Just use `withMask` normaly.
|
|
64
|
+
|
|
67
65
|
```jsx
|
|
68
66
|
import React from 'react';
|
|
69
67
|
import { Form, Field } from 'react-final-form';
|
|
70
|
-
import {
|
|
68
|
+
import { withMask } from 'use-mask-input';
|
|
71
69
|
|
|
72
70
|
function App() {
|
|
73
71
|
...
|
|
@@ -89,7 +87,3 @@ function App() {
|
|
|
89
87
|
);
|
|
90
88
|
}
|
|
91
89
|
```
|
|
92
|
-
|
|
93
|
-
## License
|
|
94
|
-
|
|
95
|
-
MIT © [eduardoborges](https://github.com/eduardoborges)
|
package/dist/index.cjs
CHANGED
|
@@ -6,9 +6,23 @@ var react = require('react');
|
|
|
6
6
|
var Inputmask = require('inputmask');
|
|
7
7
|
|
|
8
8
|
const isServer = !(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
9
|
+
function flow(...funcs) {
|
|
10
|
+
const { length } = funcs;
|
|
11
|
+
let index = length;
|
|
12
|
+
while(index--){
|
|
13
|
+
if (typeof funcs[index] !== 'function') {
|
|
14
|
+
throw new TypeError('Expected a function');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return (...args)=>{
|
|
18
|
+
let i = 0;
|
|
19
|
+
let result = length ? funcs[i].apply(this, args) : args[0];
|
|
20
|
+
while(++i < length){
|
|
21
|
+
result = funcs[i].call(this, result);
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
12
26
|
|
|
13
27
|
function _define_property$2(obj, key, value) {
|
|
14
28
|
if (key in obj) {
|
|
@@ -119,10 +133,9 @@ const withHookFormMask = (register, mask, options)=>{
|
|
|
119
133
|
if (register) {
|
|
120
134
|
const { ref } = register;
|
|
121
135
|
const maskInput = Inputmask(_object_spread$1({
|
|
122
|
-
mask
|
|
123
|
-
jitMasking: true
|
|
136
|
+
mask: mask || undefined
|
|
124
137
|
}, options));
|
|
125
|
-
newRef =
|
|
138
|
+
newRef = flow((_ref)=>{
|
|
126
139
|
if (_ref) maskInput.mask(_ref);
|
|
127
140
|
return _ref;
|
|
128
141
|
}, ref);
|
|
@@ -164,7 +177,7 @@ const withMask = (mask, options)=>(input)=>{
|
|
|
164
177
|
//
|
|
165
178
|
if (isServer) return input;
|
|
166
179
|
const maskInput = Inputmask(_object_spread({
|
|
167
|
-
mask
|
|
180
|
+
mask: mask || undefined
|
|
168
181
|
}, options));
|
|
169
182
|
if (input) {
|
|
170
183
|
maskInput.mask(input);
|
package/dist/index.cjs.map
CHANGED
|
@@ -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
|
|
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,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AChB;QAED,OAAOA,KAAAA,CAAAA;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import Inputmask$1 from 'inputmask';
|
|
3
|
-
import * as react_hook_form from 'react-hook-form';
|
|
4
3
|
import { UseFormRegisterReturn } from 'react-hook-form';
|
|
5
4
|
|
|
6
5
|
interface UseInputMaskOptions {
|
|
@@ -15,20 +14,8 @@ type Mask = Inputmask.Options['mask'];
|
|
|
15
14
|
type Options = Inputmask.Options;
|
|
16
15
|
type Input = HTMLInputElement | HTMLTextAreaElement | HTMLElement | HTMLInputElement | null;
|
|
17
16
|
|
|
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
|
-
};
|
|
17
|
+
declare const withHookFormMask: (register: Register, mask: Mask, options?: Options) => Register;
|
|
31
18
|
|
|
32
|
-
declare const withMask: (mask
|
|
19
|
+
declare const withMask: (mask?: Mask, options?: Options) => (input: Input) => Input;
|
|
33
20
|
|
|
34
21
|
export { useInputMask as default, withHookFormMask, withMask };
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,23 @@ import { useRef, useEffect } from 'react';
|
|
|
2
2
|
import Inputmask from 'inputmask';
|
|
3
3
|
|
|
4
4
|
const isServer = !(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
5
|
+
function flow(...funcs) {
|
|
6
|
+
const { length } = funcs;
|
|
7
|
+
let index = length;
|
|
8
|
+
while(index--){
|
|
9
|
+
if (typeof funcs[index] !== 'function') {
|
|
10
|
+
throw new TypeError('Expected a function');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return (...args)=>{
|
|
14
|
+
let i = 0;
|
|
15
|
+
let result = length ? funcs[i].apply(this, args) : args[0];
|
|
16
|
+
while(++i < length){
|
|
17
|
+
result = funcs[i].call(this, result);
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
8
22
|
|
|
9
23
|
function _define_property$2(obj, key, value) {
|
|
10
24
|
if (key in obj) {
|
|
@@ -115,10 +129,9 @@ const withHookFormMask = (register, mask, options)=>{
|
|
|
115
129
|
if (register) {
|
|
116
130
|
const { ref } = register;
|
|
117
131
|
const maskInput = Inputmask(_object_spread$1({
|
|
118
|
-
mask
|
|
119
|
-
jitMasking: true
|
|
132
|
+
mask: mask || undefined
|
|
120
133
|
}, options));
|
|
121
|
-
newRef =
|
|
134
|
+
newRef = flow((_ref)=>{
|
|
122
135
|
if (_ref) maskInput.mask(_ref);
|
|
123
136
|
return _ref;
|
|
124
137
|
}, ref);
|
|
@@ -160,7 +173,7 @@ const withMask = (mask, options)=>(input)=>{
|
|
|
160
173
|
//
|
|
161
174
|
if (isServer) return input;
|
|
162
175
|
const maskInput = Inputmask(_object_spread({
|
|
163
|
-
mask
|
|
176
|
+
mask: mask || undefined
|
|
164
177
|
}, options));
|
|
165
178
|
if (input) {
|
|
166
179
|
maskInput.mask(input);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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 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,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACZMG,MAAAA,YAAAA,GAAe,CAACC,KAA+B,GAAA;AACnD,IAAA,MAAM,EAAEC,IAAI,GAAEC,WAAUC,OAAAA,GAAS,GAAGH,KA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A,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;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-mask-input",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "A react Hook for build elegant input masks. Compatible with React Hook Form",
|
|
5
5
|
"author": "eduardoborges",
|
|
6
|
-
"license": "MIT",
|
|
7
6
|
"repository": "https://github.com/eduardoborges/use-mask-input",
|
|
8
|
-
"source": "src/index.tsx",
|
|
9
|
-
"main": "dist/index.js",
|
|
10
|
-
"module": "dist/index.js",
|
|
11
|
-
"types": "dist/index.d.ts",
|
|
7
|
+
"source": "./src/index.tsx",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
12
11
|
"exports": {
|
|
13
12
|
"import": "./dist/index.js",
|
|
14
13
|
"require": "./dist/index.cjs",
|
|
15
14
|
"types": "./dist/index.d.ts"
|
|
16
15
|
},
|
|
17
16
|
"engines": {
|
|
18
|
-
"node": ">=
|
|
17
|
+
"node": ">=16",
|
|
19
18
|
"npm": ">=7"
|
|
20
19
|
},
|
|
21
20
|
"scripts": {
|
|
22
|
-
"build": "./
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
21
|
+
"build": "./sh build",
|
|
22
|
+
"dev": "./sh dev",
|
|
23
|
+
"lint": "./sh lint",
|
|
24
|
+
"test": "./sh test",
|
|
25
|
+
"prepare": "./sh prepare",
|
|
26
|
+
"example": "./sh example"
|
|
26
27
|
},
|
|
27
28
|
"files": [
|
|
28
29
|
"dist",
|
|
29
30
|
"src"
|
|
30
31
|
],
|
|
31
32
|
"dependencies": {
|
|
32
|
-
"inputmask": "5.0.8"
|
|
33
|
-
"react-hook-form": "^7"
|
|
33
|
+
"inputmask": "5.0.8"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"react": ">=16.4 ||
|
|
37
|
-
"react-dom": ">=16.4 ||
|
|
36
|
+
"react": ">=16.4 || 17 || 18",
|
|
37
|
+
"react-dom": ">=16.4 || 17 || 18"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@semantic-release/changelog": "6.0.3",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@semantic-release/npm": "10.0.3",
|
|
45
45
|
"@semantic-release/release-notes-generator": "11.0.1",
|
|
46
46
|
"@types/inputmask": "^5.0.3",
|
|
47
|
-
"@types/node": "
|
|
47
|
+
"@types/node": "16",
|
|
48
48
|
"@types/react": ">=16.4 || ^17.0.0 || ^18.0.0",
|
|
49
49
|
"@types/react-dom": ">=16.4 || ^17.0.0 || ^18.0.0",
|
|
50
50
|
"@typescript-eslint/eslint-plugin": "5.59.2",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"eslint-plugin-jsx-a11y": "6.7.1",
|
|
57
57
|
"eslint-plugin-react": "7.32.2",
|
|
58
58
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
59
|
+
"react-hook-form": "^7",
|
|
59
60
|
"read-pkg": "^8.0.0",
|
|
60
61
|
"rollup": "^3.21.4",
|
|
61
62
|
"rollup-plugin-dts": "^5.3.0",
|
package/src/utils.spec.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
1
|
import { describe } from 'vitest';
|
|
3
|
-
import { compose } from './utils';
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
import { flow } from './utils';
|
|
4
|
+
|
|
5
|
+
describe('utils', (it) => {
|
|
6
|
+
it('flow', ({ expect }) => {
|
|
7
|
+
const res = flow(
|
|
8
|
+
(a: number) => a + 1,
|
|
9
|
+
(a:number) => a + 2,
|
|
10
|
+
)(1);
|
|
11
|
+
|
|
12
|
+
expect(res).toBe(4);
|
|
12
13
|
});
|
|
13
14
|
});
|
package/src/utils.ts
CHANGED
|
@@ -4,24 +4,20 @@ export const isServer = !(
|
|
|
4
4
|
&& window.document.createElement
|
|
5
5
|
);
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return (...args:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
(x: number) => x + 1,
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
console.log(sum(1));
|
|
7
|
+
export function flow(...funcs: Array<Function>) : Function {
|
|
8
|
+
const { length } = funcs;
|
|
9
|
+
let index = length;
|
|
10
|
+
while (index--) {
|
|
11
|
+
if (typeof funcs[index] !== 'function') {
|
|
12
|
+
throw new TypeError('Expected a function');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return (...args: Array<Function>) => {
|
|
16
|
+
let i = 0;
|
|
17
|
+
let result = length ? funcs[i].apply(this, args) : args[0];
|
|
18
|
+
while (++i < length) {
|
|
19
|
+
result = funcs[i].call(this, result);
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
}
|
package/src/withHookFormMask.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Inputmask from 'inputmask';
|
|
2
|
-
|
|
3
|
-
import {
|
|
2
|
+
import { RefCallback } from 'react';
|
|
3
|
+
import { flow } from './utils';
|
|
4
4
|
import { Mask, Options, Register } from './types';
|
|
5
5
|
|
|
6
|
-
export const withHookFormMask = (register: Register, mask: Mask, options?: Options) => {
|
|
6
|
+
export const withHookFormMask = (register: Register, mask: Mask, options?: Options): Register => {
|
|
7
7
|
//
|
|
8
8
|
let newRef;
|
|
9
9
|
|
|
@@ -11,19 +11,18 @@ export const withHookFormMask = (register: Register, mask: Mask, options?: Optio
|
|
|
11
11
|
const { ref } = register;
|
|
12
12
|
|
|
13
13
|
const maskInput = Inputmask({
|
|
14
|
-
mask,
|
|
15
|
-
jitMasking: true,
|
|
14
|
+
mask: mask || undefined,
|
|
16
15
|
...options,
|
|
17
16
|
});
|
|
18
17
|
|
|
19
|
-
newRef =
|
|
18
|
+
newRef = flow((_ref: HTMLElement) => {
|
|
20
19
|
if (_ref) maskInput.mask(_ref);
|
|
21
20
|
return _ref;
|
|
22
|
-
}, ref)
|
|
21
|
+
}, ref) as RefCallback<HTMLElement>;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
return {
|
|
26
25
|
...register,
|
|
27
|
-
ref: newRef
|
|
26
|
+
ref: newRef as RefCallback<HTMLElement>,
|
|
28
27
|
};
|
|
29
28
|
};
|
package/src/withMask.ts
CHANGED
|
@@ -2,12 +2,12 @@ import Inputmask from 'inputmask';
|
|
|
2
2
|
import { isServer } from './utils';
|
|
3
3
|
import { Input, Mask, Options } from './types';
|
|
4
4
|
|
|
5
|
-
export const withMask = (mask
|
|
5
|
+
export const withMask = (mask?: Mask, options?: Options) => (input: Input) => {
|
|
6
6
|
//
|
|
7
7
|
if (isServer) return input;
|
|
8
8
|
|
|
9
9
|
const maskInput = Inputmask({
|
|
10
|
-
mask,
|
|
10
|
+
mask: mask || undefined,
|
|
11
11
|
...options,
|
|
12
12
|
});
|
|
13
13
|
|