Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix #2760

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Bug fix #2760

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
*
* @author Vinit Shahdeo <https://github.com/vinitshahdeo>
*/
const arr = require('../data/data.json'),
import arr from './data.json' assert {type: 'json'}

// utility to generate a random number
randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1) + min),
let randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1) + min),
index = randomInt(0, arr.length), // random index to be used

/**
Expand All @@ -23,14 +23,16 @@ const arr = require('../data/data.json'),
* To hide author, pass options as { author: false }
*/
getQuote = (options) => {
randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1) + min),
index = randomInt(0, arr.length), // random index to be used
!options && (options = {author: true}); // default option
return {
text: arr[index].text,
...(options && options.author ? { author: arr[index].from } : {})
};
};

module.exports = {
export {
getRandomQuote,
getQuote
};