use-mask-input 3.4.1 → 4.0.0-alpha.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 (50) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/LICENSE +21 -0
  3. package/dist/chunk-GMVG3XRP.cjs +2 -0
  4. package/dist/chunk-GMVG3XRP.cjs.map +1 -0
  5. package/dist/chunk-IOJUFP7A.js +2 -0
  6. package/dist/chunk-IOJUFP7A.js.map +1 -0
  7. package/dist/index-BZ5hI6xD.d.cts +51 -0
  8. package/dist/index-BZ5hI6xD.d.ts +51 -0
  9. package/dist/index.cjs +2 -3941
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +1 -0
  12. package/dist/index.d.ts +1 -609
  13. package/dist/index.js +2 -3936
  14. package/dist/index.js.map +1 -1
  15. package/dist/react.cjs +2 -0
  16. package/dist/react.cjs.map +1 -0
  17. package/dist/react.d.cts +6 -0
  18. package/dist/react.d.ts +6 -0
  19. package/dist/react.js +2 -0
  20. package/dist/react.js.map +1 -0
  21. package/package.json +50 -60
  22. package/src/api/mask.ts +39 -0
  23. package/src/api/withMask.ts +26 -0
  24. package/src/core/applyPattern.ts +61 -0
  25. package/src/core/createMask.ts +18 -0
  26. package/src/core/parsePattern.ts +81 -0
  27. package/src/effects/bindInput.ts +73 -0
  28. package/src/index.ts +9 -0
  29. package/src/presets/cnpj.ts +3 -0
  30. package/src/presets/cpf.ts +1 -0
  31. package/src/presets/cpfCnpj.ts +3 -0
  32. package/src/presets/currency.ts +0 -0
  33. package/src/presets/email.ts +0 -0
  34. package/src/presets/phone.ts +1 -0
  35. package/src/react.ts +2 -0
  36. package/src/types.ts +14 -5
  37. package/src/utils/decimal.ts +26 -0
  38. package/src/utils/isServer.ts +7 -5
  39. package/README.md +0 -232
  40. package/src/index.tsx +0 -4
  41. package/src/inputmask.types.ts +0 -607
  42. package/src/useHookFormMask.ts +0 -29
  43. package/src/useMaskInput.ts +0 -32
  44. package/src/utils/flow.spec.ts +0 -59
  45. package/src/utils/flow.ts +0 -17
  46. package/src/utils/getMaskOptions.spec.ts +0 -125
  47. package/src/utils/getMaskOptions.ts +0 -93
  48. package/src/utils/index.ts +0 -3
  49. package/src/withHookFormMask.ts +0 -29
  50. package/src/withMask.ts +0 -15
