From ec13e84dcd6e01f908aa89bc56d3f8b1d5c9cd42 Mon Sep 17 00:00:00 2001 From: ChinCluBi Date: Fri, 12 Aug 2016 14:19:35 +0700 Subject: upgrade mocha version to support node v6.x --- package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e3ae5b96..b810d7f9 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "jsdoc": "^3.4.0", "jshint": "0.9.0", "lodash": "^4.6.1", - "mocha": "1.8.x", + "mocha": "^3.0.2", "node-minify": "*", "optimist": "0.3.5", "sinon": "1.4.2", @@ -36,6 +36,5 @@ "vinyl-transform": "0.0.1" }, "license": "MIT", - "main": "index.js", - "dependencies": {} + "main": "index.js" } -- cgit v1.2.3 From bc8ee47acecf2045f9bb4a504cd8494b8a7113e9 Mon Sep 17 00:00:00 2001 From: ChinCluBi Date: Fri, 12 Aug 2016 14:21:05 +0700 Subject: move random image from lorempixel.com to unsplash.com --- lib/image.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++------- test/image.unit.js | 50 ++++++++++++++++++++++++++++++--------------- 2 files changed, 87 insertions(+), 23 deletions(-) diff --git a/lib/image.js b/lib/image.js index 20576d92..ef4c12da 100644 --- a/lib/image.js +++ b/lib/image.js @@ -5,6 +5,8 @@ var Image = function (faker) { var self = this; + var otherCategories = ["abstract", "animals", "business", "cats", "city", "nightlife", "fashion", "sports", "technics", "transport"]; + var unsplashCategories = ["food", "nature", "people", "technology", "objects", "buildings"]; /** * image @@ -15,8 +17,8 @@ var Image = function (faker) { * @method faker.image.image */ self.image = function (width, height, randomize) { - var categories = ["abstract", "animals", "business", "cats", "city", "food", "nightlife", "fashion", "people", "nature", "sports", "technics", "transport"]; - return self[faker.random.arrayElement(categories)](width, height, randomize); + var allCategories = unsplashCategories.concat(otherCategories); + return self[faker.random.arrayElement(allCategories)](width, height, randomize); }; /** * avatar @@ -39,14 +41,25 @@ var Image = function (faker) { var width = width || 640; var height = height || 480; - var url ='http://lorempixel.com/' + width + '/' + height; - if (typeof category !== 'undefined') { - url += '/' + category; + var url ='https://source.unsplash.com'; + + if (typeof category !== 'undefined' && unsplashCategories.indexOf(category) > -1) { + url += '/category/' + category; + } + + url += '/' + width + 'x' + height + + if (typeof category !== 'undefined' && otherCategories.indexOf(category) > -1) { + url += '?' + category } + /* + Current version of unsplash official wrapper(source.unsplash.com) does not support full randomize yet. + I will implement randomize function with official unsplash api in next version. if (randomize) { url += '?' + faker.random.number() } + */ return url; }; @@ -192,7 +205,40 @@ var Image = function (faker) { */ self.transport = function (width, height, randomize) { return faker.image.imageUrl(width, height, 'transport', randomize); - } + }; + /** + * technology + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.technology + */ + self.technology = function (width, height, randomize) { + return faker.image.imageUrl(width, height, 'technology', randomize); + }; + /** + * objects + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.objects + */ + self.objects = function (width, height, randomize) { + return faker.image.imageUrl(width, height, 'objects', randomize); + }; + /** + * buildings + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.buildings + */ + self.buildings = function (width, height, randomize) { + return faker.image.imageUrl(width, height, 'buildings', randomize); + }; } -module["exports"] = Image; \ No newline at end of file +module["exports"] = Image; diff --git a/test/image.unit.js b/test/image.unit.js index e7c7c3c7..a469ba87 100644 --- a/test/image.unit.js +++ b/test/image.unit.js @@ -9,17 +9,17 @@ describe("image.js", function () { it("returns a random image url from lorempixel", function () { var imageUrl = faker.image.imageUrl(); - assert.equal(imageUrl, 'http://lorempixel.com/640/480'); + assert.equal(imageUrl, 'https://source.unsplash.com/640x480'); }); it("returns a random image url from lorempixel with width and height", function () { var imageUrl = faker.image.imageUrl(100, 100); - assert.equal(imageUrl, 'http://lorempixel.com/100/100'); + assert.equal(imageUrl, 'https://source.unsplash.com/100x100'); }); it("returns a random image url for a specified category", function () { var imageUrl = faker.image.imageUrl(100, 100, 'abstract'); - assert.equal(imageUrl, 'http://lorempixel.com/100/100/abstract'); + assert.equal(imageUrl, 'https://source.unsplash.com/100x100?abstract'); }); /* it.only("returns a random image url from lorempixel with a randomizer", function () { @@ -38,79 +38,97 @@ describe("image.js", function () { describe("abstract()", function () { it("returns a random abstract image url", function () { var abstract = faker.image.abstract(); - assert.equal(abstract, 'http://lorempixel.com/640/480/abstract'); + assert.equal(abstract, 'https://source.unsplash.com/640x480?abstract'); }); }); describe("animals()", function () { it("returns a random animals image url", function () { var animals = faker.image.animals(); - assert.equal(animals, 'http://lorempixel.com/640/480/animals'); + assert.equal(animals, 'https://source.unsplash.com/640x480?animals'); }); }); describe("business()", function () { it("returns a random business image url", function () { var business = faker.image.business(); - assert.equal(business, 'http://lorempixel.com/640/480/business'); + assert.equal(business, 'https://source.unsplash.com/640x480?business'); }); }); describe("cats()", function () { it("returns a random cats image url", function () { var cats = faker.image.cats(); - assert.equal(cats, 'http://lorempixel.com/640/480/cats'); + assert.equal(cats, 'https://source.unsplash.com/640x480?cats'); }); }); describe("city()", function () { it("returns a random city image url", function () { var city = faker.image.city(); - assert.equal(city, 'http://lorempixel.com/640/480/city'); + assert.equal(city, 'https://source.unsplash.com/640x480?city'); }); }); describe("food()", function () { it("returns a random food image url", function () { var food = faker.image.food(); - assert.equal(food, 'http://lorempixel.com/640/480/food'); + assert.equal(food, 'https://source.unsplash.com/category/food/640x480'); }); }); describe("nightlife()", function () { it("returns a random nightlife image url", function () { var nightlife = faker.image.nightlife(); - assert.equal(nightlife, 'http://lorempixel.com/640/480/nightlife'); + assert.equal(nightlife, 'https://source.unsplash.com/640x480?nightlife'); }); }); describe("fashion()", function () { it("returns a random fashion image url", function () { var fashion = faker.image.fashion(); - assert.equal(fashion, 'http://lorempixel.com/640/480/fashion'); + assert.equal(fashion, 'https://source.unsplash.com/640x480?fashion'); }); }); describe("people()", function () { it("returns a random people image url", function () { var people = faker.image.people(); - assert.equal(people, 'http://lorempixel.com/640/480/people'); + assert.equal(people, 'https://source.unsplash.com/category/people/640x480'); }); }); describe("nature()", function () { it("returns a random nature image url", function () { var nature = faker.image.nature(); - assert.equal(nature, 'http://lorempixel.com/640/480/nature'); + assert.equal(nature, 'https://source.unsplash.com/category/nature/640x480'); }); }); describe("sports()", function () { it("returns a random sports image url", function () { var sports = faker.image.sports(); - assert.equal(sports, 'http://lorempixel.com/640/480/sports'); + assert.equal(sports, 'https://source.unsplash.com/640x480?sports'); }); }); describe("technics()", function () { it("returns a random technics image url", function () { var technics = faker.image.technics(); - assert.equal(technics, 'http://lorempixel.com/640/480/technics'); + assert.equal(technics, 'https://source.unsplash.com/640x480?technics'); }); }); describe("transport()", function () { it("returns a random transport image url", function () { var transport = faker.image.transport(); - assert.equal(transport, 'http://lorempixel.com/640/480/transport'); + assert.equal(transport, 'https://source.unsplash.com/640x480?transport'); + }); + }); + describe("technology()", function () { + it("returns a random technology image url", function () { + var transport = faker.image.technology(); + assert.equal(transport, 'https://source.unsplash.com/category/technology/640x480'); + }); + }); + describe("objects()", function () { + it("returns a random objects image url", function () { + var transport = faker.image.objects(); + assert.equal(transport, 'https://source.unsplash.com/category/objects/640x480'); + }); + }); + describe("buildings()", function () { + it("returns a random buildings image url", function () { + var transport = faker.image.buildings(); + assert.equal(transport, 'https://source.unsplash.com/category/buildings/640x480'); }); }); }); -- cgit v1.2.3 From 223300a47409ef1a42b0e13aa720646b2ef7a789 Mon Sep 17 00:00:00 2001 From: ChinCluBi Date: Fri, 12 Aug 2016 14:21:48 +0700 Subject: add node v6.x to travis environment --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index db29bd46..3d922b1f 100755 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ sudo: false language: node_js node_js: + - "6" - "5" - "5.1" - "4" -- cgit v1.2.3 From 44bb2b99b133b431fafffc53accb4605797a7162 Mon Sep 17 00:00:00 2001 From: ChinCluBi Date: Tue, 27 Sep 2016 02:40:48 +0700 Subject: rewrite build script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b810d7f9..065ed654 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "scripts": { "lint": "node_modules/.bin/jshint ./lib --config ./.jshintrc", "test": "node_modules/.bin/mocha test/*.*.js", - "build": "cd build && ../node_modules/.bin/gulp && cd ../", + "build": "gulp --gulpfile build/gulpfile.js", "doc": "jsdoc -c conf.json -t ./node_modules/ink-docstrap/template -R README.md lib" }, "devDependencies": { -- cgit v1.2.3 From a130925b97144555856ae3e324bde9dbd7b62748 Mon Sep 17 00:00:00 2001 From: ChinCluBi Date: Tue, 27 Sep 2016 03:19:14 +0700 Subject: include image_provider folder to create a doc --- conf.json | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/conf.json b/conf.json index 24276443..b71600fc 100644 --- a/conf.json +++ b/conf.json @@ -3,6 +3,11 @@ "destination": "../doc/" }, + "source": { + "include": ["lib", "lib/image_providers"], + "exclude": ["lib/locales"] + }, + "plugins": [ "plugins/markdown" ] diff --git a/package.json b/package.json index 065ed654..f9bcc72a 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "lint": "node_modules/.bin/jshint ./lib --config ./.jshintrc", "test": "node_modules/.bin/mocha test/*.*.js", "build": "gulp --gulpfile build/gulpfile.js", - "doc": "jsdoc -c conf.json -t ./node_modules/ink-docstrap/template -R README.md lib" + "doc": "jsdoc -c conf.json -t ./node_modules/ink-docstrap/template -R README.md" }, "devDependencies": { "browserify": "5.11.1", -- cgit v1.2.3 From 87acfc6a5c072cbf00ab02d1cf673d4db7832946 Mon Sep 17 00:00:00 2001 From: ChinCluBi Date: Tue, 27 Sep 2016 03:19:57 +0700 Subject: added lorempixel and unsplash properties to image obj --- lib/image.js | 241 ++-------------------------------- lib/image_providers/lorempixel.js | 199 ++++++++++++++++++++++++++++ lib/image_providers/unsplash.js | 129 ++++++++++++++++++ test/image.unit.js | 270 ++++++++++++++++++++++---------------- 4 files changed, 497 insertions(+), 342 deletions(-) create mode 100644 lib/image_providers/lorempixel.js create mode 100644 lib/image_providers/unsplash.js diff --git a/lib/image.js b/lib/image.js index ef4c12da..f64b1545 100644 --- a/lib/image.js +++ b/lib/image.js @@ -1,244 +1,23 @@ /** * * @namespace faker.image + * @property {object} lorempixel - faker.image.lorempixel + * @property {object} unsplash - faker.image.unsplash + * @default Default provider is unsplash image provider */ var Image = function (faker) { - var self = this; - var otherCategories = ["abstract", "animals", "business", "cats", "city", "nightlife", "fashion", "sports", "technics", "transport"]; - var unsplashCategories = ["food", "nature", "people", "technology", "objects", "buildings"]; + var self = this + var Lorempixel = require('./image_providers/lorempixel'); + var Unsplash = require('./image_providers/unsplash'); - /** - * image - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.image - */ - self.image = function (width, height, randomize) { - var allCategories = unsplashCategories.concat(otherCategories); - return self[faker.random.arrayElement(allCategories)](width, height, randomize); - }; - /** - * avatar - * - * @method faker.image.avatar - */ - self.avatar = function () { - return faker.internet.avatar(); - }; - /** - * imageUrl - * - * @param {number} width - * @param {number} height - * @param {string} category - * @param {boolean} randomize - * @method faker.image.imageUrl - */ - self.imageUrl = function (width, height, category, randomize) { - var width = width || 640; - var height = height || 480; - var url ='https://source.unsplash.com'; + self.lorempixel = new Lorempixel(faker); + self.unsplash = new Unsplash(faker); - if (typeof category !== 'undefined' && unsplashCategories.indexOf(category) > -1) { - url += '/category/' + category; - } - - url += '/' + width + 'x' + height - - if (typeof category !== 'undefined' && otherCategories.indexOf(category) > -1) { - url += '?' + category - } + Object.assign(self, self.unsplash); +} - /* - Current version of unsplash official wrapper(source.unsplash.com) does not support full randomize yet. - I will implement randomize function with official unsplash api in next version. - if (randomize) { - url += '?' + faker.random.number() - } - */ - return url; - }; - /** - * abstract - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.abstract - */ - self.abstract = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'abstract', randomize); - }; - /** - * animals - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.animals - */ - self.animals = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'animals', randomize); - }; - /** - * business - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.business - */ - self.business = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'business', randomize); - }; - /** - * cats - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.cats - */ - self.cats = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'cats', randomize); - }; - /** - * city - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.city - */ - self.city = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'city', randomize); - }; - /** - * food - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.food - */ - self.food = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'food', randomize); - }; - /** - * nightlife - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.nightlife - */ - self.nightlife = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'nightlife', randomize); - }; - /** - * fashion - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.fashion - */ - self.fashion = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'fashion', randomize); - }; - /** - * people - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.people - */ - self.people = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'people', randomize); - }; - /** - * nature - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.nature - */ - self.nature = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'nature', randomize); - }; - /** - * sports - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.sports - */ - self.sports = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'sports', randomize); - }; - /** - * technics - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.technics - */ - self.technics = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'technics', randomize); - }; - /** - * transport - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.transport - */ - self.transport = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'transport', randomize); - }; - /** - * technology - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.technology - */ - self.technology = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'technology', randomize); - }; - /** - * objects - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.objects - */ - self.objects = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'objects', randomize); - }; - /** - * buildings - * - * @param {number} width - * @param {number} height - * @param {boolean} randomize - * @method faker.image.buildings - */ - self.buildings = function (width, height, randomize) { - return faker.image.imageUrl(width, height, 'buildings', randomize); - }; -} module["exports"] = Image; diff --git a/lib/image_providers/lorempixel.js b/lib/image_providers/lorempixel.js new file mode 100644 index 00000000..44c0e007 --- /dev/null +++ b/lib/image_providers/lorempixel.js @@ -0,0 +1,199 @@ +/** + * + * @namespace lorempixel + * @memberof faker.image + */ +var Lorempixel = function (faker) { + + var self = this; + + /** + * image + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.image + */ + self.image = function (width, height, randomize) { + var categories = ["abstract", "animals", "business", "cats", "city", "food", "nightlife", "fashion", "people", "nature", "sports", "technics", "transport"]; + return self[faker.random.arrayElement(categories)](width, height, randomize); + }; + /** + * avatar + * + * @method faker.image.lorempixel.avatar + */ + self.avatar = function () { + return faker.internet.avatar(); + }; + /** + * imageUrl + * + * @param {number} width + * @param {number} height + * @param {string} category + * @param {boolean} randomize + * @method faker.image.lorempixel.imageUrl + */ + self.imageUrl = function (width, height, category, randomize) { + var width = width || 640; + var height = height || 480; + + var url ='http://lorempixel.com/' + width + '/' + height; + if (typeof category !== 'undefined') { + url += '/' + category; + } + + if (randomize) { + url += '?' + faker.random.number() + } + + return url; + }; + /** + * abstract + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.abstract + */ + self.abstract = function (width, height, randomize) { + return faker.image.lorempixel.imageUrl(width, height, 'abstract', randomize); + }; + /** + * animals + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.animals + */ + self.animals = function (width, height, randomize) { + return faker.image.lorempixel.imageUrl(width, height, 'animals', randomize); + }; + /** + * business + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.business + */ + self.business = function (width, height, randomize) { + return faker.image.lorempixel.imageUrl(width, height, 'business', randomize); + }; + /** + * cats + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.cats + */ + self.cats = function (width, height, randomize) { + return faker.image.lorempixel.imageUrl(width, height, 'cats', randomize); + }; + /** + * city + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.city + */ + self.city = function (width, height, randomize) { + return faker.image.lorempixel.imageUrl(width, height, 'city', randomize); + }; + /** + * food + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.food + */ + self.food = function (width, height, randomize) { + return faker.image.lorempixel.imageUrl(width, height, 'food', randomize); + }; + /** + * nightlife + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.nightlife + */ + self.nightlife = function (width, height, randomize) { + return faker.image.lorempixel.imageUrl(width, height, 'nightlife', randomize); + }; + /** + * fashion + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.fashion + */ + self.fashion = function (width, height, randomize) { + return faker.image.lorempixel.imageUrl(width, height, 'fashion', randomize); + }; + /** + * people + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.people + */ + self.people = function (width, height, randomize) { + return faker.image.lorempixel.imageUrl(width, height, 'people', randomize); + }; + /** + * nature + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.nature + */ + self.nature = function (width, height, randomize) { + return faker.image.lorempixel.imageUrl(width, height, 'nature', randomize); + }; + /** + * sports + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.sports + */ + self.sports = function (width, height, randomize) { + return faker.image.lorempixel.imageUrl(width, height, 'sports', randomize); + }; + /** + * technics + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.technics + */ + self.technics = function (width, height, randomize) { + return faker.image.lorempixel.imageUrl(width, height, 'technics', randomize); + }; + /** + * transport + * + * @param {number} width + * @param {number} height + * @param {boolean} randomize + * @method faker.image.lorempixel.transport + */ + self.transport = function (width, height, randomize) { + return faker.image.lorempixel.imageUrl(width, height, 'transport', randomize); + } +} + +module["exports"] = Lorempixel; diff --git a/lib/image_providers/unsplash.js b/lib/image_providers/unsplash.js new file mode 100644 index 00000000..75d0d453 --- /dev/null +++ b/lib/image_providers/unsplash.js @@ -0,0 +1,129 @@ +/** + * + * @namespace unsplash + * @memberof faker.image + */ +var Unsplash = function (faker) { + + var self = this; + var categories = ["food", "nature", "people", "technology", "objects", "buildings"]; + + /** + * image + * + * @param {number} width + * @param {number} height + * @param {string} keyword + * @method faker.image.unsplash.image + * @description search image from unsplash + */ + self.image = function (width, height, keyword) { + return self.imageUrl(width, height, undefined, keyword); + }; + /** + * avatar + * + * @method faker.image.unsplash.avatar + */ + self.avatar = function () { + return faker.internet.avatar(); + }; + /** + * imageUrl + * + * @param {number} width + * @param {number} height + * @param {string} category + * @param {string} keyword + * @method faker.image.unsplash.imageUrl + */ + self.imageUrl = function (width, height, category, keyword) { + var width = width || 640; + var height = height || 480; + + var url ='https://source.unsplash.com'; + + if (typeof category !== 'undefined') { + url += '/category/' + category; + } + + url += '/' + width + 'x' + height; + + if (typeof keyword !== 'undefined') { + var keywordFormat = new RegExp('^([A-Za-z0-9].+,[A-Za-z0-9]+)$|^([A-Za-z0-9]+)$'); + if (keywordFormat.test(keyword)) { + url += '?' + keyword; + } + } + + return url; + }; + /** + * food + * + * @param {number} width + * @param {number} height + * @param {string} keyword + * @method faker.image.unsplash.food + */ + self.food = function (width, height, keyword) { + return faker.image.imageUrl(width, height, 'food', keyword); + }; + /** + * people + * + * @param {number} width + * @param {number} height + * @param {string} keyword + * @method faker.image.unsplash.people + */ + self.people = function (width, height, keyword) { + return faker.image.imageUrl(width, height, 'people', keyword); + }; + /** + * nature + * + * @param {number} width + * @param {number} height + * @param {string} keyword + * @method faker.image.unsplash.nature + */ + self.nature = function (width, height, keyword) { + return faker.image.imageUrl(width, height, 'nature', keyword); + }; + /** + * technology + * + * @param {number} width + * @param {number} height + * @param {string} keyword + * @method faker.image.unsplash.technology + */ + self.technology = function (width, height, keyword) { + return faker.image.imageUrl(width, height, 'technology', keyword); + }; + /** + * objects + * + * @param {number} width + * @param {number} height + * @param {string} keyword + * @method faker.image.unsplash.objects + */ + self.objects = function (width, height, keyword) { + return faker.image.imageUrl(width, height, 'objects', keyword); + }; + /** + * buildings + * + * @param {number} width + * @param {number} height + * @param {string} keyword + * @method faker.image.unsplash.buildings + */ + self.buildings = function (width, height, keyword) { + return faker.image.imageUrl(width, height, 'buildings', keyword); + }; +} + +module["exports"] = Unsplash; diff --git a/test/image.unit.js b/test/image.unit.js index a469ba87..d0d9a96e 100644 --- a/test/image.unit.js +++ b/test/image.unit.js @@ -5,130 +5,178 @@ if (typeof module !== 'undefined') { } describe("image.js", function () { - describe("imageUrl()", function () { + describe("lorempixel", function() { + describe("imageUrl()", function () { it("returns a random image url from lorempixel", function () { + var imageUrl = faker.image.lorempixel.imageUrl(); + + assert.equal(imageUrl, 'http://lorempixel.com/640/480'); + }); + it("returns a random image url from lorempixel with width and height", function () { + var imageUrl = faker.image.lorempixel.imageUrl(100, 100); + + assert.equal(imageUrl, 'http://lorempixel.com/100/100'); + }); + it("returns a random image url for a specified category", function () { + var imageUrl = faker.image.lorempixel.imageUrl(100, 100, 'abstract'); + + assert.equal(imageUrl, 'http://lorempixel.com/100/100/abstract'); + }); + }); + describe("avatar()", function () { + it("return a random avatar from UIFaces", function () { + assert.notEqual(-1, faker.image.lorempixel.avatar().indexOf('s3.amazonaws.com/uifaces/faces')); + }) + }); + describe("abstract()", function () { + it("returns a random abstract image url", function () { + var abstract = faker.image.lorempixel.abstract(); + assert.equal(abstract, 'http://lorempixel.com/640/480/abstract'); + }); + }); + describe("animals()", function () { + it("returns a random animals image url", function () { + var animals = faker.image.lorempixel.animals(); + assert.equal(animals, 'http://lorempixel.com/640/480/animals'); + }); + }); + describe("business()", function () { + it("returns a random business image url", function () { + var business = faker.image.lorempixel.business(); + assert.equal(business, 'http://lorempixel.com/640/480/business'); + }); + }); + describe("cats()", function () { + it("returns a random cats image url", function () { + var cats = faker.image.lorempixel.cats(); + assert.equal(cats, 'http://lorempixel.com/640/480/cats'); + }); + }); + describe("city()", function () { + it("returns a random city image url", function () { + var city = faker.image.lorempixel.city(); + assert.equal(city, 'http://lorempixel.com/640/480/city'); + }); + }); + describe("food()", function () { + it("returns a random food image url", function () { + var food = faker.image.lorempixel.food(); + assert.equal(food, 'http://lorempixel.com/640/480/food'); + }); + }); + describe("nightlife()", function () { + it("returns a random nightlife image url", function () { + var nightlife = faker.image.lorempixel.nightlife(); + assert.equal(nightlife, 'http://lorempixel.com/640/480/nightlife'); + }); + }); + describe("fashion()", function () { + it("returns a random fashion image url", function () { + var fashion = faker.image.lorempixel.fashion(); + assert.equal(fashion, 'http://lorempixel.com/640/480/fashion'); + }); + }); + describe("people()", function () { + it("returns a random people image url", function () { + var people = faker.image.lorempixel.people(); + assert.equal(people, 'http://lorempixel.com/640/480/people'); + }); + }); + describe("nature()", function () { + it("returns a random nature image url", function () { + var nature = faker.image.lorempixel.nature(); + assert.equal(nature, 'http://lorempixel.com/640/480/nature'); + }); + }); + describe("sports()", function () { + it("returns a random sports image url", function () { + var sports = faker.image.lorempixel.sports(); + assert.equal(sports, 'http://lorempixel.com/640/480/sports'); + }); + }); + describe("technics()", function () { + it("returns a random technics image url", function () { + var technics = faker.image.lorempixel.technics(); + assert.equal(technics, 'http://lorempixel.com/640/480/technics'); + }); + }); + describe("transport()", function () { + it("returns a random transport image url", function () { + var transport = faker.image.lorempixel.transport(); + assert.equal(transport, 'http://lorempixel.com/640/480/transport'); + }); + }); + }); + + describe("unsplash", function() { + describe("imageUrl()", function () { + it("returns a random image url from unsplash", function () { var imageUrl = faker.image.imageUrl(); assert.equal(imageUrl, 'https://source.unsplash.com/640x480'); }); - it("returns a random image url from lorempixel with width and height", function () { + it("returns a random image url from unsplash with width and height", function () { var imageUrl = faker.image.imageUrl(100, 100); assert.equal(imageUrl, 'https://source.unsplash.com/100x100'); }); it("returns a random image url for a specified category", function () { - var imageUrl = faker.image.imageUrl(100, 100, 'abstract'); + var imageUrl = faker.image.imageUrl(100, 100, 'food'); - assert.equal(imageUrl, 'https://source.unsplash.com/100x100?abstract'); + assert.equal(imageUrl, 'https://source.unsplash.com/category/food/100x100'); }); - /* - it.only("returns a random image url from lorempixel with a randomizer", function () { - var imageUrl = faker.image.imageUrl(100, 100, undefined, true); + it("returns a random image url with correct keywords for a specified category", function () { + var imageUrl = faker.image.imageUrl(100, 100, 'food', 'keyword1,keyword2'); - console.log(imageUrl); - assert.ok(imageUrl.match(/^http:\/\/lorempixel.com\/100\/100\?[\d]+$/)); - }); - */ - }); - describe("avatar()", function () { - it("return a random avatar from UIFaces", function () { - assert.notEqual(-1, faker.image.avatar().indexOf('s3.amazonaws.com/uifaces/faces')); - }) - }); - describe("abstract()", function () { - it("returns a random abstract image url", function () { - var abstract = faker.image.abstract(); - assert.equal(abstract, 'https://source.unsplash.com/640x480?abstract'); - }); - }); - describe("animals()", function () { - it("returns a random animals image url", function () { - var animals = faker.image.animals(); - assert.equal(animals, 'https://source.unsplash.com/640x480?animals'); - }); - }); - describe("business()", function () { - it("returns a random business image url", function () { - var business = faker.image.business(); - assert.equal(business, 'https://source.unsplash.com/640x480?business'); - }); - }); - describe("cats()", function () { - it("returns a random cats image url", function () { - var cats = faker.image.cats(); - assert.equal(cats, 'https://source.unsplash.com/640x480?cats'); - }); - }); - describe("city()", function () { - it("returns a random city image url", function () { - var city = faker.image.city(); - assert.equal(city, 'https://source.unsplash.com/640x480?city'); - }); - }); - describe("food()", function () { - it("returns a random food image url", function () { - var food = faker.image.food(); - assert.equal(food, 'https://source.unsplash.com/category/food/640x480'); - }); - }); - describe("nightlife()", function () { - it("returns a random nightlife image url", function () { - var nightlife = faker.image.nightlife(); - assert.equal(nightlife, 'https://source.unsplash.com/640x480?nightlife'); - }); - }); - describe("fashion()", function () { - it("returns a random fashion image url", function () { - var fashion = faker.image.fashion(); - assert.equal(fashion, 'https://source.unsplash.com/640x480?fashion'); - }); - }); - describe("people()", function () { - it("returns a random people image url", function () { - var people = faker.image.people(); - assert.equal(people, 'https://source.unsplash.com/category/people/640x480'); - }); - }); - describe("nature()", function () { - it("returns a random nature image url", function () { - var nature = faker.image.nature(); - assert.equal(nature, 'https://source.unsplash.com/category/nature/640x480'); - }); - }); - describe("sports()", function () { - it("returns a random sports image url", function () { - var sports = faker.image.sports(); - assert.equal(sports, 'https://source.unsplash.com/640x480?sports'); - }); - }); - describe("technics()", function () { - it("returns a random technics image url", function () { - var technics = faker.image.technics(); - assert.equal(technics, 'https://source.unsplash.com/640x480?technics'); - }); - }); - describe("transport()", function () { - it("returns a random transport image url", function () { - var transport = faker.image.transport(); - assert.equal(transport, 'https://source.unsplash.com/640x480?transport'); - }); - }); - describe("technology()", function () { - it("returns a random technology image url", function () { - var transport = faker.image.technology(); - assert.equal(transport, 'https://source.unsplash.com/category/technology/640x480'); - }); - }); - describe("objects()", function () { - it("returns a random objects image url", function () { - var transport = faker.image.objects(); - assert.equal(transport, 'https://source.unsplash.com/category/objects/640x480'); - }); - }); - describe("buildings()", function () { - it("returns a random buildings image url", function () { - var transport = faker.image.buildings(); - assert.equal(transport, 'https://source.unsplash.com/category/buildings/640x480'); + assert.equal(imageUrl, 'https://source.unsplash.com/category/food/100x100?keyword1,keyword2'); }); + it("returns a random image url without keyword which format is wrong for a specified category", function () { + var imageUrl = faker.image.imageUrl(100, 100, 'food', 'keyword1,?ds)0123$*908932409'); + + assert.equal(imageUrl, 'https://source.unsplash.com/category/food/100x100'); + }); + }); + describe("image()", function() { + it("returns a searching image url with keyword", function () { + var food = faker.image.image(100, 200, 'keyword1,keyword2,keyword3'); + assert.equal(food, 'https://source.unsplash.com/100x200?keyword1,keyword2,keyword3'); + }); + }) + describe("food()", function () { + it("returns a random food image url", function () { + var food = faker.image.food(); + assert.equal(food, 'https://source.unsplash.com/category/food/640x480'); + }); + }); + describe("people()", function () { + it("returns a random people image url", function () { + var people = faker.image.people(); + assert.equal(people, 'https://source.unsplash.com/category/people/640x480'); + }); + }); + describe("nature()", function () { + it("returns a random nature image url", function () { + var nature = faker.image.nature(); + assert.equal(nature, 'https://source.unsplash.com/category/nature/640x480'); + }); + }); + describe("technology()", function () { + it("returns a random technology image url", function () { + var transport = faker.image.technology(); + assert.equal(transport, 'https://source.unsplash.com/category/technology/640x480'); + }); + }); + describe("objects()", function () { + it("returns a random objects image url", function () { + var transport = faker.image.objects(); + assert.equal(transport, 'https://source.unsplash.com/category/objects/640x480'); + }); + }); + describe("buildings()", function () { + it("returns a random buildings image url", function () { + var transport = faker.image.buildings(); + assert.equal(transport, 'https://source.unsplash.com/category/buildings/640x480'); + }); + }); }); }); -- cgit v1.2.3 From 267d8f41d0a104f4613a23165a2264e87dc9594b Mon Sep 17 00:00:00 2001 From: ChinCluBi Date: Tue, 27 Sep 2016 03:27:59 +0700 Subject: remove object.assign.fix unit test --- lib/image.js | 3 ++- test/image.unit.js | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/image.js b/lib/image.js index f64b1545..9ac21ce2 100644 --- a/lib/image.js +++ b/lib/image.js @@ -15,7 +15,8 @@ var Image = function (faker) { self.lorempixel = new Lorempixel(faker); self.unsplash = new Unsplash(faker); - Object.assign(self, self.unsplash); + // Object.assign(self, self.unsplash); + // How to set default as unsplash? should be image.default? } diff --git a/test/image.unit.js b/test/image.unit.js index d0d9a96e..95d18ab5 100644 --- a/test/image.unit.js +++ b/test/image.unit.js @@ -111,70 +111,70 @@ describe("image.js", function () { describe("unsplash", function() { describe("imageUrl()", function () { it("returns a random image url from unsplash", function () { - var imageUrl = faker.image.imageUrl(); + var imageUrl = faker.image.unsplash.imageUrl(); assert.equal(imageUrl, 'https://source.unsplash.com/640x480'); }); it("returns a random image url from unsplash with width and height", function () { - var imageUrl = faker.image.imageUrl(100, 100); + var imageUrl = faker.image.unsplash.imageUrl(100, 100); assert.equal(imageUrl, 'https://source.unsplash.com/100x100'); }); it("returns a random image url for a specified category", function () { - var imageUrl = faker.image.imageUrl(100, 100, 'food'); + var imageUrl = faker.image.unsplash.imageUrl(100, 100, 'food'); assert.equal(imageUrl, 'https://source.unsplash.com/category/food/100x100'); }); it("returns a random image url with correct keywords for a specified category", function () { - var imageUrl = faker.image.imageUrl(100, 100, 'food', 'keyword1,keyword2'); + var imageUrl = faker.image.unsplash.imageUrl(100, 100, 'food', 'keyword1,keyword2'); assert.equal(imageUrl, 'https://source.unsplash.com/category/food/100x100?keyword1,keyword2'); }); it("returns a random image url without keyword which format is wrong for a specified category", function () { - var imageUrl = faker.image.imageUrl(100, 100, 'food', 'keyword1,?ds)0123$*908932409'); + var imageUrl = faker.image.unsplash.imageUrl(100, 100, 'food', 'keyword1,?ds)0123$*908932409'); assert.equal(imageUrl, 'https://source.unsplash.com/category/food/100x100'); }); }); describe("image()", function() { it("returns a searching image url with keyword", function () { - var food = faker.image.image(100, 200, 'keyword1,keyword2,keyword3'); + var food = faker.image.unsplash.image(100, 200, 'keyword1,keyword2,keyword3'); assert.equal(food, 'https://source.unsplash.com/100x200?keyword1,keyword2,keyword3'); }); }) describe("food()", function () { it("returns a random food image url", function () { - var food = faker.image.food(); + var food = faker.image.unsplash.food(); assert.equal(food, 'https://source.unsplash.com/category/food/640x480'); }); }); describe("people()", function () { it("returns a random people image url", function () { - var people = faker.image.people(); + var people = faker.image.unsplash.people(); assert.equal(people, 'https://source.unsplash.com/category/people/640x480'); }); }); describe("nature()", function () { it("returns a random nature image url", function () { - var nature = faker.image.nature(); + var nature = faker.image.unsplash.nature(); assert.equal(nature, 'https://source.unsplash.com/category/nature/640x480'); }); }); describe("technology()", function () { it("returns a random technology image url", function () { - var transport = faker.image.technology(); + var transport = faker.image.unsplash.technology(); assert.equal(transport, 'https://source.unsplash.com/category/technology/640x480'); }); }); describe("objects()", function () { it("returns a random objects image url", function () { - var transport = faker.image.objects(); + var transport = faker.image.unsplash.objects(); assert.equal(transport, 'https://source.unsplash.com/category/objects/640x480'); }); }); describe("buildings()", function () { it("returns a random buildings image url", function () { - var transport = faker.image.buildings(); + var transport = faker.image.unsplash.buildings(); assert.equal(transport, 'https://source.unsplash.com/category/buildings/640x480'); }); }); -- cgit v1.2.3 From 900f3d87cbfd9b86119c4505e3b9dc1e84ea5969 Mon Sep 17 00:00:00 2001 From: ChinCluBi Date: Tue, 27 Sep 2016 03:30:37 +0700 Subject: fix bug unsplash object --- lib/image_providers/unsplash.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/image_providers/unsplash.js b/lib/image_providers/unsplash.js index 75d0d453..514fe84c 100644 --- a/lib/image_providers/unsplash.js +++ b/lib/image_providers/unsplash.js @@ -67,7 +67,7 @@ var Unsplash = function (faker) { * @method faker.image.unsplash.food */ self.food = function (width, height, keyword) { - return faker.image.imageUrl(width, height, 'food', keyword); + return faker.image.unsplash.imageUrl(width, height, 'food', keyword); }; /** * people @@ -78,7 +78,7 @@ var Unsplash = function (faker) { * @method faker.image.unsplash.people */ self.people = function (width, height, keyword) { - return faker.image.imageUrl(width, height, 'people', keyword); + return faker.image.unsplash.imageUrl(width, height, 'people', keyword); }; /** * nature @@ -89,7 +89,7 @@ var Unsplash = function (faker) { * @method faker.image.unsplash.nature */ self.nature = function (width, height, keyword) { - return faker.image.imageUrl(width, height, 'nature', keyword); + return faker.image.unsplash.imageUrl(width, height, 'nature', keyword); }; /** * technology @@ -100,7 +100,7 @@ var Unsplash = function (faker) { * @method faker.image.unsplash.technology */ self.technology = function (width, height, keyword) { - return faker.image.imageUrl(width, height, 'technology', keyword); + return faker.image.unsplash.imageUrl(width, height, 'technology', keyword); }; /** * objects @@ -111,7 +111,7 @@ var Unsplash = function (faker) { * @method faker.image.unsplash.objects */ self.objects = function (width, height, keyword) { - return faker.image.imageUrl(width, height, 'objects', keyword); + return faker.image.unsplash.imageUrl(width, height, 'objects', keyword); }; /** * buildings @@ -122,7 +122,7 @@ var Unsplash = function (faker) { * @method faker.image.unsplash.buildings */ self.buildings = function (width, height, keyword) { - return faker.image.imageUrl(width, height, 'buildings', keyword); + return faker.image.unsplash.imageUrl(width, height, 'buildings', keyword); }; } -- cgit v1.2.3