Skip to content

Commit

Permalink
Basic API working
Browse files Browse the repository at this point in the history
  • Loading branch information
siakaramalegos committed May 28, 2019
1 parent a7119bb commit 0868c19
Show file tree
Hide file tree
Showing 6 changed files with 411 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
32 changes: 29 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
function helloCoderIpsum() {
console.log('Coder Ipsum worked')
const sampleSize =require('lodash/sampleSize')
const words = require('./words.json')

function getRandomInt(min = 3, max = 5) {
return Math.floor(Math.random() * (max - min + 1)) + min
}

// Returns a String of a set of unformatted coder ipsum "words". Note that some words are more than one word like "Lil' Bobby Tables".
function phrase(numWords = getRandomInt(6, 10)) {
return sampleSize(words, numWords).join(' ')
}

// Returns a String of a set of coder ipsum "words" in the format of a sentence - with capitalization and period punctionation. Note that some words are more than one word like "Lil' Bobby Tables".
function sentence(numWords = getRandomInt(6, 10)) {
const unformatted = phrase(numWords)
return unformatted.charAt(0).toUpperCase() + unformatted.slice(1) + '.'
}

// Returns a String of a set of coder ipsum "words" in the format of a paragraph with multiple sentences - with capitalization and period punctionation. Note that some words are more than one word like "Lil' Bobby Tables".
function paragraph(numSentences = getRandomInt(3, 5)) {
const sentenceArray = new Array(numSentences).fill().map(element => {
return sentence()
})
return sentenceArray.join(' ')
}

module.exports = helloCoderIpsum()
module.exports = {
phrase,
sentence,
paragraph
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"ipsum"
],
"author": "Sia Karamalegos",
"license": "MIT"
"license": "MIT",
"dependencies": {
"lodash": "^4.17.11"
}
}
19 changes: 19 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const coderIpsum = require('./index')

console.log("Invoking phrase with no number of words set...");
console.log(coderIpsum.phrase());

console.log("Invoking phrases of 5 words...");
console.log(coderIpsum.phrase(5));

console.log("Invoking sentence with no length set...");
console.log(coderIpsum.sentence());

console.log("Invoking sentence with 8 words...");
console.log(coderIpsum.sentence(8));

console.log("Invoking paragraph with no length set...");
console.log(coderIpsum.paragraph());

console.log("Invoking paragraph with 2 sentences...");
console.log(coderIpsum.paragraph(2));
Loading

0 comments on commit 0868c19

Please sign in to comment.