package/CHANGELOG.md CHANGED
@@ -1,3 +1,41 @@
1
+ # [4.0.0-alpha.1](https://github.com/eduardoborges/use-mask-input/compare/3.4.2...4.0.0-alpha.1) (2025-04-12)
2
+
3
+
4
+ ### Features
5
+
6
+ * full rewrite init ([5a88d22](https://github.com/eduardoborges/use-mask-input/commit/5a88d22f031f4107f1674e6ab39de9382ae393aa))
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ * entire API was rewritten – previous usage is no longer supported.
12
+
13
+ # [4.0.0-alpha.1](https://github.com/eduardoborges/use-mask-input/compare/3.4.2...4.0.0-alpha.1) (2025-04-12)
14
+
15
+
16
+ ### Features
17
+
18
+ * full rewrite init ([0e31ebc](https://github.com/eduardoborges/use-mask-input/commit/0e31ebc3943f1d022457096244be7e6fad685926))
19
+
20
+
21
+ ### BREAKING CHANGES
22
+
23
+ * entire API was rewritten – previous usage is no longer supported.
24
+
25
+ # [3.5.0-alpha.1](https://github.com/eduardoborges/use-mask-input/compare/3.4.2...3.5.0-alpha.1) (2025-04-12)
26
+
27
+
28
+ ### Features
29
+
30
+ * full rewrite init ([9c40e5f](https://github.com/eduardoborges/use-mask-input/commit/9c40e5fe71a2c2f6c5016f834505d35e4ffbe856))
31
+
32
+ ## [3.4.2](https://github.com/eduardoborges/use-mask-input/compare/3.4.1...3.4.2) (2024-11-22)
33
+
34
+
35
+ ### Bug Fixes
36
+
37
+ * mui textfield disappearing ([#95](https://github.com/eduardoborges/use-mask-input/issues/95)) ([fa0caf6](https://github.com/eduardoborges/use-mask-input/commit/fa0caf66fe05f33e5a5aeaf3e92b38352ca46abb))
38
+
1
39
  ## [3.4.1](https://github.com/eduardoborges/use-mask-input/compare/3.4.0...3.4.1) (2024-11-22)
2
40
 
3
41
 
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Eduardo Borges
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ 'use strict';function k(t,i){let s=t.replace(/\D/g,"").padStart(3,"0"),e=s.slice(0,-2),n=s.slice(-2),c=+`${e}.${n}`,a=i?.decimal?.symbol||"",o=i?.decimal?.thousandSeparator||"",r=i?.decimal?.decimalSeparator||".",p=c.toFixed(2).replace(".",r).replace(/\B(?=(\d{3})+(?!\d))/g,o);return a?`${a} ${p}`:p}function g(t){return t.includes("[DECIMAL]")}function h(t,i){let s=[],e=t.split(""),n=0;for(;n<e.length;){let c=e[n];if(g(t)){s.push({type:"currency"}),n+=8,n+=1;continue}if(c==="["){let o="";n+=1;let r=1;for(;n<e.length&&r>0;)e[n]==="["?r+=1:e[n]==="]"&&(r-=1),r>0&&(o+=e[n]),n+=1;s.push({type:"optional",tokens:h(o)});continue}let a=t.slice(n).match(/^(9|A|\*)\{(\d+)\}/);if(a){let o=a[1],r=parseInt(a[2],10),p;switch(o){case "9":p="digit";break;case "A":p="letter";break;default:p="wildcard";}for(let f=0;f<r;f+=1)s.push({type:p});n+=a[0].length;continue}c==="9"?s.push({type:"digit"}):c.toUpperCase()==="A"?s.push({type:"letter"}):c==="*"?s.push({type:"wildcard"}):c==="C"?s.push({type:"currency"}):s.push({type:"fixed",char:c}),n+=1;}return s}function M(t){return /\d/.test(t)}function I(t){return /[a-zA-Z]/.test(t)}function b(t){return /[a-zA-Z0-9]/.test(t)}function v(t,i,s){let e=t.replace(/[^a-zA-Z0-9]/g,"").split(""),n="",c=a=>{a.forEach(o=>{if(e.length!==0){if(o.type==="digit"){let r=e.findIndex(M);r!==-1&&(n+=e.splice(r,1)[0]);}else if(o.type==="letter"){let r=e.findIndex(I);r!==-1&&(n+=e.splice(r,1)[0]);}else if(o.type==="wildcard"){let r=e.findIndex(b);r!==-1&&(n+=e.splice(r,1)[0]);}else if(o.type==="fixed")n+=o.char;else if(o.type==="optional"){let r=n,p=[...e];c(o.tokens),n===r&&e.splice(0,e.length-p.length);}else if(o.type==="currency"){let r=e.join("");n+=k(r,s),e.length=0;}}});};return c(i),n}var y=new Map;function P(t,i,s){y.has(i)||y.set(i,h(i));let e=y.get(i);return v(t,e,s)}function d(t,i){return s=>{if(Array.isArray(t)){let e=s.replace(/\D/g,"").length,c=t.map(a=>({pattern:a,size:a.replace(/[^9A*]/g,"").length})).sort((a,o)=>a.size-o.size).find(a=>e<=a.size)?.pattern??t[t.length-1];return P(s,c,i)}return P(s,t,i)}}function w(t,i,s,e){if(!t)return;if(t.tagName!=="INPUT"&&t.tagName!=="TEXTAREA"){console.warn("bindInput only works with input and textarea elements");return}let n=()=>{let a=t.value,o=t.selectionStart??a.length,r=g(s),f=i((l=>r?l.replace(/[^0-9]/g,""):l)(a),e),m=r?f.length:(()=>{let l=o,x=0;for(let u=0;u<f.length&&x<o;u+=1)/\d|[a-zA-Z]/.test(f[u])&&(x+=1),l=u+1;return l})();t.value=f,t.setSelectionRange(m,m);},c=a=>{let o=a;if(o.key==="Backspace"){let r=t.selectionStart??0;if(r>0&&/\W/.test(t.value[r-1])){o.preventDefault();let p=t.value.split("");for(let l=r-1;l>=0;l-=1)if(/[a-zA-Z0-9]/.test(p[l])){p.splice(l,1);break}let f=i(p.join(""),e);t.value=f;let m=Math.max(r-1,0);t.setSelectionRange(m,m);}}};return t.addEventListener("input",n),t.addEventListener("keydown",c),()=>{t.removeEventListener("input",n),t.removeEventListener("keydown",c);}}function $(t,i){let s=d(t,i);return {format:s,bind:e=>{if(!e)throw new Error("Input is required");return w(e,s,t,i)}}}var F="999.999.999-99";var W=d(["999.999.999-99","99.999.999/9999-99"]);var V=d("99.999.999/9999-99");var _=["(99) 9999-9999","(99) 99999-9999"];exports.a=P;exports.b=d;exports.c=$;exports.d=F;exports.e=W;exports.f=V;exports.g=_;//# sourceMappingURL=chunk-GMVG3XRP.cjs.map
2
+ //# sourceMappingURL=chunk-GMVG3XRP.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/decimal.ts","../src/core/parsePattern.ts","../src/core/applyPattern.ts","../src/core/createMask.ts","../src/effects/bindInput.ts","../src/api/mask.ts","../src/presets/cpf.ts","../src/presets/cpfCnpj.ts","../src/presets/cnpj.ts","../src/presets/phone.ts"],"names":["formatDecimal","raw","options","digits","int","dec","value","symbol","thousandSeparator","decimalSeparator","formatted","isDecimalPattern","pattern","parsePattern","tokens","chars","i","char","inner","depth","repeatMatch","type","count","tokenType","j","isDigit","c","isLetter","isWildcard","applyTokens","result","apply","tks","token","index","before","prevChars","cache","applyPattern","createMask","best","p","b","bindInput","input","maskFn","handleInput","oldValue","cursorPos","isDecimal","masked","newCursor","newPos","rawIndex","handleKeydown","_e","e","pos","mask","formatter","CPF","cpfCnpjMask","cnpjMask","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uB,IAAAA,CAAAA,CAAWvB,CAAW,CAAA,oBAAoB,ECF1CwB,IAAAA,CAAAA,CAAW,CAAC,gBAAA,CAAkB,iBAAiB","file":"chunk-GMVG3XRP.cjs","sourcesContent":["import { Pattern, PatternOptions } from '../types';\n\nexport function formatDecimal(\n raw: string,\n options?: PatternOptions,\n): string {\n const digits = raw.replace(/\\D/g, '').padStart(3, '0');\n const int = digits.slice(0, -2);\n const dec = digits.slice(-2);\n const value = Number(`${int}.${dec}`);\n\n const symbol = options?.decimal?.symbol || '';\n const thousandSeparator = options?.decimal?.thousandSeparator || '';\n const decimalSeparator = options?.decimal?.decimalSeparator || '.';\n\n const formatted = value\n .toFixed(2)\n .replace('.', decimalSeparator)\n .replace(/\\B(?=(\\d{3})+(?!\\d))/g, thousandSeparator);\n\n return symbol ? `${symbol} ${formatted}` : formatted;\n}\n\nexport function isDecimalPattern(pattern: Pattern): boolean {\n return pattern.includes('[DECIMAL]');\n}\n","/* eslint-disable no-continue */\nimport { PatternOptions } from '../types';\nimport { isDecimalPattern } from '../utils/decimal';\n\nexport type MaskToken =\n | { type: 'digit' }\n | { type: 'letter' }\n | { type: 'wildcard' }\n | { type: 'currency' }\n | { type: 'fixed'; char: string }\n | { type: 'optional'; tokens: MaskToken[] };\n\nexport function parsePattern(pattern: string, options: PatternOptions): MaskToken[] {\n // presets\n\n const tokens: MaskToken[] = [];\n const chars = pattern.split('');\n let i = 0;\n\n while (i < chars.length) {\n const char = chars[i];\n\n if (isDecimalPattern(pattern)) {\n tokens.push({ type: 'currency' });\n i += 'currency'.length;\n i += 1;\n continue;\n }\n\n if (char === '[') {\n let inner = '';\n i += 1;\n let depth = 1;\n while (i < chars.length && depth > 0) {\n if (chars[i] === '[') depth += 1;\n else if (chars[i] === ']') depth -= 1;\n if (depth > 0) inner += chars[i];\n i += 1;\n }\n\n tokens.push({ type: 'optional', tokens: parsePattern(inner, options) });\n continue;\n }\n\n const repeatMatch = pattern.slice(i).match(/^(9|A|\\*)\\{(\\d+)\\}/);\n if (repeatMatch) {\n const type = repeatMatch[1];\n const count = parseInt(repeatMatch[2], 10);\n let tokenType: string;\n switch (type) {\n case '9':\n tokenType = 'digit';\n break;\n case 'A':\n tokenType = 'letter';\n break;\n default:\n tokenType = 'wildcard';\n }\n for (let j = 0; j < count; j += 1) tokens.push({ type: tokenType as any });\n i += repeatMatch[0].length;\n continue;\n }\n\n if (char === '9') {\n tokens.push({ type: 'digit' });\n } else if (char.toUpperCase() === 'A') {\n tokens.push({ type: 'letter' });\n } else if (char === '*') {\n tokens.push({ type: 'wildcard' });\n } else if (char === 'C') {\n tokens.push({ type: 'currency' });\n } else {\n tokens.push({ type: 'fixed', char });\n }\n\n i += 1;\n }\n\n return tokens;\n}\n","import { PatternOptions } from '../types';\nimport { formatDecimal } from '../utils/decimal';\nimport { parsePattern, MaskToken } from './parsePattern';\n\nfunction isDigit(c: string) {\n return /\\d/.test(c);\n}\n\nfunction isLetter(c: string) {\n return /[a-zA-Z]/.test(c);\n}\n\nfunction isWildcard(c: string) {\n return /[a-zA-Z0-9]/.test(c);\n}\n\nfunction applyTokens(value: string, tokens: MaskToken[], options: PatternOptions): string {\n const chars = value.replace(/[^a-zA-Z0-9]/g, '').split('');\n let result = '';\n\n const apply = (tks: MaskToken[]) => {\n tks.forEach((token) => {\n if (chars.length === 0) return;\n\n if (token.type === 'digit') {\n const index = chars.findIndex(isDigit);\n if (index !== -1) result += chars.splice(index, 1)[0];\n } else if (token.type === 'letter') {\n const index = chars.findIndex(isLetter);\n if (index !== -1) result += chars.splice(index, 1)[0];\n } else if (token.type === 'wildcard') {\n const index = chars.findIndex(isWildcard);\n if (index !== -1) result += chars.splice(index, 1)[0];\n } else if (token.type === 'fixed') {\n result += token.char;\n } else if (token.type === 'optional') {\n const before = result;\n const prevChars = [...chars];\n apply(token.tokens);\n if (result === before) chars.splice(0, chars.length - prevChars.length);\n } else if (token.type === 'currency') {\n const raw = chars.join('');\n result += formatDecimal(raw, options);\n chars.length = 0;\n }\n });\n };\n\n apply(tokens);\n return result;\n}\n\nconst cache = new Map<string, MaskToken[]>();\n\nexport function applyPattern(value: string, pattern: string, options: PatternOptions): string {\n if (!cache.has(pattern)) {\n cache.set(pattern, parsePattern(pattern, options));\n }\n const tokens = cache.get(pattern)!;\n return applyTokens(value, tokens, options);\n}\n","import { Pattern, PatternOptions } from '../types';\nimport { applyPattern } from './applyPattern';\n\nexport function createMask(pattern: Pattern | Pattern[], options?: PatternOptions) {\n return (value: string): string => {\n if (Array.isArray(pattern)) {\n const digits = value.replace(/\\D/g, '').length;\n const candidates = pattern\n .map((p) => ({ pattern: p, size: p.replace(/[^9A*]/g, '').length }))\n .sort((a, b) => a.size - b.size);\n\n const best = candidates.find((p) => digits <= p.size)?.pattern ?? pattern[pattern.length - 1];\n return applyPattern(value, best, options);\n }\n\n return applyPattern(value, pattern, options);\n };\n}\n","import { Input, Pattern, PatternOptions } from '../types';\nimport { isDecimalPattern } from '../utils/decimal';\n\nexport function bindInput(\n input: Input,\n maskFn: Function,\n pattern: Pattern,\n options?: PatternOptions,\n): (() => void) | undefined {\n if (!input) return;\n\n if (input.tagName !== 'INPUT' && input.tagName !== 'TEXTAREA') {\n console.warn('bindInput only works with input and textarea elements');\n return;\n }\n\n const handleInput = () => {\n const oldValue = input.value;\n const cursorPos = input.selectionStart ?? oldValue.length;\n const isDecimal = isDecimalPattern(pattern);\n\n const getDigits = (value: string) => {\n if (isDecimal) return value.replace(/[^0-9]/g, '');\n return value;\n };\n\n const masked = maskFn(getDigits(oldValue), options);\n\n const newCursor = isDecimal\n ? masked.length\n : (() => {\n let newPos = cursorPos;\n let rawIndex = 0;\n for (let i = 0; i < masked.length && rawIndex < cursorPos; i += 1) {\n if (/\\d|[a-zA-Z]/.test(masked[i])) rawIndex += 1;\n newPos = i + 1;\n }\n return newPos;\n })();\n\n input.value = masked;\n input.setSelectionRange(newCursor, newCursor);\n };\n\n const handleKeydown = (_e: Event) => {\n const e = _e as KeyboardEvent;\n if (e.key === 'Backspace') {\n const pos = input.selectionStart ?? 0;\n if (pos > 0 && /\\W/.test(input.value[pos - 1])) {\n e.preventDefault();\n const chars = input.value.split('');\n for (let i = pos - 1; i >= 0; i -= 1) {\n if (/[a-zA-Z0-9]/.test(chars[i])) {\n chars.splice(i, 1);\n break;\n }\n }\n const masked = maskFn(chars.join(''), options);\n input.value = masked;\n const newPos = Math.max(pos - 1, 0);\n input.setSelectionRange(newPos, newPos);\n }\n }\n };\n\n input.addEventListener('input', handleInput);\n input.addEventListener('keydown', handleKeydown);\n\n return () => {\n input.removeEventListener('input', handleInput);\n input.removeEventListener('keydown', handleKeydown);\n };\n}\n","import { createMask } from '../core/createMask';\nimport { bindInput } from '../effects/bindInput';\nimport { Input, Pattern, PatternOptions } from '../types';\n\n/**\n *\n * @param pattern - The pattern to be used for the mask. It can be a string or an array of strings.\n * @example\n * ```ts\n * import { mask } from 'use-mask-input';\n * const input = document.querySelector('input') as HTMLInputElement;\n * mask(['999.999.999-99', '99.999.999/9999-99']).bind(input);\n * ```\n * @returns An object with a `format` function and a `bind` function.\n * The `format` function can be used to format a value according to the mask, and\n * the `bind` function can be used to bind the mask to an input element.\n *\n * @example\n * ```ts\n * import { mask } from 'use-mask-input';\n * const input = document.querySelector('input') as HTMLInputElement;\n * const { format, bind } = mask(['999.999.999-99', '99.999.999/9999-99']);\n * bind(input);\n * const formattedValue = format('12345678900');\n * console.log(formattedValue); // 123.456.789-00\n * ```\n */\nexport function mask(pattern: Pattern, options?: PatternOptions) {\n const formatter = createMask(pattern, options);\n return {\n format: formatter,\n bind: (input: Input) => {\n if (!input) throw new Error('Input is required');\n return bindInput(input, formatter, pattern, options);\n },\n };\n}\n\nexport default mask;\n","export const CPF = '999.999.999-99';\n","import { createMask } from '../core/createMask';\n\nexport const cpfCnpjMask = createMask(['999.999.999-99', '99.999.999/9999-99']);\n","import { createMask } from '../core/createMask';\n\nexport const cnpjMask = createMask('99.999.999/9999-99');\n","export const BR_PHONE = ['(99) 9999-9999', '(99) 99999-9999'];\n"]}
@@ -0,0 +1,2 @@
1
+ function k(t,i){let s=t.replace(/\D/g,"").padStart(3,"0"),e=s.slice(0,-2),n=s.slice(-2),c=+`${e}.${n}`,a=i?.decimal?.symbol||"",o=i?.decimal?.thousandSeparator||"",r=i?.decimal?.decimalSeparator||".",p=c.toFixed(2).replace(".",r).replace(/\B(?=(\d{3})+(?!\d))/g,o);return a?`${a} ${p}`:p}function g(t){return t.includes("[DECIMAL]")}function h(t,i){let s=[],e=t.split(""),n=0;for(;n<e.length;){let c=e[n];if(g(t)){s.push({type:"currency"}),n+=8,n+=1;continue}if(c==="["){let o="";n+=1;let r=1;for(;n<e.length&&r>0;)e[n]==="["?r+=1:e[n]==="]"&&(r-=1),r>0&&(o+=e[n]),n+=1;s.push({type:"optional",tokens:h(o)});continue}let a=t.slice(n).match(/^(9|A|\*)\{(\d+)\}/);if(a){let o=a[1],r=parseInt(a[2],10),p;switch(o){case "9":p="digit";break;case "A":p="letter";break;default:p="wildcard";}for(let f=0;f<r;f+=1)s.push({type:p});n+=a[0].length;continue}c==="9"?s.push({type:"digit"}):c.toUpperCase()==="A"?s.push({type:"letter"}):c==="*"?s.push({type:"wildcard"}):c==="C"?s.push({type:"currency"}):s.push({type:"fixed",char:c}),n+=1;}return s}function M(t){return /\d/.test(t)}function I(t){return /[a-zA-Z]/.test(t)}function b(t){return /[a-zA-Z0-9]/.test(t)}function v(t,i,s){let e=t.replace(/[^a-zA-Z0-9]/g,"").split(""),n="",c=a=>{a.forEach(o=>{if(e.length!==0){if(o.type==="digit"){let r=e.findIndex(M);r!==-1&&(n+=e.splice(r,1)[0]);}else if(o.type==="letter"){let r=e.findIndex(I);r!==-1&&(n+=e.splice(r,1)[0]);}else if(o.type==="wildcard"){let r=e.findIndex(b);r!==-1&&(n+=e.splice(r,1)[0]);}else if(o.type==="fixed")n+=o.char;else if(o.type==="optional"){let r=n,p=[...e];c(o.tokens),n===r&&e.splice(0,e.length-p.length);}else if(o.type==="currency"){let r=e.join("");n+=k(r,s),e.length=0;}}});};return c(i),n}var y=new Map;function P(t,i,s){y.has(i)||y.set(i,h(i));let e=y.get(i);return v(t,e,s)}function d(t,i){return s=>{if(Array.isArray(t)){let e=s.replace(/\D/g,"").length,c=t.map(a=>({pattern:a,size:a.replace(/[^9A*]/g,"").length})).sort((a,o)=>a.size-o.size).find(a=>e<=a.size)?.pattern??t[t.length-1];return P(s,c,i)}return P(s,t,i)}}function w(t,i,s,e){if(!t)return;if(t.tagName!=="INPUT"&&t.tagName!=="TEXTAREA"){console.warn("bindInput only works with input and textarea elements");return}let n=()=>{let a=t.value,o=t.selectionStart??a.length,r=g(s),f=i((l=>r?l.replace(/[^0-9]/g,""):l)(a),e),m=r?f.length:(()=>{let l=o,x=0;for(let u=0;u<f.length&&x<o;u+=1)/\d|[a-zA-Z]/.test(f[u])&&(x+=1),l=u+1;return l})();t.value=f,t.setSelectionRange(m,m);},c=a=>{let o=a;if(o.key==="Backspace"){let r=t.selectionStart??0;if(r>0&&/\W/.test(t.value[r-1])){o.preventDefault();let p=t.value.split("");for(let l=r-1;l>=0;l-=1)if(/[a-zA-Z0-9]/.test(p[l])){p.splice(l,1);break}let f=i(p.join(""),e);t.value=f;let m=Math.max(r-1,0);t.setSelectionRange(m,m);}}};return t.addEventListener("input",n),t.addEventListener("keydown",c),()=>{t.removeEventListener("input",n),t.removeEventListener("keydown",c);}}function $(t,i){let s=d(t,i);return {format:s,bind:e=>{if(!e)throw new Error("Input is required");return w(e,s,t,i)}}}var F="999.999.999-99";var W=d(["999.999.999-99","99.999.999/9999-99"]);var V=d("99.999.999/9999-99");var _=["(99) 9999-9999","(99) 99999-9999"];export{P as a,d as b,$ as c,F as d,W as e,V as f,_ as g};//# sourceMappingURL=chunk-IOJUFP7A.js.map
2
+ //# sourceMappingURL=chunk-IOJUFP7A.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/decimal.ts","../src/core/parsePattern.ts","../src/core/applyPattern.ts","../src/core/createMask.ts","../src/effects/bindInput.ts","../src/api/mask.ts","../src/presets/cpf.ts","../src/presets/cpfCnpj.ts","../src/presets/cnpj.ts","../src/presets/phone.ts"],"names":["formatDecimal","raw","options","digits","int","dec","value","symbol","thousandSeparator","decimalSeparator","formatted","isDecimalPattern","pattern","parsePattern","tokens","chars","i","char","inner","depth","repeatMatch","type","count","tokenType","j","isDigit","c","isLetter","isWildcard","applyTokens","result","apply","tks","token","index","before","prevChars","cache","applyPattern","createMask","best","p","b","bindInput","input","maskFn","handleInput","oldValue","cursorPos","isDecimal","masked","newCursor","newPos","rawIndex","handleKeydown","_e","e","pos","mask","formatter","CPF","cpfCnpjMask","cnpjMask","BR_PHONE"],"mappings":"AAEO,SAASA,CAAAA,CACdC,EACAC,CACQ,CAAA,CACR,IAAMC,CAASF,CAAAA,CAAAA,CAAI,OAAQ,CAAA,KAAA,CAAO,EAAE,CAAA,CAAE,SAAS,CAAG,CAAA,GAAG,EAC/CG,CAAMD,CAAAA,CAAAA,CAAO,MAAM,CAAG,CAAA,EAAE,CACxBE,CAAAA,CAAAA,CAAMF,CAAO,CAAA,KAAA,CAAM,EAAE,CACrBG,CAAAA,CAAAA,CAAQ,CAAO,CAAGF,EAAAA,CAAG,IAAIC,CAAG,CAAA,CAAA,CAE5BE,CAASL,CAAAA,CAAAA,EAAS,OAAS,EAAA,MAAA,EAAU,GACrCM,CAAoBN,CAAAA,CAAAA,EAAS,OAAS,EAAA,iBAAA,EAAqB,EAC3DO,CAAAA,CAAAA,CAAmBP,GAAS,OAAS,EAAA,gBAAA,EAAoB,GAEzDQ,CAAAA,CAAAA,CAAYJ,CACf,CAAA,OAAA,CAAQ,CAAC,CACT,CAAA,OAAA,CAAQ,IAAKG,CAAgB,CAAA,CAC7B,QAAQ,uBAAyBD,CAAAA,CAAiB,CAErD,CAAA,OAAOD,CAAS,CAAA,CAAA,EAAGA,CAAM,CAAIG,CAAAA,EAAAA,CAAS,CAAKA,CAAAA,CAAAA,CAC7C,CA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V,CAAAA,CAAAA,CAA0B,CAC/D,IAAMyD,CAAAA,CAAYpB,EAAW3B,CAASV,CAAAA,CAAO,EAC7C,OAAO,CACL,MAAQyD,CAAAA,CAAAA,CACR,IAAOf,CAAAA,CAAAA,EAAiB,CACtB,GAAI,CAACA,CAAO,CAAA,MAAM,IAAI,KAAA,CAAM,mBAAmB,CAC/C,CAAA,OAAOD,CAAUC,CAAAA,CAAAA,CAAOe,CAAW/C,CAAAA,CAAAA,CAASV,CAAO,CACrD,CACF,CACF,CCpCO,IAAM0D,EAAM,iBCEZ,IAAMC,CAActB,CAAAA,CAAAA,CAAW,CAAC,gBAAA,CAAkB,oBAAoB,CAAC,ECAjEuB,IAAAA,CAAAA,CAAWvB,CAAW,CAAA,oBAAoB,ECF1CwB,IAAAA,CAAAA,CAAW,CAAC,gBAAA,CAAkB,iBAAiB","file":"chunk-IOJUFP7A.js","sourcesContent":["import { Pattern, PatternOptions } from '../types';\n\nexport function formatDecimal(\n raw: string,\n options?: PatternOptions,\n): string {\n const digits = raw.replace(/\\D/g, '').padStart(3, '0');\n const int = digits.slice(0, -2);\n const dec = digits.slice(-2);\n const value = Number(`${int}.${dec}`);\n\n const symbol = options?.decimal?.symbol || '';\n const thousandSeparator = options?.decimal?.thousandSeparator || '';\n const decimalSeparator = options?.decimal?.decimalSeparator || '.';\n\n const formatted = value\n .toFixed(2)\n .replace('.', decimalSeparator)\n .replace(/\\B(?=(\\d{3})+(?!\\d))/g, thousandSeparator);\n\n return symbol ? `${symbol} ${formatted}` : formatted;\n}\n\nexport function isDecimalPattern(pattern: Pattern): boolean {\n return pattern.includes('[DECIMAL]');\n}\n","/* eslint-disable no-continue */\nimport { PatternOptions } from '../types';\nimport { isDecimalPattern } from '../utils/decimal';\n\nexport type MaskToken =\n | { type: 'digit' }\n | { type: 'letter' }\n | { type: 'wildcard' }\n | { type: 'currency' }\n | { type: 'fixed'; char: string }\n | { type: 'optional'; tokens: MaskToken[] };\n\nexport function parsePattern(pattern: string, options: PatternOptions): MaskToken[] {\n // presets\n\n const tokens: MaskToken[] = [];\n const chars = pattern.split('');\n let i = 0;\n\n while (i < chars.length) {\n const char = chars[i];\n\n if (isDecimalPattern(pattern)) {\n tokens.push({ type: 'currency' });\n i += 'currency'.length;\n i += 1;\n continue;\n }\n\n if (char === '[') {\n let inner = '';\n i += 1;\n let depth = 1;\n while (i < chars.length && depth > 0) {\n if (chars[i] === '[') depth += 1;\n else if (chars[i] === ']') depth -= 1;\n if (depth > 0) inner += chars[i];\n i += 1;\n }\n\n tokens.push({ type: 'optional', tokens: parsePattern(inner, options) });\n continue;\n }\n\n const repeatMatch = pattern.slice(i).match(/^(9|A|\\*)\\{(\\d+)\\}/);\n if (repeatMatch) {\n const type = repeatMatch[1];\n const count = parseInt(repeatMatch[2], 10);\n let tokenType: string;\n switch (type) {\n case '9':\n tokenType = 'digit';\n break;\n case 'A':\n tokenType = 'letter';\n break;\n default:\n tokenType = 'wildcard';\n }\n for (let j = 0; j < count; j += 1) tokens.push({ type: tokenType as any });\n i += repeatMatch[0].length;\n continue;\n }\n\n if (char === '9') {\n tokens.push({ type: 'digit' });\n } else if (char.toUpperCase() === 'A') {\n tokens.push({ type: 'letter' });\n } else if (char === '*') {\n tokens.push({ type: 'wildcard' });\n } else if (char === 'C') {\n tokens.push({ type: 'currency' });\n } else {\n tokens.push({ type: 'fixed', char });\n }\n\n i += 1;\n }\n\n return tokens;\n}\n","import { PatternOptions } from '../types';\nimport { formatDecimal } from '../utils/decimal';\nimport { parsePattern, MaskToken } from './parsePattern';\n\nfunction isDigit(c: string) {\n return /\\d/.test(c);\n}\n\nfunction isLetter(c: string) {\n return /[a-zA-Z]/.test(c);\n}\n\nfunction isWildcard(c: string) {\n return /[a-zA-Z0-9]/.test(c);\n}\n\nfunction applyTokens(value: string, tokens: MaskToken[], options: PatternOptions): string {\n const chars = value.replace(/[^a-zA-Z0-9]/g, '').split('');\n let result = '';\n\n const apply = (tks: MaskToken[]) => {\n tks.forEach((token) => {\n if (chars.length === 0) return;\n\n if (token.type === 'digit') {\n const index = chars.findIndex(isDigit);\n if (index !== -1) result += chars.splice(index, 1)[0];\n } else if (token.type === 'letter') {\n const index = chars.findIndex(isLetter);\n if (index !== -1) result += chars.splice(index, 1)[0];\n } else if (token.type === 'wildcard') {\n const index = chars.findIndex(isWildcard);\n if (index !== -1) result += chars.splice(index, 1)[0];\n } else if (token.type === 'fixed') {\n result += token.char;\n } else if (token.type === 'optional') {\n const before = result;\n const prevChars = [...chars];\n apply(token.tokens);\n if (result === before) chars.splice(0, chars.length - prevChars.length);\n } else if (token.type === 'currency') {\n const raw = chars.join('');\n result += formatDecimal(raw, options);\n chars.length = 0;\n }\n });\n };\n\n apply(tokens);\n return result;\n}\n\nconst cache = new Map<string, MaskToken[]>();\n\nexport function applyPattern(value: string, pattern: string, options: PatternOptions): string {\n if (!cache.has(pattern)) {\n cache.set(pattern, parsePattern(pattern, options));\n }\n const tokens = cache.get(pattern)!;\n return applyTokens(value, tokens, options);\n}\n","import { Pattern, PatternOptions } from '../types';\nimport { applyPattern } from './applyPattern';\n\nexport function createMask(pattern: Pattern | Pattern[], options?: PatternOptions) {\n return (value: string): string => {\n if (Array.isArray(pattern)) {\n const digits = value.replace(/\\D/g, '').length;\n const candidates = pattern\n .map((p) => ({ pattern: p, size: p.replace(/[^9A*]/g, '').length }))\n .sort((a, b) => a.size - b.size);\n\n const best = candidates.find((p) => digits <= p.size)?.pattern ?? pattern[pattern.length - 1];\n return applyPattern(value, best, options);\n }\n\n return applyPattern(value, pattern, options);\n };\n}\n","import { Input, Pattern, PatternOptions } from '../types';\nimport { isDecimalPattern } from '../utils/decimal';\n\nexport function bindInput(\n input: Input,\n maskFn: Function,\n pattern: Pattern,\n options?: PatternOptions,\n): (() => void) | undefined {\n if (!input) return;\n\n if (input.tagName !== 'INPUT' && input.tagName !== 'TEXTAREA') {\n console.warn('bindInput only works with input and textarea elements');\n return;\n }\n\n const handleInput = () => {\n const oldValue = input.value;\n const cursorPos = input.selectionStart ?? oldValue.length;\n const isDecimal = isDecimalPattern(pattern);\n\n const getDigits = (value: string) => {\n if (isDecimal) return value.replace(/[^0-9]/g, '');\n return value;\n };\n\n const masked = maskFn(getDigits(oldValue), options);\n\n const newCursor = isDecimal\n ? masked.length\n : (() => {\n let newPos = cursorPos;\n let rawIndex = 0;\n for (let i = 0; i < masked.length && rawIndex < cursorPos; i += 1) {\n if (/\\d|[a-zA-Z]/.test(masked[i])) rawIndex += 1;\n newPos = i + 1;\n }\n return newPos;\n })();\n\n input.value = masked;\n input.setSelectionRange(newCursor, newCursor);\n };\n\n const handleKeydown = (_e: Event) => {\n const e = _e as KeyboardEvent;\n if (e.key === 'Backspace') {\n const pos = input.selectionStart ?? 0;\n if (pos > 0 && /\\W/.test(input.value[pos - 1])) {\n e.preventDefault();\n const chars = input.value.split('');\n for (let i = pos - 1; i >= 0; i -= 1) {\n if (/[a-zA-Z0-9]/.test(chars[i])) {\n chars.splice(i, 1);\n break;\n }\n }\n const masked = maskFn(chars.join(''), options);\n input.value = masked;\n const newPos = Math.max(pos - 1, 0);\n input.setSelectionRange(newPos, newPos);\n }\n }\n };\n\n input.addEventListener('input', handleInput);\n input.addEventListener('keydown', handleKeydown);\n\n return () => {\n input.removeEventListener('input', handleInput);\n input.removeEventListener('keydown', handleKeydown);\n };\n}\n","import { createMask } from '../core/createMask';\nimport { bindInput } from '../effects/bindInput';\nimport { Input, Pattern, PatternOptions } from '../types';\n\n/**\n *\n * @param pattern - The pattern to be used for the mask. It can be a string or an array of strings.\n * @example\n * ```ts\n * import { mask } from 'use-mask-input';\n * const input = document.querySelector('input') as HTMLInputElement;\n * mask(['999.999.999-99', '99.999.999/9999-99']).bind(input);\n * ```\n * @returns An object with a `format` function and a `bind` function.\n * The `format` function can be used to format a value according to the mask, and\n * the `bind` function can be used to bind the mask to an input element.\n *\n * @example\n * ```ts\n * import { mask } from 'use-mask-input';\n * const input = document.querySelector('input') as HTMLInputElement;\n * const { format, bind } = mask(['999.999.999-99', '99.999.999/9999-99']);\n * bind(input);\n * const formattedValue = format('12345678900');\n * console.log(formattedValue); // 123.456.789-00\n * ```\n */\nexport function mask(pattern: Pattern, options?: PatternOptions) {\n const formatter = createMask(pattern, options);\n return {\n format: formatter,\n bind: (input: Input) => {\n if (!input) throw new Error('Input is required');\n return bindInput(input, formatter, pattern, options);\n },\n };\n}\n\nexport default mask;\n","export const CPF = '999.999.999-99';\n","import { createMask } from '../core/createMask';\n\nexport const cpfCnpjMask = createMask(['999.999.999-99', '99.999.999/9999-99']);\n","import { createMask } from '../core/createMask';\n\nexport const cnpjMask = createMask('99.999.999/9999-99');\n","export const BR_PHONE = ['(99) 9999-9999', '(99) 99999-9999'];\n"]}
@@ -0,0 +1,51 @@
1
+ type Input = HTMLInputElement | HTMLTextAreaElement | HTMLInputElement | null;
2
+ type Pattern = string;
3
+ type PatternOptions = {
4
+ decimal: {
5
+ symbol?: string;
6
+ thousandSeparator?: string;
7
+ decimalSeparator?: string;
8
+ };
9
+ } | undefined;
10
+
11
+ declare function createMask(pattern: Pattern | Pattern[], options?: PatternOptions): (value: string) => string;
12
+
13
+ declare function applyPattern(value: string, pattern: string, options: PatternOptions): string;
14
+
15
+ /**
16
+ *
17
+ * @param pattern - The pattern to be used for the mask. It can be a string or an array of strings.
18
+ * @example
19
+ * ```ts
20
+ * import { mask } from 'use-mask-input';
21
+ * const input = document.querySelector('input') as HTMLInputElement;
22
+ * mask(['999.999.999-99', '99.999.999/9999-99']).bind(input);
23
+ * ```
24
+ * @returns An object with a `format` function and a `bind` function.
25
+ * The `format` function can be used to format a value according to the mask, and
26
+ * the `bind` function can be used to bind the mask to an input element.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { mask } from 'use-mask-input';
31
+ * const input = document.querySelector('input') as HTMLInputElement;
32
+ * const { format, bind } = mask(['999.999.999-99', '99.999.999/9999-99']);
33
+ * bind(input);
34
+ * const formattedValue = format('12345678900');
35
+ * console.log(formattedValue); // 123.456.789-00
36
+ * ```
37
+ */
38
+ declare function mask(pattern: Pattern, options?: PatternOptions): {
39
+ format: (value: string) => string;
40
+ bind: (input: Input) => (() => void) | undefined;
41
+ };
42
+
43
+ declare const CPF = "999.999.999-99";
44
+
45
+ declare const cpfCnpjMask: (value: string) => string;
46
+
47
+ declare const cnpjMask: (value: string) => string;
48
+
49
+ declare const BR_PHONE: string[];
50
+
51
+ export { BR_PHONE as B, CPF as C, type Input as I, type PatternOptions as P, applyPattern as a, cpfCnpjMask as b, createMask as c, cnpjMask as d, mask as m };
@@ -0,0 +1,51 @@
1
+ type Input = HTMLInputElement | HTMLTextAreaElement | HTMLInputElement | null;
2
+ type Pattern = string;
3
+ type PatternOptions = {
4
+ decimal: {
5
+ symbol?: string;
6
+ thousandSeparator?: string;
7
+ decimalSeparator?: string;
8
+ };
9
+ } | undefined;
10
+
11
+ declare function createMask(pattern: Pattern | Pattern[], options?: PatternOptions): (value: string) => string;
12
+
13
+ declare function applyPattern(value: string, pattern: string, options: PatternOptions): string;
14
+
15
+ /**
16
+ *
17
+ * @param pattern - The pattern to be used for the mask. It can be a string or an array of strings.
18
+ * @example
19
+ * ```ts
20
+ * import { mask } from 'use-mask-input';
21
+ * const input = document.querySelector('input') as HTMLInputElement;
22
+ * mask(['999.999.999-99', '99.999.999/9999-99']).bind(input);
23
+ * ```
24
+ * @returns An object with a `format` function and a `bind` function.
25
+ * The `format` function can be used to format a value according to the mask, and
26
+ * the `bind` function can be used to bind the mask to an input element.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { mask } from 'use-mask-input';
31
+ * const input = document.querySelector('input') as HTMLInputElement;
32
+ * const { format, bind } = mask(['999.999.999-99', '99.999.999/9999-99']);
33
+ * bind(input);
34
+ * const formattedValue = format('12345678900');
35
+ * console.log(formattedValue); // 123.456.789-00
36
+ * ```
37
+ */
38
+ declare function mask(pattern: Pattern, options?: PatternOptions): {
39
+ format: (value: string) => string;
40
+ bind: (input: Input) => (() => void) | undefined;
41
+ };
42
+
43
+ declare const CPF = "999.999.999-99";
44
+
45
+ declare const cpfCnpjMask: (value: string) => string;
46
+
47
+ declare const cnpjMask: (value: string) => string;
48
+
49
+ declare const BR_PHONE: string[];
50
+
51
+ export { BR_PHONE as B, CPF as C, type Input as I, type PatternOptions as P, applyPattern as a, cpfCnpjMask as b, createMask as c, cnpjMask as d, mask as m };