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 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 7 deletions(-) (limited to 'lib/image.js') 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; -- 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 +++-------------------------------------------------------- 1 file changed, 10 insertions(+), 231 deletions(-) (limited to 'lib/image.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; -- 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 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/image.js') 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? } -- cgit v1.2.3