Skip to content

Commit

Permalink
Merge new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
diegofelipece committed Jul 8, 2019
2 parents 8b3609b + fab55f5 commit aa517a6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ pNum | Number | 1 | Number of paragraphs requested
quotes | Array | mussumQuotes | Array of quotes to generate paragraphs
mainQuote | String | mussumMainQuote | Main quote to start your "Lorem Ipsum"
genLimit | Number | 1000 | Limit of paragraphs that can be requested
resultType | String | `'html'` | Format of the response, choose between: `'html'` or `'text'`
tagBefore | String | `'<p>'` | Anything you want to put before each paragraph
tagAfter | String | `'</p>'` | Anything you want to put after each paragraph
resultType | String | `'html'` | Format of the response, choose between: `'html'`, `'text'` or `'array'`
tagBefore | String | `'<p>'` | Anything you want to put before each paragraph (valid only with `'html'` resultType)
tagAfter | String | `'</p>'` | Anything you want to put after each paragraph (valid only with `'html'` resultType)
pQuotes | Number | 4 | Number of quotes used to build a paragraph

The options can be set on an object passed as a parameter, like the example below:
Expand Down
5 changes: 3 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ <h3>Using a select to manipulate other custom options</h3>
<select class="form-control" id="customKind">
<option value="html">html</option>
<option value="text">text</option>
<option value="array">array</option>
</select>
</div>
<div class="form-group">
Expand Down Expand Up @@ -181,7 +182,7 @@ <h3>Using a select to manipulate other custom options</h3>
<script src="vendors/bootstrap.min.js"></script>
<link rel="stylesheet" href="vendors/highlight.min.css">
<script src="vendors/highlight.min.js"></script>
<script src="../dist/mipsum.min.js"></script>
<script src="../dist/mipsum.js"></script>

<!-- Calls for mIpsum.js -->
<script type="text/javascript">
Expand Down Expand Up @@ -259,7 +260,7 @@ <h3>Using a select to manipulate other custom options</h3>
quotes: olbaDioblaDa,
mainQuote: beatlesIpsum,
tagBefore: '<h1>',
tagAfter: '</h1>'
tagAfter: '</h1>',
});
console.log(customIpsum);
$('#customIpsum').html(customIpsum);
Expand Down
20 changes: 11 additions & 9 deletions src/lib/mipsum.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class MussumIpsum {
tempParagraphs.push(this.createOneParagraph())
}

tempParagraphs.forEach((paragraph, i) => { if (options.pNum > i) paragraphs.push(paragraph) })
tempParagraphs.forEach((paragraph, i) => (options.pNum > i) && paragraphs.push(paragraph))
return paragraphs
}

Expand All @@ -43,7 +43,7 @@ export class MussumIpsum {
const thisPosition = (
Math.round(Math.random() * (randomLimit - 1) + 1) - 1
) // get a random position
singleParagraph += `${tempQuotes[thisPosition]} ` // append the quote on a temp string
singleParagraph += `${tempQuotes[thisPosition]}` // append the quote on a temp string
tempQuotes.splice(thisPosition, 1) // exlude the used value for the array
randomLimit -= 1 // decrease max getRandomNumber
}
Expand All @@ -56,14 +56,16 @@ export class MussumIpsum {
const { _options: options } = this
const paragraphs = recievedParagraphs

let response = ''
paragraphs[0] = `${options.mainQuote} ${paragraphs[0]}` // add the initial quote
// add the initial quote
paragraphs[0] = `${options.mainQuote} ${paragraphs[0]}`

paragraphs.forEach((paragraph) => {
response += (options.resultType === 'html') ? `${options.tagBefore}${paragraph}${options.tagAfter}` : `${paragraph} \n\n`
})

return response
return (options.resultType === 'array')
? paragraphs
: paragraphs.reduce((response, paragraph) => (
(options.resultType === 'html')
? `${options.tagBefore}${paragraph}${options.tagAfter}`
: `${paragraph}\n\n`
), '')
}

errorHandler() {
Expand Down
11 changes: 10 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ const config = {
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader', 'eslint-loader'],
use: [
'babel-loader',
{
loader:'eslint-loader',
options: {
failOnWarning: false,
quiet: true,
},
}
],
},
],
},
Expand Down

0 comments on commit aa517a6

Please sign in to comment.