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.0.0 to 1.0.1

src/tests/cnpj.spec.js

2

lib/index.js

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

module.exports=function(t){var r={};function e(n){if(r[n])return r[n].exports;var u=r[n]={i:n,l:!1,exports:{}};return t[n].call(u.exports,u,u.exports,e),u.l=!0,u.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var u in t)e.d(n,u,function(r){return t[r]}.bind(null,u));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=0)}([function(t,r,e){"use strict";e.r(r),e.d(r,"isCnpj",function(){return n}),e.d(r,"isCpf",function(){return u});const n=t=>{if(""==(t=t.replace(/[^\d]+/g,"")))return!1;if(14!=t.length)return!1;if("00000000000000"==t||"11111111111111"==t||"22222222222222"==t||"33333333333333"==t||"44444444444444"==t||"55555555555555"==t||"66666666666666"==t||"77777777777777"==t||"88888888888888"==t||"99999999999999"==t)return!1;let r=t.length-2,e=t.substring(0,r);const n=t.substring(r);let u=0,o=r-7;for(let t=r;t>=1;t--)u+=e.charAt(r-t)*o--,o<2&&(o=9);let i=u%11<2?0:11-u%11;if(i!=n.charAt(0))return!1;r+=1,e=t.substring(0,r),u=0,o=r-7;for(let t=r;t>=1;t--)u+=e.charAt(r-t)*o--,o<2&&(o=9);return(i=u%11<2?0:11-u%11)==n.charAt(1)},u=t=>{if(""==(t=t.replace(/[^\d]+/g,"")))return!1;if(11!=t.length||"00000000000"==t||"11111111111"==t||"22222222222"==t||"33333333333"==t||"44444444444"==t||"55555555555"==t||"66666666666"==t||"77777777777"==t||"88888888888"==t||"99999999999"==t)return!1;let r=0;for(let e=0;e<9;e++)r+=parseInt(t.charAt(e))*(10-e);let e=11-r%11;if(10!=e&&11!=e||(e=0),e!=parseInt(t.charAt(9)))return!1;r=0;for(let e=0;e<10;e++)r+=parseInt(t.charAt(e))*(11-e);return 10!=(e=11-r%11)&&11!=e||(e=0),e==parseInt(t.charAt(10))}}]);
module.exports=function(r){var t={};function e(n){if(t[n])return t[n].exports;var u=t[n]={i:n,l:!1,exports:{}};return r[n].call(u.exports,u,u.exports,e),u.l=!0,u.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var u in r)e.d(n,u,function(t){return r[t]}.bind(null,u));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=0)}([function(r,t,e){"use strict";e.r(t),e.d(t,"isCnpj",function(){return u}),e.d(t,"isCpf",function(){return o});var n=/[\.\-\/]+/g,u=function(r){if(""==(r=r.replace(n,"")))return!1;if(14!=r.length)return!1;if("00000000000000"==r||"11111111111111"==r||"22222222222222"==r||"33333333333333"==r||"44444444444444"==r||"55555555555555"==r||"66666666666666"==r||"77777777777777"==r||"88888888888888"==r||"99999999999999"==r)return!1;for(var t=r.length-2,e=r.substring(0,t),u=r.substring(t),o=0,i=t-7,f=t;f>=1;f--)o+=e.charAt(t-f)*i--,i<2&&(i=9);var a=o%11<2?0:11-o%11;if(a!=u.charAt(0))return!1;t+=1,e=r.substring(0,t),o=0,i=t-7;for(var c=t;c>=1;c--)o+=e.charAt(t-c)*i--,i<2&&(i=9);return(a=o%11<2?0:11-o%11)==u.charAt(1)},o=function(r){if(""==(r=r.replace(n,"")))return!1;if(11!=r.length||"00000000000"==r||"11111111111"==r||"22222222222"==r||"33333333333"==r||"44444444444"==r||"55555555555"==r||"66666666666"==r||"77777777777"==r||"88888888888"==r||"99999999999"==r)return!1;for(var t=0,e=0;e<9;e++)t+=parseInt(r.charAt(e))*(10-e);var u=11-t%11;if(10!=u&&11!=u||(u=0),u!=parseInt(r.charAt(9)))return!1;t=0;for(var o=0;o<10;o++)t+=parseInt(r.charAt(o))*(11-o);return 10!=(u=11-t%11)&&11!=u||(u=0),u==parseInt(r.charAt(10))}}]);
{
"name": "validator-brazil",
"version": "1.0.0",
"version": "1.0.1",
"description": "validacao de cpf e cnpj",

@@ -8,3 +8,3 @@ "main": "lib/index.js",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jest",
"build": "webpack --config webpack.config.js",

@@ -32,7 +32,20 @@ "prepublish": "npm run build"

"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"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": {
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}"
],
"transform": {
"^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest"
}
}
}

@@ -26,4 +26,11 @@ # validator-brazil

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

@@ -36,4 +43,11 @@

console.log(validator.isCnpj("00111222000100"));
console.log(validator.isCpf("12312345600"));
// 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
// With points or hyphens
console.log(validator.isCnpj("54.334.068/0001-36")); // true
console.log(validator.isCpf("123.123.456-00")); // false
```

@@ -0,3 +1,5 @@

const regex = /[\.\-\/]+/g;
export const isCnpj = cnpj => {
cnpj = cnpj.replace(/[^\d]+/g, "");
cnpj = cnpj.replace(regex, "");

@@ -49,3 +51,4 @@ if (cnpj == "") return false;

export const isCpf = cpf => {
cpf = cpf.replace(/[^\d]+/g, "");
cpf = cpf.replace(regex, "");
if (cpf == "") return false;

@@ -52,0 +55,0 @@

Sorry, the diff of this file is not supported yet

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