Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: victorquinn/chancejs
base: 0.5.1
...
head fork: victorquinn/chancejs
compare: 0.5.2
  • 14 commits
  • 6 files changed
  • 2 commit comments
  • 3 contributors
View
77 README.md
@@ -38,23 +38,27 @@ It can also be used with [Bower](http://bower.io)
then in the HTML of your app:
<!-- Load Chance -->
- <script type="text/javascript" src="components/chance/chance.min.js"></script>
+ <script type="text/javascript" src="bower_components/chance/chance.min.js"></script>
<script>
// Use Chance immediately!
alert(chance.string());
</script>
-### RequireJS
+### Component
-Chance also includes an AMD define so it can be used with RequireJS.
+It can also be used with [Component](http://component.io)
+
+ component install victorquinn/chancejs
+
+then in the HTML of your app:
+
+ <!-- Load Chance -->
+ <script type="text/javascript" src="components/victorquinn-chancejs/chance.js"></script>
+ <script>
+ // Use Chance immediately!
+ alert(chance.string());
+ </script>
- require(['Chance'], function(Chance) {
- // Instantiate
- var chance = new Chance();
-
- // Then just use it:
- var my_random_integer = chance.integer();
- });
### Node.js
@@ -67,6 +71,18 @@ And it can be used in Node.js.
// Get a random zip code
chance.zip();
+### RequireJS
+
+Chance also includes an AMD define so it can be used with RequireJS.
+
+ require(['Chance'], function(Chance) {
+ // Instantiate
+ var chance = new Chance();
+
+ // Then just use it:
+ var my_random_integer = chance.integer();
+ });
+
## Author
### Victor Quinn
@@ -79,27 +95,28 @@ Please feel free to reach out to me if you have any questions or suggestions.
THANK YOU!
```
- project : chancejs
- repo age : 4 months
- active : 40 days
- commits : 215
- files : 18
+project : chancejs
+ repo age : 5 months
+ active : 43 days
+ commits : 231
+ files : 19
authors :
- 167 Victor Quinn 77.7%
- 11 davmillar 5.1%
- 11 Tim Petricola 5.1%
- 5 Michael Cordingley 2.3%
- 5 Matt Klaber 2.3%
- 3 qjcg 1.4%
- 2 dhilipsiva 0.9%
- 2 Andreas Koeberle 0.9%
- 2 path411 0.9%
- 2 Kevin Garnett 0.9%
- 1 Ryan Tenney 0.5%
- 1 Doug Lawrence 0.5%
- 1 Richard Anaya 0.5%
- 1 Adam Krebs 0.5%
- 1 leesei 0.5%
+ 180 Victor Quinn 77.9%
+ 11 davmillar 4.8%
+ 11 Tim Petricola 4.8%
+ 5 Michael Cordingley 2.2%
+ 5 Matt Klaber 2.2%
+ 4 Kevin Garnett 1.7%
+ 3 qjcg 1.3%
+ 2 dhilipsiva 0.9%
+ 2 Andreas Koeberle 0.9%
+ 2 path411 0.9%
+ 1 Ryan Tenney 0.4%
+ 1 Doug Lawrence 0.4%
+ 1 Johannes Stein 0.4%
+ 1 Richard Anaya 0.4%
+ 1 Adam Krebs 0.4%
+ 1 leesei 0.4%
```
This project is licensed under the [MIT License](http://en.wikipedia.org/wiki/MIT_License) so feel free to hack away :)
View
2  bower.json
@@ -1,6 +1,6 @@
{
"name": "chance",
- "version": "0.5.1",
+ "version": "0.5.2",
"main": "chance.js",
"ignore": ["node_modules"],
"description": "Chance - Utility library to generate anything random",
View
25 chance.js
@@ -1,4 +1,4 @@
-// Chance.js 0.5.1
+// Chance.js 0.5.2
// http://chancejs.com
// (c) 2013 Victor Quinn
// Chance may be freely distributed or modified under the MIT license.
@@ -1027,12 +1027,21 @@
};
// Guid
- Chance.prototype.guid = function () {
- return this.hash({casing: 'upper', length: 8}) + '-' +
- this.hash({casing: 'upper', length: 4}) + '-' +
- this.hash({casing: 'upper', length: 4}) + '-' +
- this.hash({casing: 'upper', length: 4}) + '-' +
- this.hash({casing: 'upper', length: 12});
+ Chance.prototype.guid = function (options) {
+ options = options || {version: 5};
+
+ var guid_pool = "ABCDEF1234567890",
+ variant_pool = "AB89",
+ guid = this.string({pool: guid_pool, length: 8}) + '-' +
+ this.string({pool: guid_pool, length: 4}) + '-' +
+ // The Version
+ options.version +
+ this.string({pool: guid_pool, length: 3}) + '-' +
+ // The Variant
+ this.string({pool: variant_pool, length: 1}) +
+ this.string({pool: guid_pool, length: 3}) + '-' +
+ this.string({pool: guid_pool, length: 12});
+ return guid;
};
// Hash
@@ -1070,7 +1079,7 @@
// -- End Miscellaneous --
- Chance.prototype.VERSION = "0.5.1";
+ Chance.prototype.VERSION = "0.5.2";
// Mersenne Twister from https://gist.github.com/banksean/300494
var MersenneTwister = function (seed) {
View
9 component.json
@@ -0,0 +1,9 @@
+{
+ "name": "chance",
+ "repo": "victorquinn/chancejs",
+ "description": "Minimalist generator of random strings, numbers, etc.",
+ "version": "0.5.2",
+ "keywords": ["chance", "random", "generator", "test"],
+ "scripts": "chance.js",
+ "licence": "MIT"
+}
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "chance",
"main": "./chance.js",
- "version": "0.5.1",
+ "version": "0.5.2",
"description": "Chance - Utility library to generate anything random",
"homepage": "http://chancejs.com",
"author": "Victor Quinn <mail@victorquinn.com>",
View
35 test/test.misc.js
@@ -94,6 +94,41 @@ define(['Chance', 'mocha', 'chai', 'underscore'], function (Chance, mocha, chai,
expect(guid).to.match(/([0-9a-fA-F]){8}(-([0-9a-fA-F]){4}){3}-([0-9a-fA-F]){12}/);
});
});
+
+ it("returns a proper version 1 guid", function () {
+ _(1000).times(function () {
+ guid = chance.guid({version: 1});
+ expect(guid).to.match(/([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-1([0-9a-fA-F]){3}-([AB89])([0-9a-fA-F]){3}-([0-9a-fA-F]){12}/);
+ });
+ });
+
+ it("returns a proper version 2 guid", function () {
+ _(1000).times(function () {
+ guid = chance.guid({version: 2});
+ expect(guid).to.match(/([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-2([0-9a-fA-F]){3}-([AB89])([0-9a-fA-F]){3}-([0-9a-fA-F]){12}/);
+ });
+ });
+
+ it("returns a proper version 3 guid", function () {
+ _(1000).times(function () {
+ guid = chance.guid({version: 3});
+ expect(guid).to.match(/([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-3([0-9a-fA-F]){3}-([AB89])([0-9a-fA-F]){3}-([0-9a-fA-F]){12}/);
+ });
+ });
+
+ it("returns a proper version 4 guid", function () {
+ _(1000).times(function () {
+ guid = chance.guid({version: 4});
+ expect(guid).to.match(/([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-4([0-9a-fA-F]){3}-([AB89])([0-9a-fA-F]){3}-([0-9a-fA-F]){12}/);
+ });
+ });
+
+ it("returns a proper version 5 guid", function () {
+ _(1000).times(function () {
+ guid = chance.guid({version: 5});
+ expect(guid).to.match(/([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-5([0-9a-fA-F]){3}-([AB89])([0-9a-fA-F]){3}-([0-9a-fA-F]){12}/);
+ });
+ });
});
describe("Hash", function () {

Showing you all comments on commits in this comparison.

@sidwood

What?! No unit test? ;o)

@victorquinn

Heh shame on me!

I actually tried to find a way to do it but couldn't find one without breaking compatibility.

This is an odd case due to the fact that I am globally instantiating an object named "chance." So it actually passed my tests fine because PhantomJS (which I use for the tests) had access to the chance object. It is an edge case that will fail only when using this in Node and not anywhere else.

I considered creating another separate test suite spinning up Chance in Node rather than PhantomJS but that seemed unnecessarily complex.

Anyway, I know you were likely just joking with your comment, but I wanted to let you know I did think long and hard about it!

Something went wrong with that request. Please try again.