random-puppy
Advanced tools
Comparing version 1.0.0 to 1.0.1
20
index.js
@@ -23,3 +23,3 @@ 'use strict'; | ||
module.exports = function (subreddit) { | ||
function randomPuppy(subreddit) { | ||
subreddit = (typeof subreddit === 'string' && subreddit.length !== 0) ? subreddit : 'puppies'; | ||
@@ -34,2 +34,20 @@ | ||
.then(getRandomImage => formatResult(getRandomImage)); | ||
} | ||
function callback(subreddit, cb) { | ||
randomPuppy(subreddit) | ||
.then(url => cb(null, url)) | ||
.catch(err => cb(err)); | ||
} | ||
// subreddit is optional | ||
// callback support is provided for a training exercise | ||
module.exports = (subreddit, cb) => { | ||
if (typeof cb === 'function') { | ||
callback(subreddit, cb); | ||
} else if (typeof subreddit === 'function') { | ||
callback(null, subreddit); | ||
} else { | ||
return randomPuppy(subreddit); | ||
} | ||
}; |
{ | ||
"name": "random-puppy", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Get a random puppy image url.", | ||
@@ -22,3 +22,8 @@ "license": "MIT", | ||
"keywords": [ | ||
"puppy", "doggie", "dog", "imgur", "random", "placeholder" | ||
"puppy", | ||
"doggie", | ||
"dog", | ||
"imgur", | ||
"random", | ||
"placeholder" | ||
], | ||
@@ -25,0 +30,0 @@ "dependencies": { |
4239
41