Comparing version 1.0.0 to 1.1.0
29
index.js
var quotes = require('./data').quotes | ||
function getAQuote () { | ||
var pick = Math.floor(Math.random() * quotes.length) | ||
function getAQuote (idx) { | ||
var pick = idx || Math.floor(Math.random() * quotes.length) | ||
return quotes[pick] | ||
} | ||
module.exports = function(num) { | ||
function formatter (quote, opts) { | ||
if (opts.textOnly) return quote.text | ||
return quote | ||
} | ||
module.exports = exports = function(num, opts) { | ||
if (!opts && typeof num === 'object') { | ||
opts = num | ||
num = 1 | ||
} | ||
num = Math.floor(+num || 1) | ||
if (num === 1) return getAQuote() | ||
opts = Object(opts) | ||
if (num === 1) return formatter(getAQuote(), opts) | ||
var quotes = [] | ||
for (var i = 1; i <= num; i++) { | ||
quotes.push(getAQuote()) | ||
quotes.push(formatter(getAQuote(), opts)) | ||
} | ||
return quotes | ||
} | ||
exports.daily = function(opts) { | ||
opts = Object(opts) | ||
var now = new Date() | ||
, beginningOfDay = (new Date(now.getFullYear(), now.getMonth(), now.getDate())) / 1000 | ||
return formatter(getAQuote(beginningOfDay % quotes.length), opts) | ||
} |
{ | ||
"name": "barth", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Helpful Karl Barth quotes.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# barth | ||
Helpful Karl Barth quotes. | ||
[![NPM](https://nodei.co/npm/barth.png?downloads=true)](https://nodei.co/npm/barth/) | ||
## CLI | ||
@@ -16,5 +18,16 @@ ``` | ||
## Usage | ||
```barth([num [, options]])``` | ||
``` | ||
var barth = require('barth') | ||
barth() | ||
barth() // => {text: 'A quote.'} | ||
barth(3) // => [{text: 'An array of 3 quotes.'},{...},{...}] | ||
barth({textOnly: true}) // => 'Only the quote text will be returned.' | ||
``` | ||
```barth.daily([options])``` | ||
``` | ||
barth.daily() // => '{text: 'A quote that will show all day long.}' | ||
barth.daily({textOnly: true}) // => 'A quote that shows all day long.' | ||
``` |
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
18403
203
33