Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Apr 24, 2016
1 parent 6307334 commit acce8fe
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 41 deletions.
39 changes: 15 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# random-zipcode

> Generate a random chinese zipcode.
> Generate a random (U.S.) zip code.
[![MIT License](https://img.shields.io/badge/license-MIT_License-green.svg?style=flat-square)](https://github.com/mock-end/random-zipcode/blob/master/LICENSE)

Expand All @@ -19,34 +19,25 @@ $ npm install --save random-zipcode
```js
var randomZip = require('random-zipcode');

// API
// - randomZip();
// - randomZip(plusFour);

randomZip();
// => 310000
// => '90210'
```

Can optionally specify that it ought to return a [Zip+4](http://vq.io/19rzsve):

```js
randomZip(true);
// => '01035-1838'
```

## Related

- [random-integral](https://github.com/mock-end/random-integral) - Generate a random integer.
- [random-natural](https://github.com/mock-end/random-natural) - Generate a random natural number.
- [random-decimal](https://github.com/mock-end/random-decimal) - Generate a random decimal.
- [random-index](https://github.com/mock-end/random-index) - Generate a random array-like index.
- [random-hexadecimal](https://github.com/mock-end/random-hexadecimal) - Generate a random hexadecimal number.
- [random-octal](https://github.com/mock-end/random-octal) - Generate a random octal.
- [random-unicode](https://github.com/mock-end/random-unicode) - Generate a random unicode.
- [random-bool](https://github.com/mock-end/random-bool) - Generate a random boolean (true/false).
- [random-char](https://github.com/mock-end/random-char) - Generate a random char.
- [random-lorem](https://github.com/mock-end/random-lorem) - Generate a random world.
- [random-title](https://github.com/mock-end/random-title) - Generate a random title.
- [random-sentence](https://github.com/mock-end/random-sentence) - Generate a random sentence.
- [random-paragraph](https://github.com/mock-end/random-paragraph) - Generate a random paragraph.
- [random-tld](https://github.com/mock-end/random-tld) - Return a random tld.
- [random-domains](https://github.com/mock-end/random-domains) - Generate a random domain name.
- [random-uri](https://github.com/mock-end/random-uri.git) - Generate a random url.
- [random-email](https://github.com/mock-end/random-email) - Generate a random email.
- [random-lang](https://github.com/mock-end/random-lang) - Return a random language name.
- [random-mobile](https://github.com/mock-end/random-mobile) - Generate a random chinese mobile phone number.
- [random-ipv4](https://github.com/mock-end/random-ipv4) - Generate a random ipv4 address.
- [random-ipv6](https://github.com/mock-end/random-ipv6) - Generate a random ipv6 address.
- [random-color](https://github.com/mock-end/random-color) - Generate a random color.
- [random-areacode](https://github.com/mock-end/random-areacode) - Generate a random (U.S.) area code.
- [random-mobile](https://github.com/mock-end/random-mobile) - Generate a random (U.S.) mobile phone number.

## Contributing

Expand Down
25 changes: 23 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
'use strict';

module.exports = function () {
return '' + (Math.round(Math.random() * (999999 - 100000)) + 100000);
var randomNatural = require('random-natural');

module.exports = function (plusFour) {

var i = 5;

var result = '';

while (i--) {
result += randomNatural(0, 9).toString();
}

if (plusFour) {

result += '-';

i = 4;
while (i--) {
result += randomNatural(0, 9).toString();
}
}

return result;
};
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "random-zipcode",
"version": "1.0.0",
"description": "Generate a random chinese zipcode.",
"description": "Generate a random (U.S.) zip code.",
"main": "index.js",
"scripts": {
"lint": "jshint index.js",
Expand All @@ -16,17 +16,17 @@
"email": "bubkoo.wy@gmail.com"
},
"keywords": [
"zipcode",
"zip",
"code",
"generator",
"generate",
"gen",
"zipcode",
"U.S.",
"location",
"random",
"randomly",
"randomize",
"rand",
"chinese"
"chance",
"test",
"dice",
"mock"
],
"license": "MIT",
"repository": {
Expand All @@ -43,5 +43,8 @@
"coveralls": "^2.11.9",
"istanbul": "^0.4.2",
"mocha": "^2.4.5"
},
"dependencies": {
"random-natural": "^1.0.2"
}
}
16 changes: 9 additions & 7 deletions test/spec/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
'use strict';

var char = require('chai');
var expect = char.expect;

var expect = require('chai').expect;

describe('random-zip: ', function () {

var randomZip = require('../../index');

it('shuffle()', function () {
expect(randomZip()).to.match(/^[\d]{6}$/);
it('common', function () {

var count = 100;

while (count--) {
expect(randomZip()).to.match(/^[\d]{5}$/);
expect(randomZip(true)).to.match(/^[\d]{5}-\d{4}$/);
}
});
});

0 comments on commit acce8fe

Please sign in to comment.