+1
-1
| { | ||
| "name": "chance", | ||
| "version": "0.5.9", | ||
| "version": "0.6.0", | ||
| "main": "chance.js", | ||
@@ -5,0 +5,0 @@ "ignore": ["node_modules"], |
+1
-1
@@ -5,3 +5,3 @@ { | ||
| "description": "Minimalist generator of random strings, numbers, etc.", | ||
| "version": "0.5.9", | ||
| "version": "0.6.0", | ||
| "keywords": ["chance", "random", "generator", "test"], | ||
@@ -8,0 +8,0 @@ "main": "chance.js", |
+1
-1
| { | ||
| "name": "chance", | ||
| "main": "./chance.js", | ||
| "version": "0.5.9", | ||
| "version": "0.6.0", | ||
| "description": "Chance - Utility library to generate anything random", | ||
@@ -6,0 +6,0 @@ "homepage": "http://chancejs.com", |
+38
-26
@@ -108,37 +108,49 @@ # Chance | ||
| ``` | ||
| project : chancejs | ||
| repo age : 1 year | ||
| active : 77 days | ||
| commits : 306 | ||
| project : chancejs | ||
| repo age : 1 year, 2 months | ||
| active : 87 days | ||
| commits : 336 | ||
| files : 21 | ||
| authors : | ||
| 230 Victor Quinn 75.2% | ||
| 13 Tim Petricola 4.2% | ||
| 11 davmillar 3.6% | ||
| 5 Michael Cordingley 1.6% | ||
| 5 Alex DiLiberto 1.6% | ||
| 5 Matt Klaber 1.6% | ||
| 4 Kevin Garnett 1.3% | ||
| 3 Alexandr Lozovyuk 1.0% | ||
| 3 qjcg 1.0% | ||
| 2 xshyamx 0.7% | ||
| 2 Andreas Koeberle 0.7% | ||
| 2 Iskren Chernev 0.7% | ||
| 2 Nicholas Johnson 0.7% | ||
| 2 Pascal Borreli 0.7% | ||
| 2 dhilipsiva 0.7% | ||
| 2 path411 0.7% | ||
| 2 shyam 0.7% | ||
| 2 Adam Krebs 0.7% | ||
| 1 Ng, Patrick 0.3% | ||
| 249 Victor Quinn 74.1% | ||
| 13 Tim Petricola 3.9% | ||
| 11 davmillar 3.3% | ||
| 5 Michael Cordingley 1.5% | ||
| 5 Alex DiLiberto 1.5% | ||
| 5 Matt Klaber 1.5% | ||
| 4 Abhijeet Pawar 1.2% | ||
| 4 Kevin Garnett 1.2% | ||
| 4 Avishaan 1.2% | ||
| 3 qjcg 0.9% | ||
| 3 Alexandr Lozovyuk 0.9% | ||
| 3 Nicholas Johnson 0.9% | ||
| 2 xshyamx 0.6% | ||
| 2 Adam Krebs 0.6% | ||
| 2 Andreas Koeberle 0.6% | ||
| 2 Iskren Chernev 0.6% | ||
| 2 Pascal Borreli 0.6% | ||
| 2 dhilipsiva 0.6% | ||
| 2 path411 0.6% | ||
| 2 shyam 0.6% | ||
| 1 Richard Anaya 0.3% | ||
| 1 Johannes Stein 0.3% | ||
| 1 ddunning 0.3% | ||
| 1 Doug Lawrence 0.3% | ||
| 1 Dominic Barnes 0.3% | ||
| 1 flrent 0.3% | ||
| 1 leesei 0.3% | ||
| 1 lkptrzk 0.3% | ||
| 1 Richard Anaya 0.3% | ||
| 1 Dominic Barnes 0.3% | ||
| 1 Ryan Tenney 0.3% | ||
| 1 Samuel Greene 0.3% | ||
| 1 Johannes Stein 0.3% | ||
| 1 Ng, Patrick 0.3% | ||
| ``` | ||
| ### Contribute! | ||
| Be a part of this project! You can run the test using the following. | ||
| 1. Install dependencies from package.json by running `npm install` | ||
| 2. Install dependencies for testing by running `bower install` | ||
| 3. Run the test via `npm test` | ||
| 4. Make some fun new modules! | ||
| This project is licensed under the [MIT License](http://en.wikipedia.org/wiki/MIT_License) so feel free to hack away :) | ||
@@ -145,0 +157,0 @@ |
+13
-0
@@ -229,3 +229,16 @@ define(['Chance', 'mocha', 'chai', 'underscore'], function (Chance, mocha, chai, _) { | ||
| }); | ||
| }); | ||
| describe("Geohash", function () { | ||
| it("geohash() looks right", function() { | ||
| expect(chance.geohash()).to.be.a('string'); | ||
| expect(chance.geohash()).to.have.length(7); | ||
| }); | ||
| it("geohash() will accept a length and obey it", function() { | ||
| _(1000).times(function () { | ||
| var length = chance.d10(); | ||
| expect(chance.geohash({ length: length })).to.have.length(length); | ||
| }); | ||
| }); | ||
| }); | ||
@@ -232,0 +245,0 @@ |
+77
-0
@@ -43,2 +43,65 @@ define(['Chance', 'mocha', 'chai', 'underscore'], function (Chance, mocha, chai, _) { | ||
| describe("weighted()", function () { | ||
| it("returns an element", function () { | ||
| _(1000).times(function () { | ||
| picked = chance.weighted(['a', 'b', 'c', 'd'], [1, 1, 1, 1]); | ||
| expect(picked).to.be.a('string'); | ||
| }); | ||
| }); | ||
| it("throws an error if called with an array of weights with length different from options", function() { | ||
| expect(function () { | ||
| chance.weighted(['a', 'b', 'c', 'd'], [1, 2, 3]); | ||
| }).to.throw(RangeError, /length of array and weights must match/); | ||
| expect(function () { | ||
| chance.weighted(['a', 'b', 'c', 'd'], [1, 2, 3, 4]); | ||
| }).to.not.throw(RangeError, /length of array and weights must match/); | ||
| expect(function () { | ||
| chance.weighted(['a', 'b', 'c', 'd'], [1, 2, 3, 4, 5]); | ||
| }).to.throw(RangeError, /length of array and weights must match/); | ||
| }); | ||
| it("returns with results properly weighted", function() { | ||
| // Use Math.random as the random function rather than our Mersenne twister just to | ||
| // speed things up here because this test takes awhile to gather enough data to | ||
| // have a large enough sample size to adequately test. This increases performance | ||
| // by a few orders of magnitude | ||
| var chance = new Chance(Math.random); | ||
| _(10).times(function() { | ||
| var picked = { a: 0, b: 0, c: 0, d: 0 }; | ||
| // This makes it a tad slow, but we need a large enough sample size to adequately test | ||
| _(100000).times(function () { | ||
| picked[chance.weighted(['a', 'b', 'c', 'd'], [1, 100, 100, 1])]++; | ||
| }); | ||
| // This range is somewhat arbitrary, but good enough to test our constraints | ||
| expect(picked.b / picked.a).to.be.within(80, 120); | ||
| expect(picked.c / picked.d).to.be.within(80, 120); | ||
| expect((picked.c / picked.b) * 100).to.be.within(50, 150); | ||
| }); | ||
| }); | ||
| it("works with fractional weights", function() { | ||
| // Use Math.random as the random function rather than our Mersenne twister just to | ||
| // speed things up here because this test takes awhile to gather enough data to | ||
| // have a large enough sample size to adequately test. This increases performance | ||
| // by a few orders of magnitude | ||
| var chance = new Chance(Math.random); | ||
| _(10).times(function() { | ||
| var picked = { a: 0, b: 0, c: 0, d: 0 }; | ||
| // This makes it a tad slow, but we need a large enough sample size to adequately test | ||
| _(100000).times(function () { | ||
| picked[chance.weighted(['a', 'b', 'c', 'd'], [0.001, 0.1, 0.1, 0.001])]++; | ||
| }); | ||
| // This range is somewhat arbitrary, but good enough to test our constraints | ||
| expect(picked.b / picked.a).to.be.within(80, 120); | ||
| expect(picked.c / picked.d).to.be.within(80, 120); | ||
| expect((picked.c / picked.b) * 100).to.be.within(50, 150); | ||
| }); | ||
| }); | ||
| }); | ||
| describe("shuffle()", function () { | ||
@@ -135,2 +198,16 @@ it("returns an array of the same size", function () { | ||
| describe("n random terms", function () { | ||
| it("gives an array of n terms for the given function", function () { | ||
| var arr = chance.n(chance.email, 25, {domain: "example.com"}); | ||
| expect(arr).to.be.an('array'); | ||
| expect(arr[0]).to.match(/example\.com$/); | ||
| expect(arr.length).to.equal(25); | ||
| }); | ||
| it("gives an array of 1 term when n is not given", function () { | ||
| var arr = chance.n(chance.email); | ||
| expect(arr).to.be.an('array'); | ||
| expect(arr.length).to.equal(1); | ||
| }); | ||
| }); | ||
| describe("pad()", function () { | ||
@@ -137,0 +214,0 @@ it("always returns same number when width same as the length of the number", function () { |
+49
-5
@@ -88,2 +88,46 @@ define(['Chance', 'mocha', 'chai', 'underscore'], function (Chance, mocha, chai, _) { | ||
| describe("Mac Address", function () { | ||
| var mac, chance = new Chance(); | ||
| it("returns a proper mac address", function () { | ||
| _(1000).times(function () { | ||
| mac = chance.mac_address(); | ||
| expect(mac).to.match(/([0-9a-fA-F]){2}:([0-9a-fA-F]){2}:([0-9a-fA-F]){2}:([0-9a-fA-F]){2}:([0-9a-fA-F]){2}:([0-9a-fA-F]){2}/); | ||
| }); | ||
| }); | ||
| it("returns a proper colon separated mac address", function () { | ||
| _(1000).times(function () { | ||
| mac = chance.mac_address({separator: ":"}); | ||
| expect(mac).to.match(/([0-9a-fA-F]){2}:([0-9a-fA-F]){2}:([0-9a-fA-F]){2}:([0-9a-fA-F]){2}:([0-9a-fA-F]){2}:([0-9a-fA-F]){2}/); | ||
| }); | ||
| }); | ||
| it("returns a proper hyphen separated mac address", function () { | ||
| _(1000).times(function () { | ||
| mac = chance.mac_address({separator:"-"}); | ||
| expect(mac).to.match(/([0-9a-fA-F]){2}-([0-9a-fA-F]){2}-([0-9a-fA-F]){2}-([0-9a-fA-F]){2}-([0-9a-fA-F]){2}-([0-9a-fA-F]){2}/); | ||
| }); | ||
| }); | ||
| it("returns a proper network version mac address", function () { | ||
| _(1000).times(function () { | ||
| mac = chance.mac_address({networkVersion:true}); | ||
| expect(mac).to.match(/([0-9a-fA-F]){4}.([0-9a-fA-F]){4}.([0-9a-fA-F]){4}/); | ||
| }); | ||
| }); | ||
| }); | ||
| describe("Apple Token", function(){ | ||
| var apple_token, chance = new Chance(); | ||
| it("returns a proper apple token", function () { | ||
| _(1000).times(function () { | ||
| apple_token = chance.apple_token(); | ||
| expect(apple_token).to.match(/([0-9a-fA-F]){64}/); | ||
| }); | ||
| }); | ||
| }); | ||
| describe("Guid", function () { | ||
@@ -102,3 +146,3 @@ var guid, chance = new Chance(); | ||
| 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}/); | ||
| 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}/); | ||
| }); | ||
@@ -110,3 +154,3 @@ }); | ||
| 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}/); | ||
| 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}/); | ||
| }); | ||
@@ -118,3 +162,3 @@ }); | ||
| 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}/); | ||
| 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}/); | ||
| }); | ||
@@ -126,3 +170,3 @@ }); | ||
| 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}/); | ||
| 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}/); | ||
| }); | ||
@@ -134,3 +178,3 @@ }); | ||
| 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}/); | ||
| 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}/); | ||
| }); | ||
@@ -137,0 +181,0 @@ }); |
+7
-0
@@ -47,2 +47,9 @@ define(['Chance', 'mocha', 'chai', 'underscore'], function (Chance, mocha, chai, _) { | ||
| it("email() has a length specified, it should generate a string before the domain with an equal length", function () { | ||
| _(1000).times(function () { | ||
| email = chance.email({length: 5}); | ||
| expect(email.split('@')[0].length).to.equal(5); | ||
| }); | ||
| }); | ||
| it("fbid() returns what looks like a Facebook id", function () { | ||
@@ -49,0 +56,0 @@ _(1000).times(function () { |
Sorry, the diff of this file is too big to display
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
152064
6.79%3089
5.86%161
8.05%8
-11.11%