-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from GainTime/v4
V4.1
- Loading branch information
Showing
45 changed files
with
2,564 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
src/ | ||
node_modules/ | ||
.prettierrc | ||
tsconfig.json | ||
webpack.config.js | ||
.gitignore | ||
index.html | ||
*.map | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
src/ | ||
node_modules/ | ||
.prettierrc | ||
tsconfig.json | ||
webpack.config.js | ||
.gitignore | ||
index.html | ||
*.map | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"semi": false, | ||
"arrowParens": "always", | ||
"singleQuote": true, | ||
"trailingComma": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,63 @@ | ||
## Como começar | ||
|
||
- Importe o nosso JavaScript. | ||
```js | ||
<script type="text/javascript" src="br-validator/dist/gaintime.br-validator.min.js"></script> | ||
### ESM | ||
|
||
``` | ||
npm install br-validator | ||
``` | ||
- Adicione o atributo data-validate aos inputs que deseja validar, tal que o valor do atributo pode ser cpf, cnpj, date, brPhone, cep, text ou num. | ||
|
||
```js | ||
<input type="text" data-validate="cpf"> | ||
import Br from 'br-validator' | ||
|
||
// options é opcional, se vc não passar nada, será: | ||
const options = { | ||
css: true // Utilizar nosso stylesheet, | ||
messages: true // Utilizar nossas mensagens de erro | ||
} | ||
|
||
const br = new Br(options) | ||
const BR = br.init() | ||
``` | ||
|
||
### text/javascript | ||
|
||
``` | ||
npm install [email protected] | ||
``` | ||
|
||
Será criada uma variável global chamada `br` | ||
|
||
```html | ||
<script type="text/javascript" src="br-validator/dist/index.js"></script> | ||
<script> | ||
br.init() // Configuração padrão | ||
// ou | ||
new br.Br(options).init() // Assim você pode personalizar | ||
</script> | ||
``` | ||
|
||
## Como utilizar | ||
|
||
Adicione o atributo data-validate aos inputs que deseja validar, tal que o valor do atributo pode ser cpf, cnpj, date, brPhone, cep, text ou num. | ||
|
||
```html | ||
<input type="text" data-validate="cpf" /> | ||
``` | ||
|
||
Para validar ceps, utilizamos um formato diferente: | ||
|
||
```html | ||
<script> | ||
const BR = br.init() | ||
BR.fields.cep.forEach((e) => { | ||
e.addEventListener('blur', function (f) { | ||
console.log(f) | ||
br.cep(f.target, (response) => { | ||
console.log(response) | ||
}) | ||
}) | ||
}) | ||
</script> | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var cpf_1 = require("./modules/cpf"); | ||
var phone_1 = require("./modules/phone"); | ||
var cnpj_1 = require("./modules/cnpj"); | ||
var cep_1 = require("./modules/cep"); | ||
var date_1 = require("./modules/date"); | ||
exports.default = { | ||
cpf: cpf_1.default, | ||
phone: phone_1.default, | ||
cnpj: cnpj_1.default, | ||
cep: cep_1.default, | ||
date: date_1.default | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function cep(raw) { | ||
var cleaned = ('' + raw).replace(/\D/g, ''); | ||
var match = cleaned.match(/^(\d{1,5})?[- ]??[\s]?(\d{1,3})?(.*)?$/); | ||
for (var i = 1; i <= 2; i++) { | ||
if (!match[i]) { | ||
match[i] = ''; | ||
} | ||
} | ||
if (!match[1] || cleaned.length < 5) { | ||
return raw; | ||
} | ||
else { | ||
return match[1] + "-" + match[2]; | ||
} | ||
} | ||
exports.default = cep; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function cnpj(raw) { | ||
var cleaned = ('' + raw).replace(/\D/g, ''); | ||
var regex = /^(\d{1,2})?[- ]??[\s]?(\d{1,3})?[\s]?(\d{1,3})?(\d{1,4})?(\d{1,2})?(.*)?$/; | ||
var match = cleaned.match(regex); | ||
for (var i = 1; i <= 5; i++) { | ||
if (!match[i]) { | ||
match[i] = ''; | ||
} | ||
} | ||
if (!match[1] || cleaned.length < 3) { | ||
return raw; | ||
} | ||
else if (match[1] && !match[2]) { | ||
return match[1] + "."; | ||
} | ||
else if (match[2] && !match[3]) { | ||
return match[1] + "." + match[2] + (cleaned.length < 5 ? '' : '.'); | ||
} | ||
else if (match[3] && !match[4]) { | ||
return match[1] + "." + match[2] + "." + match[3] + (cleaned.length < 8 ? '' : '/'); | ||
} | ||
else if (match[4] && !match[5]) { | ||
return match[1] + "." + match[2] + "." + match[3] + "/" + match[4] + (cleaned.length < 12 ? '' : '-'); | ||
} | ||
else { | ||
return match[1] + "." + match[2] + "." + match[3] + "/" + match[4] + match[5]; | ||
} | ||
} | ||
exports.default = cnpj; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function cpf(raw) { | ||
var cleaned = ('' + raw).replace(/\D/g, ''); | ||
var regex = /^(\d{1,3})?[- ]??[\s]?(\d{1,3})?[\s]?(\d{1,3})?(.*)?$/; | ||
var match = cleaned.match(regex); | ||
for (var i = 1; i <= 4; i++) { | ||
if (!match[i]) | ||
match[i] = ''; | ||
} | ||
if (!match[1] || cleaned.length < 3) { | ||
return raw; | ||
} | ||
else if (match[1] && !match[2]) { | ||
return match[1] + "."; | ||
} | ||
else if (match[2] && !match[3]) { | ||
return match[1] + "." + match[2] + (cleaned.length < 6 ? '' : '.'); | ||
} | ||
else if (match[3] && !match[4]) { | ||
return match[1] + "." + match[2] + "." + match[3] + (cleaned.length < 9 ? '' : '-'); | ||
} | ||
else { | ||
return match[1] + "." + match[2] + "." + match[3] + "-" + match[4]; | ||
} | ||
} | ||
exports.default = cpf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function date(raw) { | ||
var cleaned = ('' + raw).replace(/\D/g, ''); | ||
var match = cleaned.match(/^(\d{1,2})?[- ]??[\s]?(\d{1,2})?(.*)?$/); | ||
for (var i = 1; i <= 3; i++) { | ||
if (!match[i]) { | ||
match[i] = ''; | ||
} | ||
} | ||
if (!match[1] || cleaned.length < 2) { | ||
return raw; | ||
} | ||
else if (match[1] && !match[2]) { | ||
return match[1] + "/"; | ||
} | ||
else if (match[2] && !match[3]) { | ||
return match[1] + "/" + match[2] + (cleaned.length < 4 ? '' : '/'); | ||
} | ||
else if (match[3]) { | ||
return match[1] + "/" + match[2] + "/" + match[3]; | ||
} | ||
} | ||
exports.default = date; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function phone(raw) { | ||
var cleaned = ('' + raw).replace(/\D/g, ''); | ||
var match = []; | ||
if (cleaned.length <= 10) { | ||
match = cleaned.match(/^(\d{1,2})?[- ]?(\d{1,4})?(\d{1,4})?(.*)?$/); | ||
} | ||
else { | ||
match = cleaned.match(/^(\d{1,2})?[- ]?(\d{1,5})?(\d{1,4})?(.*)?$/); | ||
} | ||
for (var i = 1; i <= 3; i++) { | ||
if (!match[i]) { | ||
match[i] = ''; | ||
} | ||
} | ||
if (!match[1] || cleaned.length < 2) { | ||
return raw; | ||
} | ||
else if (match[1] && !match[2]) { | ||
return "(" + match[1] + ") "; | ||
} | ||
else if (match[2] && !match[3]) { | ||
return "(" + match[1] + ") " + match[2] + (cleaned.length < 6 ? '' : '-'); | ||
} | ||
else if (match[3]) { | ||
return "(" + match[1] + ") " + match[2] + "-" + match[3]; | ||
} | ||
} | ||
exports.default = phone; |
Oops, something went wrong.