-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4702bf6
commit 812158c
Showing
11 changed files
with
95 additions
and
21 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
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,4 +1,3 @@ | ||
declare const _default: { | ||
isCPF: (value: string | number) => boolean; | ||
}; | ||
export default _default; | ||
import isCPF from './isCPF'; | ||
import isCNPJ from './isCNPJ'; | ||
export { isCPF, isCNPJ }; |
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
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 @@ | ||
declare const isCNPJ: (value: string | number) => boolean; | ||
export default isCNPJ; |
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,47 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const isCNPJ = (value) => { | ||
value = ('' + value).replace(/[\.\-\/]+/g, ""); | ||
if (value == "") | ||
return false; | ||
if (value.length != 14) | ||
return false; | ||
if (value == "00000000000000" || | ||
value == "11111111111111" || | ||
value == "22222222222222" || | ||
value == "33333333333333" || | ||
value == "44444444444444" || | ||
value == "55555555555555" || | ||
value == "66666666666666" || | ||
value == "77777777777777" || | ||
value == "88888888888888" || | ||
value == "99999999999999") | ||
return false; | ||
var size = value.length - 2; | ||
var numbers = value.substring(0, size); | ||
var digits = value.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; | ||
} | ||
var result = sum % 11 < 2 ? 0 : 11 - (sum % 11); | ||
if (result !== +digits.charAt(0)) | ||
return false; | ||
size = size + 1; | ||
numbers = value.substring(0, size); | ||
sum = 0; | ||
pos = size - 7; | ||
for (var i = size; i >= 1; i--) { | ||
sum += +numbers.charAt(size - i) * pos--; | ||
if (pos < 2) | ||
pos = 9; | ||
} | ||
result = sum % 11 < 2 ? 0 : 11 - (sum % 11); | ||
if (result != +digits.charAt(1)) | ||
return false; | ||
return true; | ||
}; | ||
exports.default = isCNPJ; |
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
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
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,5 +1,7 @@ | ||
import isCPF from './isCPF'; | ||
import isCNPJ from './isCNPJ'; | ||
|
||
export default { | ||
isCPF | ||
export { | ||
isCPF, | ||
isCNPJ | ||
} |
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,23 @@ | ||
import { isCNPJ } from './index'; | ||
|
||
describe("cnpj validation", () => { | ||
it("should return true to valid cnpj without hyphen and points", () => { | ||
expect(isCNPJ("00933180000164")).toBeTruthy(); | ||
}); | ||
|
||
it("should return true to valid cnpj with hyphen and points", () => { | ||
expect(isCNPJ("00.933.180/0001-64")).toBeTruthy(); | ||
}); | ||
|
||
it("should return false with letters", () => { | ||
expect(isCNPJ("00933180000164a")).toBeFalsy(); | ||
}); | ||
|
||
it("should return false to invalid cnpj with hyphen and points", () => { | ||
expect(isCNPJ("001112220000133")).toBeFalsy(); | ||
}); | ||
|
||
it("should return false to invalid cnpj", () => { | ||
expect(isCNPJ("00000000000000")).toBeFalsy(); | ||
}); | ||
}); |
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
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