From c73ae5c7c785522b576114d789ed50aa5b4e98c6 Mon Sep 17 00:00:00 2001 From: Jordan Richlen Date: Thu, 29 Mar 2018 18:24:00 -0500 Subject: [PATCH 1/4] Added chance.image() --- chance.js | 7 +++++++ test/test.web.js | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/chance.js b/chance.js index 908edf33..aa268041 100644 --- a/chance.js +++ b/chance.js @@ -1373,6 +1373,13 @@ } }; + Chance.prototype.image = function (options) { + var height = '500'; + var width = '500'; + + return 'https://picsum.photos/' + width + '/' + height + '/?random' + } + // -- End Web -- // -- Location -- diff --git a/test/test.web.js b/test/test.web.js index b5798bdd..eae72a1b 100644 --- a/test/test.web.js +++ b/test/test.web.js @@ -540,3 +540,16 @@ test('url() can take and respect extensions', t => { t.not(url.indexOf('.html'), -1) }) }) + +// chance.image() +test('image() returns picsum url with default height and width', t => { + _.times(1000, () => { + let image = chance.image() + t.true(_.isString(image)) + t.true(image.split('.').length > 1) + t.true(image.split('://').length > 1) + t.true(image.split('picsum.photos').length > 1) + t.true(image.split('/500/500').length > 1) + t.true(image.split('/?random').length > 1) + }) +}) From 6e589b2fc56171ba18d49c22d6b4b4a3df9e2db3 Mon Sep 17 00:00:00 2001 From: Jordan Richlen Date: Thu, 29 Mar 2018 18:36:48 -0500 Subject: [PATCH 2/4] Updated chance.image() to accept options --- chance.js | 8 +++++--- test/test.web.js | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/chance.js b/chance.js index aa268041..714b78e0 100644 --- a/chance.js +++ b/chance.js @@ -1374,10 +1374,12 @@ }; Chance.prototype.image = function (options) { - var height = '500'; - var width = '500'; + options = initOptions(options, { + width: 500, + height: 500 + }) - return 'https://picsum.photos/' + width + '/' + height + '/?random' + return 'https://picsum.photos/' + options.width + '/' + options.height + '/?random' } // -- End Web -- diff --git a/test/test.web.js b/test/test.web.js index eae72a1b..e0d85536 100644 --- a/test/test.web.js +++ b/test/test.web.js @@ -542,7 +542,7 @@ test('url() can take and respect extensions', t => { }) // chance.image() -test('image() returns picsum url with default height and width', t => { +test('image() returns image url with default width and height', t => { _.times(1000, () => { let image = chance.image() t.true(_.isString(image)) @@ -553,3 +553,41 @@ test('image() returns picsum url with default height and width', t => { t.true(image.split('/?random').length > 1) }) }) +test('image() returns image url respects width and height', t => { + _.times(1000, () => { + let width = chance.natural(); + let height = chance.natural(); + let image = chance.image({ + width, + height + }) + t.true(_.isString(image)) + t.true(image.split('.').length > 1) + t.true(image.split('://').length > 1) + t.true(image.split('picsum.photos').length > 1) + t.true(image.split('/' + width + '/' + height).length > 1) + t.true(image.split('/?random').length > 1) + }) +}) +// test('image() returns image url with default height and width', t => { +// _.times(1000, () => { +// let image = chance.image() +// t.true(_.isString(image)) +// t.true(image.split('.').length > 1) +// t.true(image.split('://').length > 1) +// t.true(image.split('picsum.photos').length > 1) +// t.true(image.split('/500/500').length > 1) +// t.true(image.split('/?random').length > 1) +// }) +// }) +// test('image() returns image url with default height and width', t => { +// _.times(1000, () => { +// let image = chance.image() +// t.true(_.isString(image)) +// t.true(image.split('.').length > 1) +// t.true(image.split('://').length > 1) +// t.true(image.split('picsum.photos').length > 1) +// t.true(image.split('/500/500').length > 1) +// t.true(image.split('/?random').length > 1) +// }) +// }) From e664b6185c91006feb87794d14008fadf7325c0c Mon Sep 17 00:00:00 2001 From: Jordan Richlen Date: Thu, 29 Mar 2018 19:01:08 -0500 Subject: [PATCH 3/4] Added options to chance.image() --- chance.js | 10 +++++----- test/test.web.js | 50 ++++++++++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/chance.js b/chance.js index 714b78e0..a4f934a6 100644 --- a/chance.js +++ b/chance.js @@ -1374,12 +1374,12 @@ }; Chance.prototype.image = function (options) { - options = initOptions(options, { - width: 500, - height: 500 - }) + options = initOptions(options, { width: 500, height: 500, greyscale: false, blurred: false }); + + var greyscale = options.greyscale ? 'g/' : ''; + var query = options.blurred ? '/?blur' : '/?random'; - return 'https://picsum.photos/' + options.width + '/' + options.height + '/?random' + return 'https://picsum.photos/' + greyscale + options.width + '/' + options.height + query; } // -- End Web -- diff --git a/test/test.web.js b/test/test.web.js index e0d85536..a3272f88 100644 --- a/test/test.web.js +++ b/test/test.web.js @@ -553,7 +553,7 @@ test('image() returns image url with default width and height', t => { t.true(image.split('/?random').length > 1) }) }) -test('image() returns image url respects width and height', t => { +test('image() returns image url that respects width and height', t => { _.times(1000, () => { let width = chance.natural(); let height = chance.natural(); @@ -569,25 +569,29 @@ test('image() returns image url respects width and height', t => { t.true(image.split('/?random').length > 1) }) }) -// test('image() returns image url with default height and width', t => { -// _.times(1000, () => { -// let image = chance.image() -// t.true(_.isString(image)) -// t.true(image.split('.').length > 1) -// t.true(image.split('://').length > 1) -// t.true(image.split('picsum.photos').length > 1) -// t.true(image.split('/500/500').length > 1) -// t.true(image.split('/?random').length > 1) -// }) -// }) -// test('image() returns image url with default height and width', t => { -// _.times(1000, () => { -// let image = chance.image() -// t.true(_.isString(image)) -// t.true(image.split('.').length > 1) -// t.true(image.split('://').length > 1) -// t.true(image.split('picsum.photos').length > 1) -// t.true(image.split('/500/500').length > 1) -// t.true(image.split('/?random').length > 1) -// }) -// }) +test('image() returns image url that respects greyscale', t => { + _.times(1000, () => { + let image = chance.image({ + greyscale: true + }) + t.true(_.isString(image)) + t.true(image.split('.').length > 1) + t.true(image.split('://').length > 1) + t.true(image.split('picsum.photos').length > 1) + t.true(image.split('/g/500/500').length > 1) + t.true(image.split('/?random').length > 1) + }) +}) +test('image() returns image url that respects blurred', t => { + _.times(1000, () => { + let image = chance.image({ + blurred: true + }) + t.true(_.isString(image)) + t.true(image.split('.').length > 1) + t.true(image.split('://').length > 1) + t.true(image.split('picsum.photos').length > 1) + t.true(image.split('/500/500').length > 1) + t.true(image.split('/?blur').length > 1) + }) +}) From 133c55b62c5c723b23c84b0f220f6f3c8fdda8a9 Mon Sep 17 00:00:00 2001 From: Jordan Richlen Date: Fri, 6 Apr 2018 18:32:15 -0500 Subject: [PATCH 4/4] Changed chance.image() to chance.loremPicsum() --- chance.js | 2 +- test/test.web.js | 66 ++++++++++++++++++++++++------------------------ 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/chance.js b/chance.js index a4f934a6..1d174fa6 100644 --- a/chance.js +++ b/chance.js @@ -1373,7 +1373,7 @@ } }; - Chance.prototype.image = function (options) { + Chance.prototype.loremPicsum = function (options) { options = initOptions(options, { width: 500, height: 500, greyscale: false, blurred: false }); var greyscale = options.greyscale ? 'g/' : ''; diff --git a/test/test.web.js b/test/test.web.js index a3272f88..63e5b622 100644 --- a/test/test.web.js +++ b/test/test.web.js @@ -541,57 +541,57 @@ test('url() can take and respect extensions', t => { }) }) -// chance.image() -test('image() returns image url with default width and height', t => { +// chance.loremPicsum() +test('loremPicsum() returns loremPicsum url with default width and height', t => { _.times(1000, () => { - let image = chance.image() - t.true(_.isString(image)) - t.true(image.split('.').length > 1) - t.true(image.split('://').length > 1) - t.true(image.split('picsum.photos').length > 1) - t.true(image.split('/500/500').length > 1) - t.true(image.split('/?random').length > 1) + let loremPicsumUrl = chance.loremPicsum() + t.true(_.isString(loremPicsumUrl)) + t.true(loremPicsumUrl.split('.').length > 1) + t.true(loremPicsumUrl.split('://').length > 1) + t.true(loremPicsumUrl.split('picsum.photos').length > 1) + t.true(loremPicsumUrl.split('/500/500').length > 1) + t.true(loremPicsumUrl.split('/?random').length > 1) }) }) -test('image() returns image url that respects width and height', t => { +test('loremPicsum() returns loremPicsum url that respects width and height', t => { _.times(1000, () => { let width = chance.natural(); let height = chance.natural(); - let image = chance.image({ + let loremPicsumUrl = chance.loremPicsum({ width, height }) - t.true(_.isString(image)) - t.true(image.split('.').length > 1) - t.true(image.split('://').length > 1) - t.true(image.split('picsum.photos').length > 1) - t.true(image.split('/' + width + '/' + height).length > 1) - t.true(image.split('/?random').length > 1) + t.true(_.isString(loremPicsumUrl)) + t.true(loremPicsumUrl.split('.').length > 1) + t.true(loremPicsumUrl.split('://').length > 1) + t.true(loremPicsumUrl.split('picsum.photos').length > 1) + t.true(loremPicsumUrl.split('/' + width + '/' + height).length > 1) + t.true(loremPicsumUrl.split('/?random').length > 1) }) }) -test('image() returns image url that respects greyscale', t => { +test('loremPicsum() returns loremPicsum url that respects greyscale', t => { _.times(1000, () => { - let image = chance.image({ + let loremPicsumUrl = chance.loremPicsum({ greyscale: true }) - t.true(_.isString(image)) - t.true(image.split('.').length > 1) - t.true(image.split('://').length > 1) - t.true(image.split('picsum.photos').length > 1) - t.true(image.split('/g/500/500').length > 1) - t.true(image.split('/?random').length > 1) + t.true(_.isString(loremPicsumUrl)) + t.true(loremPicsumUrl.split('.').length > 1) + t.true(loremPicsumUrl.split('://').length > 1) + t.true(loremPicsumUrl.split('picsum.photos').length > 1) + t.true(loremPicsumUrl.split('/g/500/500').length > 1) + t.true(loremPicsumUrl.split('/?random').length > 1) }) }) -test('image() returns image url that respects blurred', t => { +test('loremPicsum() returns loremPicsum url that respects blurred', t => { _.times(1000, () => { - let image = chance.image({ + let loremPicsumUrl = chance.loremPicsum({ blurred: true }) - t.true(_.isString(image)) - t.true(image.split('.').length > 1) - t.true(image.split('://').length > 1) - t.true(image.split('picsum.photos').length > 1) - t.true(image.split('/500/500').length > 1) - t.true(image.split('/?blur').length > 1) + t.true(_.isString(loremPicsumUrl)) + t.true(loremPicsumUrl.split('.').length > 1) + t.true(loremPicsumUrl.split('://').length > 1) + t.true(loremPicsumUrl.split('picsum.photos').length > 1) + t.true(loremPicsumUrl.split('/500/500').length > 1) + t.true(loremPicsumUrl.split('/?blur').length > 1) }) })