Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zip #98

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ Casual uses javascript properties for common generators so you don't need to use

casual.country // 'United Kingdom'
casual.city // 'New Ortiz chester'
casual.zip(digits = {5, 9}) // '26995-7979' (if no digits specified then random selection between ZIP and ZIP+4)
casual.zip(digits = {5, 9}) // '26995-7979' or '26995' (if no digits specified then random selection between ZIP and ZIP+4)
casual.zip_short // '26995'
casual.zip_long // '26995-7979'
casual.street // 'Jadyn Islands'
casual.address // '6390 Tremblay Pines Suite 784'
casual.address1 // '8417 Veda Circles'
Expand Down
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ declare namespace Casual {
// EMBEDDED GENERATORS
country: string; // 'United Kingdom'
city: string; // 'New Ortiz chester'
zip(digits: Object): string; // '26995-7979' (if no digits specified then random selection between ZIP and ZIP+4)
zip(digits?: number): string; // '26995-7979' (if no digits specified then random selection between ZIP and ZIP+4)
zip_short: string; // '26995'
zip_long: string // '26995-7979'
street: string; // 'Jadyn Islands'
address: string; // '6390 Tremblay Pines Suite 784'
address1: string; // '8417 Veda Circles'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "casual",
"version": "1.6.2",
"version": "1.7.0",
"description": "Fake data generator",
"main": "src/casual.js",
"scripts": {
Expand Down
10 changes: 9 additions & 1 deletion src/providers/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var provider = {
return this.populate_one_of(this.city_formats);
},

zip: function(digits) {
zip: function(digits=0) {
if (digits === 5) {
return this.numerify(this.zip_formats[0]);
} else if (digits === 9) {
Expand All @@ -59,6 +59,14 @@ var provider = {
return this.numerify(this.random_element(this.zip_formats));
}
},

zip_short: function() {
return this.numerify(this.zip_formats[0]);
},

zip_long: function() {
return this.numerify(this.zip_formats[this.zip_formats.length - 1]);
},

street_suffix: function() {
return this.random_element(this.street_suffixes);
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ar_SY/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var provider = {
return this.random_element(this.cities);
},

zip: function(digits) {
zip: function(digits=0) {
if (digits === 5) {
return this.numerify(this.zip_formats[0]);
} else if (digits === 9) {
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ja_JP/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var provider = {
return this.populate_one_of(this.city_formats);
},

zip: function(digits) {
zip: function(digits=0) {
if (digits === 5) {
return this.numerify(this.zip_formats[0]);
} else if (digits === 9) {
Expand Down
5 changes: 5 additions & 0 deletions test/casual.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ describe('API', function() {
it('Should have getter function at _{name}', function() {
providers.forEach(check_getters);
});

it('zip should not be a function', function() {
const type = typeof casual.zip;
type.should.not.eql('function');
});

it('Should return only funtions interface', function() {
var functions = casual.functions();
Expand Down