use-mask-input 3.4.2 → 3.5.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.
- package/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +77 -1
- package/dist/index.cjs +3892 -3786
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +593 -0
- package/dist/index.d.ts +14 -30
- package/dist/index.js +3892 -3786
- package/dist/index.js.map +1 -1
- package/package.json +32 -38
- package/src/index.tsx +7 -4
- package/src/inputmask.types.ts +16 -9
- package/src/types.ts +19 -3
- package/src/useHookFormMask.ts +16 -8
- package/src/useMaskInput.ts +18 -9
- package/src/utils/flow.spec.ts +8 -7
- package/src/utils/flow.ts +8 -4
- package/src/utils/getMaskOptions.spec.ts +3 -2
- package/src/utils/getMaskOptions.ts +3 -3
- package/src/utils/index.ts +3 -3
- package/src/utils/isServer.ts +4 -3
- package/src/utils/moduleInterop.ts +13 -0
- package/src/withHookFormMask.ts +11 -6
- package/src/withMask.ts +20 -11
package/package.json
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-mask-input",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"description": "A react Hook for build elegant input masks. Compatible with React Hook Form",
|
|
5
5
|
"author": "Eduardo Borges<euduardoborges@gmail.com>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"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",
|
|
12
8
|
"exports": {
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
16
14
|
},
|
|
17
15
|
"engines": {
|
|
18
16
|
"node": ">=16",
|
|
@@ -32,44 +30,40 @@
|
|
|
32
30
|
"CHANGELOG.md"
|
|
33
31
|
],
|
|
34
32
|
"peerDependencies": {
|
|
35
|
-
"react": ">=
|
|
36
|
-
"react-dom": ">=
|
|
33
|
+
"react": ">=17",
|
|
34
|
+
"react-dom": ">=17"
|
|
37
35
|
},
|
|
38
36
|
"devDependencies": {
|
|
39
|
-
"
|
|
40
|
-
"@
|
|
41
|
-
"@rollup/plugin-node-resolve": "15.3.0",
|
|
37
|
+
"@eslint/compat": "^1.3.2",
|
|
38
|
+
"@eslint/js": "^9.35.0",
|
|
42
39
|
"@semantic-release/changelog": "6.0.3",
|
|
43
|
-
"@semantic-release/commit-analyzer": "13.0.
|
|
40
|
+
"@semantic-release/commit-analyzer": "13.0.1",
|
|
44
41
|
"@semantic-release/git": "10.0.1",
|
|
45
|
-
"@semantic-release/github": "11.0.
|
|
46
|
-
"@semantic-release/npm": "12.0.
|
|
47
|
-
"@semantic-release/release-notes-generator": "14.0.
|
|
42
|
+
"@semantic-release/github": "11.0.5",
|
|
43
|
+
"@semantic-release/npm": "12.0.2",
|
|
44
|
+
"@semantic-release/release-notes-generator": "14.0.3",
|
|
45
|
+
"@stylistic/eslint-plugin": "3.1.0",
|
|
48
46
|
"@types/inputmask": "5.0.7",
|
|
49
47
|
"@types/node": "22",
|
|
50
|
-
"@types/react": ">=
|
|
51
|
-
"@types/react-dom": ">=
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"eslint": "
|
|
57
|
-
"eslint-
|
|
58
|
-
"eslint-
|
|
59
|
-
"eslint-plugin-
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"eslint-plugin-react-hooks": "4.6.0",
|
|
63
|
-
"patch-package": "^8.0.0",
|
|
64
|
-
"react-hook-form": "7.53.2",
|
|
48
|
+
"@types/react": ">=17",
|
|
49
|
+
"@types/react-dom": ">=17",
|
|
50
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
51
|
+
"eslint": "^9.35.0",
|
|
52
|
+
"eslint-config-airbnb-extended": "^2.2.0",
|
|
53
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
54
|
+
"eslint-plugin-import-x": "^4.16.1",
|
|
55
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
56
|
+
"eslint-plugin-react": "^7.37.5",
|
|
57
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
58
|
+
"inputmask": "5.0.10-beta.52",
|
|
59
|
+
"react-hook-form": "7.62.0",
|
|
65
60
|
"read-pkg": "9.0.1",
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"semantic-release": "24.2.0",
|
|
70
|
-
"simple-git-hooks": "2.11.1",
|
|
61
|
+
"semantic-release": "24.2.7",
|
|
62
|
+
"simple-git-hooks": "2.13.1",
|
|
63
|
+
"tsup": "8.5.0",
|
|
71
64
|
"typescript": "5.1",
|
|
72
|
-
"
|
|
65
|
+
"typescript-eslint": "^8.42.0",
|
|
66
|
+
"vitest": "3.2.4"
|
|
73
67
|
},
|
|
74
68
|
"simple-git-hooks": {
|
|
75
69
|
"pre-commit": "npm run lint && npm run test && npm run build"
|
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export { default as withHookFormMask } from './withHookFormMask';
|
|
2
|
+
export { default as withMask } from './withMask';
|
|
3
|
+
export { default as useHookFormMask } from './useHookFormMask';
|
|
4
|
+
export { default as useMaskInput } from './useMaskInput';
|
|
5
|
+
export type {
|
|
6
|
+
Mask, Options, UseFormRegister, UseFormRegisterReturn,
|
|
7
|
+
} from './types';
|
package/src/inputmask.types.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
|
|
1
|
+
/* eslint-disable @stylistic/max-len */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
type Range = { start: string; end: string } | [string, string];
|
|
4
4
|
|
|
5
5
|
type PositionCaretOnClick = 'none' | 'lvp' | 'radixFocus' | 'select' | 'ignore';
|
|
6
6
|
|
|
7
|
-
type InputMode = 'verbatim'
|
|
7
|
+
type InputMode = 'verbatim'
|
|
8
|
+
| 'none'
|
|
9
|
+
| 'text'
|
|
10
|
+
| 'decimal'
|
|
11
|
+
| 'numeric'
|
|
12
|
+
| 'tel'
|
|
13
|
+
| 'search'
|
|
14
|
+
| 'email'
|
|
15
|
+
| 'url';
|
|
8
16
|
|
|
9
17
|
type Casing = 'upper' | 'lower' | 'title';
|
|
10
18
|
|
|
@@ -19,8 +27,9 @@ type DefinitionValidator = (
|
|
|
19
27
|
|
|
20
28
|
export interface Options {
|
|
21
29
|
/**
|
|
22
|
-
* Change the mask placeholder. Instead of "_", you can change the unfilled
|
|
23
|
-
*
|
|
30
|
+
* Change the mask placeholder. Instead of "_", you can change the unfilled
|
|
31
|
+
* characters mask as you like, simply by adding the placeholder option.
|
|
32
|
+
* For example, placeholder: " " will change the default autofill with empty
|
|
24
33
|
* values.
|
|
25
34
|
*
|
|
26
35
|
* @default "_"
|
|
@@ -479,7 +488,7 @@ export interface Options {
|
|
|
479
488
|
*
|
|
480
489
|
* @default {k: "000", m: "000000"}
|
|
481
490
|
*/
|
|
482
|
-
shortcuts?:
|
|
491
|
+
shortcuts?: Record<string, string> | null | undefined;
|
|
483
492
|
/**
|
|
484
493
|
* Format used to input a date. This option is only effective for the datetime alias.
|
|
485
494
|
*
|
|
@@ -533,9 +542,7 @@ export interface Options {
|
|
|
533
542
|
* Add new definitions to this inputmask.
|
|
534
543
|
*/
|
|
535
544
|
definitions?:
|
|
536
|
-
|
|
|
537
|
-
[key: string]: Definition;
|
|
538
|
-
}
|
|
545
|
+
| Record<string, Definition>
|
|
539
546
|
| undefined;
|
|
540
547
|
/**
|
|
541
548
|
* Enable/disable prefilling of the year.
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
import { Options as MaskOptions } from './inputmask.types';
|
|
1
|
+
import type { Options as MaskOptions } from './inputmask.types';
|
|
2
2
|
|
|
3
3
|
export type { UseFormRegister, UseFormRegisterReturn } from 'react-hook-form';
|
|
4
4
|
|
|
5
|
-
export type Mask = 'datetime'
|
|
5
|
+
export type Mask = 'datetime'
|
|
6
|
+
| 'email'
|
|
7
|
+
| 'numeric'
|
|
8
|
+
| 'currency'
|
|
9
|
+
| 'decimal'
|
|
10
|
+
| 'integer'
|
|
11
|
+
| 'percentage'
|
|
12
|
+
| 'url'
|
|
13
|
+
| 'ip'
|
|
14
|
+
| 'mac'
|
|
15
|
+
| 'ssn'
|
|
16
|
+
| 'brl-currency'
|
|
17
|
+
| 'cpf'
|
|
18
|
+
| 'cnpj'
|
|
19
|
+
| (string & {})
|
|
20
|
+
| (string[] & {})
|
|
21
|
+
| null;
|
|
6
22
|
export type Options = MaskOptions;
|
|
7
|
-
export type Input = HTMLInputElement | HTMLTextAreaElement | HTMLElement |
|
|
23
|
+
export type Input = HTMLInputElement | HTMLTextAreaElement | HTMLElement | null;
|
package/src/useHookFormMask.ts
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/* eslint-disable import-x/no-extraneous-dependencies */
|
|
1
3
|
import inputmask from 'inputmask';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
+
|
|
5
|
+
import { flow, getMaskOptions } from './utils';
|
|
6
|
+
import interopDefaultSync from './utils/moduleInterop';
|
|
7
|
+
|
|
8
|
+
import type { RefCallback } from 'react';
|
|
9
|
+
import type {
|
|
4
10
|
FieldValues, Path,
|
|
5
11
|
RegisterOptions,
|
|
6
12
|
UseFormRegister,
|
|
13
|
+
UseFormRegisterReturn,
|
|
7
14
|
} from 'react-hook-form';
|
|
8
|
-
import { Mask, Options } from './types';
|
|
9
|
-
import { flow, getMaskOptions } from './utils';
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
import type { Mask, Options } from './types';
|
|
17
|
+
|
|
18
|
+
export default function useHookFormMask<
|
|
12
19
|
T extends FieldValues, D extends RegisterOptions,
|
|
13
20
|
>(registerFn: UseFormRegister<T>) {
|
|
14
|
-
return (fieldName: Path<T>, mask: Mask, options?: (
|
|
21
|
+
return (fieldName: Path<T>, mask: Mask, options?: (
|
|
22
|
+
D & Options) | Options | D): UseFormRegisterReturn<Path<T>> => {
|
|
15
23
|
if (!registerFn) throw new Error('registerFn is required');
|
|
16
24
|
|
|
17
25
|
const { ref, ...restRegister } = registerFn(fieldName, options as any);
|
|
18
26
|
|
|
19
|
-
const maskInput = inputmask(getMaskOptions(mask, options as any));
|
|
27
|
+
const maskInput = interopDefaultSync(inputmask)(getMaskOptions(mask, options as any));
|
|
20
28
|
|
|
21
29
|
const newRef = flow((_ref: HTMLElement) => {
|
|
22
30
|
if (_ref) {
|
|
@@ -33,7 +41,7 @@ export function useHookFormMask<
|
|
|
33
41
|
|
|
34
42
|
return {
|
|
35
43
|
...restRegister,
|
|
36
|
-
ref: newRef
|
|
44
|
+
ref: newRef,
|
|
37
45
|
};
|
|
38
46
|
};
|
|
39
47
|
}
|
package/src/useMaskInput.ts
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
|
+
/* eslint-disable import-x/no-extraneous-dependencies */
|
|
1
2
|
import { useEffect, useRef } from 'react';
|
|
3
|
+
|
|
2
4
|
import inputmask from 'inputmask';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
+
|
|
6
|
+
import { getMaskOptions } from './utils';
|
|
7
|
+
import isServer from './utils/isServer';
|
|
8
|
+
import interopDefaultSync from './utils/moduleInterop';
|
|
9
|
+
|
|
10
|
+
import type { RefObject } from 'react';
|
|
11
|
+
|
|
12
|
+
import type { Mask, Options } from './types';
|
|
5
13
|
|
|
6
14
|
interface UseInputMaskOptions {
|
|
7
|
-
mask: Mask
|
|
8
|
-
register
|
|
9
|
-
options?: Options
|
|
15
|
+
mask: Mask;
|
|
16
|
+
register?: (element: HTMLElement) => void;
|
|
17
|
+
options?: Options;
|
|
10
18
|
}
|
|
11
19
|
|
|
12
|
-
export
|
|
20
|
+
export default function useInputMask(props: UseInputMaskOptions): RefObject<HTMLInputElement> {
|
|
13
21
|
const { mask, register, options } = props;
|
|
14
22
|
const ref = useRef<HTMLInputElement>(null);
|
|
15
23
|
if (isServer) return ref;
|
|
16
24
|
|
|
25
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
17
26
|
useEffect(() => {
|
|
18
|
-
if (!isServer) {
|
|
27
|
+
if (!isServer && ref.current) {
|
|
19
28
|
if (!ref.current) return;
|
|
20
29
|
|
|
21
|
-
const maskInput = inputmask(getMaskOptions(mask, options));
|
|
30
|
+
const maskInput = interopDefaultSync(inputmask)(getMaskOptions(mask, options));
|
|
22
31
|
|
|
23
32
|
maskInput.mask(ref.current);
|
|
24
33
|
|
|
@@ -29,4 +38,4 @@ export const useInputMask = (props: UseInputMaskOptions) => {
|
|
|
29
38
|
}, [mask, register, options]);
|
|
30
39
|
|
|
31
40
|
return ref;
|
|
32
|
-
}
|
|
41
|
+
}
|
package/src/utils/flow.spec.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
|
|
1
2
|
import {
|
|
2
|
-
describe,
|
|
3
|
+
describe, expect, it,
|
|
3
4
|
} from 'vitest';
|
|
4
5
|
|
|
5
|
-
import
|
|
6
|
+
import flow from './flow';
|
|
6
7
|
|
|
7
8
|
describe('flow', () => {
|
|
8
9
|
it('returns a function', () => {
|
|
@@ -16,9 +17,9 @@ describe('flow', () => {
|
|
|
16
17
|
});
|
|
17
18
|
|
|
18
19
|
it('throws an error if any argument is not a function', () => {
|
|
19
|
-
// @ts-
|
|
20
|
+
// @ts-expect-error - null is not a function
|
|
20
21
|
expect(() => flow(null)).toThrow(TypeError);
|
|
21
|
-
// @ts-
|
|
22
|
+
// @ts-expect-error - null is not a function
|
|
22
23
|
expect(() => flow(() => {}, null)).toThrow(TypeError);
|
|
23
24
|
});
|
|
24
25
|
|
|
@@ -29,10 +30,10 @@ describe('flow', () => {
|
|
|
29
30
|
|
|
30
31
|
it.todo('binds the functions to the correct context', () => {
|
|
31
32
|
const context = { value: 42 };
|
|
32
|
-
const fn1 = function (this:
|
|
33
|
+
const fn1 = function (this: { value: number }) {
|
|
33
34
|
return this.value;
|
|
34
35
|
};
|
|
35
|
-
const fn2 = function (this:
|
|
36
|
+
const fn2 = function (this: { value: number }, n: number) {
|
|
36
37
|
return this.value + n;
|
|
37
38
|
};
|
|
38
39
|
const fn = flow(fn1, fn2).bind(context);
|
|
@@ -47,7 +48,7 @@ describe('flow', () => {
|
|
|
47
48
|
|
|
48
49
|
it('should throw an error if any argument is not a function', () => {
|
|
49
50
|
expect(() => {
|
|
50
|
-
flow(1 as
|
|
51
|
+
flow(1 as unknown as Function, () => {});
|
|
51
52
|
}).toThrow(TypeError);
|
|
52
53
|
});
|
|
53
54
|
|
package/src/utils/flow.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
3
|
+
export default function flow(...funcs: Function[]): Function {
|
|
2
4
|
const { length } = funcs;
|
|
3
5
|
let index = length;
|
|
4
|
-
while (index
|
|
6
|
+
while (index > 0) {
|
|
7
|
+
index -= 1;
|
|
5
8
|
if (typeof funcs[index] !== 'function') {
|
|
6
9
|
throw new TypeError('Expected a function');
|
|
7
10
|
}
|
|
8
11
|
}
|
|
9
|
-
return (...args:
|
|
12
|
+
return (...args: Function[]) => {
|
|
10
13
|
let i = 0;
|
|
11
14
|
let result = length ? funcs[i].apply(this, args) : args[0];
|
|
12
|
-
while (
|
|
15
|
+
while (i + 1 < length) {
|
|
16
|
+
i += 1;
|
|
13
17
|
result = funcs[i].call(this, result);
|
|
14
18
|
}
|
|
15
19
|
return result;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { describe,
|
|
2
|
-
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import getMaskOptions from './getMaskOptions';
|
|
3
4
|
|
|
4
5
|
describe('getMaskOptions', () => {
|
|
5
6
|
it('returns default options when no mask is provided', () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Mask, Options } from '../types';
|
|
1
|
+
import type { Mask, Options } from '../types';
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export default function getMaskOptions(mask?: Mask, _options?: Options): Options {
|
|
4
4
|
const options: Options = {
|
|
5
5
|
jitMasking: false,
|
|
6
6
|
..._options,
|
|
@@ -91,4 +91,4 @@ export const getMaskOptions = (mask?: Mask, _options?: Options): Options => {
|
|
|
91
91
|
mask,
|
|
92
92
|
...options,
|
|
93
93
|
};
|
|
94
|
-
}
|
|
94
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { default as flow } from './flow';
|
|
2
|
+
export { default as isServer } from './isServer';
|
|
3
|
+
export { default as getMaskOptions } from './getMaskOptions';
|
package/src/utils/isServer.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/**
|
|
3
|
+
* Synchronously resolve the default value of a module.
|
|
4
|
+
*/
|
|
5
|
+
export default function interopDefaultSync<T = any>(module: T): T {
|
|
6
|
+
if (typeof module === 'object' && module !== null) {
|
|
7
|
+
if ('default' in module) {
|
|
8
|
+
return module.default as T;
|
|
9
|
+
}
|
|
10
|
+
return module;
|
|
11
|
+
}
|
|
12
|
+
return module;
|
|
13
|
+
}
|
package/src/withHookFormMask.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
+
/* eslint-disable import-x/no-extraneous-dependencies */
|
|
1
2
|
import inputmask from 'inputmask';
|
|
2
|
-
|
|
3
|
+
|
|
3
4
|
import { flow, getMaskOptions } from './utils';
|
|
4
|
-
import
|
|
5
|
+
import interopDefaultSync from './utils/moduleInterop';
|
|
6
|
+
|
|
7
|
+
import type { RefCallback } from 'react';
|
|
8
|
+
|
|
9
|
+
import type { Mask, Options, UseFormRegisterReturn } from './types';
|
|
5
10
|
|
|
6
|
-
export
|
|
11
|
+
export default function withHookFormMask(
|
|
7
12
|
register: UseFormRegisterReturn,
|
|
8
13
|
mask: Mask,
|
|
9
14
|
options?: Options,
|
|
10
|
-
): UseFormRegisterReturn
|
|
15
|
+
): UseFormRegisterReturn {
|
|
11
16
|
//
|
|
12
17
|
let newRef;
|
|
13
18
|
|
|
14
19
|
if (register) {
|
|
15
20
|
const { ref } = register;
|
|
16
21
|
|
|
17
|
-
const maskInput = inputmask(getMaskOptions(mask, options));
|
|
22
|
+
const maskInput = interopDefaultSync(inputmask)(getMaskOptions(mask, options));
|
|
18
23
|
|
|
19
24
|
newRef = flow((_ref: HTMLElement) => {
|
|
20
25
|
if (_ref) maskInput.mask(_ref);
|
|
@@ -26,4 +31,4 @@ export const withHookFormMask = (
|
|
|
26
31
|
...register,
|
|
27
32
|
ref: newRef as RefCallback<HTMLElement>,
|
|
28
33
|
};
|
|
29
|
-
}
|
|
34
|
+
}
|
package/src/withMask.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import { Input, Mask, Options } from './types';
|
|
1
|
+
/* eslint-disable import-x/no-extraneous-dependencies */
|
|
2
|
+
import inputmask from 'inputmask';
|
|
4
3
|
|
|
5
|
-
|
|
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): Input => {
|
|
6
12
|
//
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
if (isServer) return input;
|
|
14
|
+
if (mask === null) return input;
|
|
15
|
+
|
|
16
|
+
const maskInput = interopDefaultSync(inputmask)(getMaskOptions(mask, options));
|
|
9
17
|
|
|
10
|
-
|
|
18
|
+
if (input) {
|
|
19
|
+
maskInput.mask(input);
|
|
20
|
+
}
|
|
11
21
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
22
|
+
return input;
|
|
23
|
+
};
|
|
24
|
+
}
|