PageSourceSearch

https://www.portalmaioresemelhores.com.br/public/assets/js/core/cpf-mask.js?v=1.0.0-1790903893

js portalmaioresemelhores.com.br collected 2026-10-02 01:18:29 UTC 1,500 bytes, 49 lines download raw bytes

1/**
2 * CPF Mask Utility
3 * 
4 * Aplica máscara de CPF 000.000.000-00
5 * dinamicamente baseado na quantidade de dígitos.
6 */
7const CpfMask = {
8    /**
9     * Aplica a máscara a um elemento de input
10     * @param {HTMLInputElement} input 
11     */
12    apply(input) {
13        if (!input) return;
14
15        input.addEventListener('input', (e) => {
16            let value = e.target.value.replace(/\D/g, '');
17            if (value.length > 11) value = value.slice(0, 11);
18
19            if (value.length > 9) {
20                value = value.replace(/^(\d{3})(\d{3})(\d{3})(\d{0,2}).*/, '$1.$2.$3-$4');
21            } else if (value.length > 6) {
22                value = value.replace(/^(\d{3})(\d{3})(\d{0,3}).*/, '$1.$2.$3');
23            } else if (value.length > 3) {
24                value = value.replace(/^(\d{3})(\d{0,3}).*/, '$1.$2');
25            }
26
27            e.target.value = value;
28        });
29
30        // Disparar uma vez para formatar valor inicial se houver
31        if (input.value) {
32            input.dispatchEvent(new Event('input'));
33        }
34    },
35
36    /**
37     * Inicializa máscara em todos os elementos que combinam com o seletor
38     * @param {string} selector 
39     */
40    init(selector = '.cpf-mask, #cpf, input[name="cpf"]') {
41        document.querySelectorAll(selector).forEach(input => this.apply(input));
42    }
43};
44
45// Exportar globalmente
46window.CpfMask = CpfMask;
47
48// Auto-init se houver elementos na página
49document.addEventListener('DOMContentLoaded', () => CpfMask.init());

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.