-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cpf-cnpj): New mask for cpf/cnpj inputs
- Loading branch information
Showing
8 changed files
with
107 additions
and
7 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,11 @@ | ||
/*exported CPFCNPJ */ | ||
/*globals CPF, CNPJ*/ | ||
var CPFCNPJ = function(value) { | ||
if (!value || !value.length) { | ||
return value; | ||
} else if (value.length <= 11) { | ||
return CPF(value); | ||
} else { | ||
return CNPJ(value); | ||
} | ||
}; |
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,52 @@ | ||
var should = require('should'), | ||
BrM = require('../releases/br-masks.min'); | ||
|
||
describe('CPF/CNPJ', function(){ | ||
it('should maks 10157471000161 to 10.157.471/0001-61', function(done) { | ||
should(BrM.cpfCnpj('10157471000161')).be.eql('10.157.471/0001-61'); | ||
done(); | ||
}); | ||
it('should maks 54506158000167 to 54.506.158/0001-67', function(done) { | ||
should(BrM.cpfCnpj('54506158000167')).be.eql('54.506.158/0001-67'); | ||
done(); | ||
}); | ||
it('should maks 79121383000106 to 79.121.383/0001-06', function(done) { | ||
should(BrM.cpfCnpj('79121383000106')).be.eql('79.121.383/0001-06'); | ||
done(); | ||
}); | ||
it('should maks 12871891000134 to 12.871.891/0001-34', function(done) { | ||
should(BrM.cpfCnpj('12871891000134')).be.eql('12.871.891/0001-34'); | ||
done(); | ||
}); | ||
it('should maks 01781192000120 to 01.781.192/0001-20', function(done) { | ||
should(BrM.cpfCnpj('01781192000120')).be.eql('01.781.192/0001-20'); | ||
done(); | ||
}); | ||
|
||
// --- // | ||
|
||
it('should mask 97070868669 to 970.708.686-69', function(done) { | ||
should(BrM.cpfCnpj('97070868669')).be.eql('970.708.686-69'); | ||
done(); | ||
}); | ||
it('should mask 21984171208 to 219.841.712-08', function(done) { | ||
should(BrM.cpfCnpj('21984171208')).be.eql('219.841.712-08'); | ||
done(); | ||
}); | ||
it('should mask 24653511098 to 246.535.110-98', function(done) { | ||
should(BrM.cpfCnpj('24653511098')).be.eql('246.535.110-98'); | ||
done(); | ||
}); | ||
it('should mask 24650512070 to 246.505.120-70', function(done) { | ||
should(BrM.cpfCnpj('24650512070')).be.eql('246.505.120-70'); | ||
done(); | ||
}); | ||
it('should mask 14351512013 to 143.515.120-13', function(done) { | ||
should(BrM.cpfCnpj('14351512013')).be.eql('143.515.120-13'); | ||
done(); | ||
}); | ||
it('should mask 143515 to 143.515', function(done) { | ||
should(BrM.cpfCnpj('1435151')).be.eql('143.515.1'); | ||
done(); | ||
}); | ||
}); |