Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

validator-brazil

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validator-brazil - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

22

package.json
{
"name": "validator-brazil",
"version": "1.1.0",
"version": "1.2.0",
"description": "validacao de cpf e cnpj",
"main": "lib/index.js",
"main": "src/index.js",
"types": "src/index.d.ts",
"scripts": {
"test": "jest",
"build": "webpack --config webpack.config.js",
"prepublish": "npm run build"
"test": "jest"
},

@@ -19,2 +17,3 @@ "repository": {

"cnpj",
"cep",
"validacao",

@@ -31,11 +30,6 @@ "brazil",

"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"babel-loader": "^8.0.4",
"jest": "^23.6.0",
"path": "^0.12.7",
"webpack": "^4.28.2",
"webpack-cli": "^3.1.2"
"jest": "^23.6.0"
},

@@ -51,2 +45,2 @@ "jest": {

}
}
}

@@ -29,7 +29,7 @@ # validator-brazil

// No points or hyphens
console.log(isCpf("29018170097")); // false
console.log(isCpf("12312345600")); // false
isCpf("29018170097"); // false
isCpf("12312345600"); // false
// With points or hyphens
console.log(isCpf("123.123.456-00")); // false
isCpf("123.123.456-00"); // false
```

@@ -43,7 +43,7 @@

// No points or hyphens
console.log(isCnpj("54334068000136")); // true
console.log(isCnpj("00111222000100")); // false
isCnpj("54334068000136"); // true
isCnpj("00111222000100"); // false
// With points or hyphens
console.log(isCnpj("54.334.068/0001-36")); // true
isCnpj("54.334.068/0001-36"); // true
```

@@ -57,7 +57,7 @@

// No points or hyphens
console.log(isCep("43710130")); // true
console.log(isCep("5471013423")); // false
isCep("43710130"); // true
isCep("5471013423"); // false
// With points or hyphens
console.log(isCep("43710-130")); // true
isCep("43710-130"); // true
```

@@ -71,10 +71,10 @@

// No points or hyphens
console.log(validator.isCnpj("54334068000136")); // true
console.log(validator.isCnpj("00111222000100")); // false
console.log(validator.isCpf("29018170097")); // true
console.log(validator.isCpf("12312345600")); // false
validator.isCnpj("54334068000136"); // true
validator.isCnpj("00111222000100"); // false
validator.isCpf("29018170097"); // true
validator.isCpf("12312345600"); // false
// With points or hyphens
console.log(validator.isCnpj("54.334.068/0001-36")); // true
console.log(validator.isCpf("123.123.456-00")); // false
validator.isCnpj("54.334.068/0001-36"); // true
validator.isCpf("123.123.456-00"); // false
```

@@ -1,4 +0,4 @@

const regex = /[\.\-\/]+/g;
var regex = /[\.\-\/]+/g;
export const isCnpj = cnpj => {
module.exports.isCnpj = function(cnpj) {
cnpj = cnpj.replace(regex, "");

@@ -24,12 +24,12 @@

let size = cnpj.length - 2;
let numbers = cnpj.substring(0, size);
const digits = cnpj.substring(size);
let sum = 0;
let pos = size - 7;
for (let i = size; i >= 1; i--) {
var size = cnpj.length - 2;
var numbers = cnpj.substring(0, size);
var digits = cnpj.substring(size);
var sum = 0;
var pos = size - 7;
for (var i = size; i >= 1; i--) {
sum += numbers.charAt(size - i) * pos--;
if (pos < 2) pos = 9;
}
let result = sum % 11 < 2 ? 0 : 11 - (sum % 11);
var result = sum % 11 < 2 ? 0 : 11 - (sum % 11);
if (result != digits.charAt(0)) return false;

@@ -41,3 +41,3 @@

pos = size - 7;
for (let i = size; i >= 1; i--) {
for (var i = size; i >= 1; i--) {
sum += numbers.charAt(size - i) * pos--;

@@ -52,3 +52,3 @@ if (pos < 2) pos = 9;

export const isCpf = cpf => {
module.exports.isCpf = function(cpf) {
cpf = cpf.replace(regex, "");

@@ -73,5 +73,5 @@

let add = 0;
for (let i = 0; i < 9; i++) add += parseInt(cpf.charAt(i)) * (10 - i);
let rev = 11 - (add % 11);
var add = 0;
for (var i = 0; i < 9; i++) add += parseInt(cpf.charAt(i)) * (10 - i);
var rev = 11 - (add % 11);
if (rev == 10 || rev == 11) rev = 0;

@@ -82,3 +82,3 @@ if (rev != parseInt(cpf.charAt(9))) return false;

for (let i = 0; i < 10; i++) add += parseInt(cpf.charAt(i)) * (11 - i);
for (var i = 0; i < 10; i++) add += parseInt(cpf.charAt(i)) * (11 - i);
rev = 11 - (add % 11);

@@ -90,6 +90,6 @@ if (rev == 10 || rev == 11) rev = 0;

export const isCep = cep => {
module.exports.isCep = function(cep) {
cep = cep.replace(regex, "");
const cepRegex = /^[0-9]{8}$/g;
var cepRegex = /^[1-9]{1}[0-9]{7}$/g;
return cepRegex.test(cep);
}
};
import { isCep } from "../index";
describe("cep validation", () => {
it("should return true to valid cep", () => {
expect(isCep("54710130")).toEqual(true);
});
it("should return true to valid cep without hyphen", () => {
expect(isCep("14710130")).toEqual(true);
});
it("should return false to invalid cep", () => {
expect(isCep("5471012023")).toEqual(false);
});
it("should return false to invalid cep with 0 in the initial", () => {
expect(isCep("04710130")).toEqual(false);
});
it("should return true to valid cep with hyphen", () => {
expect(isCep("54710-130")).toEqual(true);
});
it("should return false to invalid cep", () => {
expect(isCep("5471012023")).toEqual(false);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc