Comparing version 1.1.8 to 1.1.9
{ | ||
"name": "chance", | ||
"version": "1.1.8", | ||
"version": "1.1.9", | ||
"main": "chance.js", | ||
@@ -5,0 +5,0 @@ "ignore": [ |
@@ -35,3 +35,3 @@ # birthday | ||
Can also specify the type, same types as with [age](#age). | ||
Can specify the type, same types as with [age](#age). | ||
@@ -43,3 +43,3 @@ ```js | ||
You can also compose with `chance.year` for interesting combinations. For example, let's say we want to get the birthdays of some renaissance artists (born between 1450 and 1500). We can generate a year and then get a birthday from that year: | ||
You can compose with `chance.year` for interesting combinations. For example, let's say we want to get the birthdays of some renaissance artists (born between 1450 and 1500). We can generate a year and then get a birthday from that year: | ||
@@ -56,3 +56,11 @@ ```js | ||
Can specify maxAge and/or minAge. This will return a date which yields to an age between the given range. Attention on limits: the full day of birthdays are considered to be part of the allowed range (from the first millisecond of the minimum date to the last second of the maximum date). | ||
```js | ||
chance.birthday({minAge: 18, maxAge: 21}); | ||
=> Thu Apr 18 2002 13:48:34 GMT-0400 (EDT) | ||
``` | ||
[Date]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date | ||
[Moment]: http://momentjs.com |
{ | ||
"name": "chance", | ||
"main": "./chance.js", | ||
"version": "1.1.8", | ||
"version": "1.1.9", | ||
"description": "Chance - Utility library to generate anything random", | ||
@@ -6,0 +6,0 @@ "homepage": "http://chancejs.com", |
@@ -519,2 +519,6 @@ import test from 'ava' | ||
test('string() returns an empty string with zero length', t => { | ||
t.is(chance.string({length: 0}), '') | ||
}) | ||
test('falsy() should return a falsy value', t => { | ||
@@ -521,0 +525,0 @@ _.times(1000, () => { |
@@ -19,4 +19,16 @@ import test from 'ava' | ||
const currentYear = new Date().getFullYear() | ||
const now = Object.freeze(new Date()) | ||
const currentYear = now.getFullYear() | ||
// helper functions | ||
const ymd = dt => ({y: dt.getFullYear(), m: dt.getMonth(), d: dt.getDate()}) | ||
const today = ymd(now) | ||
const age = dt => { | ||
// - uses the format returned by ymd, instead of Date -- improves speed between 30% and 60% | ||
// - uses `today` as a closure -- considers current date constant, each time the test suit runs | ||
const dob = ymd(dt) | ||
const completed = (today.m > dob.m || (today.m === dob.m && today.d >= dob.d)) | ||
return (today.y - dob.y) - (completed ? 0 : 1) | ||
} | ||
// chance.age() | ||
@@ -144,2 +156,41 @@ test('age() returns a random age within expected bounds', t => { | ||
test('birthday() can have an age range specified by minAge only', t => { | ||
for(let minAge=0; minAge < 100; minAge++) | ||
_.times(10, () => { | ||
let birthday = chance.birthday({ minAge }) | ||
const calculated = age(birthday) | ||
t.true(calculated >= minAge, JSON.stringify({birthday, calculated})) | ||
}) | ||
}) | ||
test('birthday() can have an age range specified by maxAge only', t => { | ||
for(let maxAge=0; maxAge < 100; maxAge++) | ||
_.times(10, () => { | ||
let birthday = chance.birthday({ maxAge }) | ||
const calculated = age(birthday) | ||
t.true(calculated <= maxAge, JSON.stringify({birthday, calculated})) | ||
}) | ||
}) | ||
test('birthday() can have an age range specified by minAge and maxAge', t => { | ||
for(let minAge=0; minAge < 100; minAge++) | ||
for(let maxAge=minAge; maxAge < 100; maxAge++) | ||
_.times(10, () => { | ||
let birthday = chance.birthday({ minAge, maxAge }) | ||
const calculated = age(birthday) | ||
t.true(calculated >= minAge, JSON.stringify({birthday, calculated})) | ||
t.true(calculated <= maxAge, JSON.stringify({birthday, calculated})) | ||
}) | ||
}) | ||
test('birthday() throws an error if minAge < 0', t => { | ||
const fn = () => chance.birthday({ minAge: -1 }) | ||
t.throws(fn, 'Chance: MinAge cannot be less than zero.') | ||
}) | ||
test('birthday() throws an error if minAge > maxAge', t => { | ||
const fn = () => chance.birthday({ minAge: 30, maxAge: 10 }) | ||
t.throws(fn, 'Chance: MinAge cannot be greater than MaxAge.') | ||
}) | ||
// chance.cnpj() | ||
@@ -146,0 +197,0 @@ test('cnpj() returns a random cnpj', t => { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1897843
161
20294