react-lorem-ipsum
Advanced tools
Comparing version
@@ -22,2 +22,3 @@ "use strict"; | ||
}; | ||
var stDevPercentage = 0.2; | ||
@@ -29,3 +30,2 @@ var LoremIpsum = function LoremIpsum(_ref) { | ||
startWithLoremIpsum = _ref.startWithLoremIpsum; | ||
var stDevPercentage = 0.2; | ||
@@ -38,5 +38,11 @@ var randomPositiveFromRange = function randomPositiveFromRange(min, max) { | ||
var getStandardDeviation = function getStandardDeviation(value, percentage) { | ||
return Math.round(value * percentage); | ||
return Math.ceil(value * percentage); | ||
}; | ||
var parseIntWithDefault = function parseIntWithDefault(value, defaultValue) { | ||
var finalValue = parseInt(value, 10); | ||
if (Number.isNaN(finalValue)) finalValue = defaultValue; | ||
return finalValue; | ||
}; | ||
var getRandomWord = function getRandomWord() { | ||
@@ -46,10 +52,11 @@ return _words["default"][randomPositiveFromRange(0, _words["default"].length - 1)]; | ||
var createSentence = function createSentence() { | ||
var awis = parseInt(avgWordsPerSentence, 10); | ||
if (Number.isNaN(awis)) awis = defaultProps.avgWordsPerSentence; | ||
var sentence = ''; | ||
var stDev = getStandardDeviation(awis, stDevPercentage); | ||
var sentenceLength = randomPositiveFromRange(awis - stDev, awis + stDev); | ||
var createSentence = function createSentence(_ref2) { | ||
var withLoremIpsum = _ref2.withLoremIpsum; | ||
var awps = parseIntWithDefault(avgWordsPerSentence, defaultProps.avgWordsPerSentence); | ||
var sentence = withLoremIpsum ? 'Lorem ipsum odor amet, ' : ''; | ||
var stDev = getStandardDeviation(awps, stDevPercentage); | ||
var sentenceLength = randomPositiveFromRange(awps - stDev, awps + stDev); | ||
var remainingSentenceLength = withLoremIpsum ? Math.max(3, sentenceLength - 4) : sentenceLength; | ||
for (var i = 0; i < sentenceLength; i += 1) { | ||
for (var i = 0; i < remainingSentenceLength; i += 1) { | ||
var word = getRandomWord(); | ||
@@ -59,22 +66,19 @@ sentence += "".concat(word, " "); | ||
sentence = "".concat(sentence.charAt(0).toUpperCase() + sentence.slice(1).trim(), "."); | ||
sentence = "".concat(sentence.charAt(0).toUpperCase() + sentence.slice(1).toLowerCase().trim(), "."); | ||
return sentence; | ||
}; | ||
var createParagraph = function createParagraph(_ref2) { | ||
var firstParagraph = _ref2.firstParagraph; | ||
var asip = parseInt(avgSentencesPerParagraph, 10); | ||
if (Number.isNaN(asip)) asip = defaultProps.avgSentencesPerParagraph; | ||
var createParagraph = function createParagraph(_ref3) { | ||
var firstParagraph = _ref3.firstParagraph; | ||
var aspp = parseIntWithDefault(avgSentencesPerParagraph, defaultProps.avgSentencesPerParagraph); | ||
var paragraph = ''; | ||
var stDev = getStandardDeviation(asip, stDevPercentage); | ||
var paragraphLength = randomPositiveFromRange(asip - stDev, asip + stDev); | ||
var stDev = getStandardDeviation(aspp, stDevPercentage); | ||
var paragraphLength = randomPositiveFromRange(aspp - stDev, aspp + stDev); | ||
for (var i = 0; i < paragraphLength; i += 1) { | ||
var swli = typeof startWithLoremIpsum === 'boolean' ? startWithLoremIpsum : defaultProps.startWithLoremIpsum; | ||
if (i === 0 && firstParagraph && swli) { | ||
paragraph += "Lorem ipsum odor amet, ".concat(getRandomWord(), " ").concat(getRandomWord(), " ").concat(getRandomWord(), ". "); | ||
} else { | ||
paragraph += "".concat(createSentence(), " "); | ||
} | ||
var withLoremIpsum = !!(i === 0 && firstParagraph && swli); | ||
paragraph += "".concat(createSentence({ | ||
withLoremIpsum: withLoremIpsum | ||
}), " "); | ||
} | ||
@@ -81,0 +85,0 @@ |
{ | ||
"name": "react-lorem-ipsum", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "React Component for Creating Lorem Ipsum Text as Placeholder", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# React Lorem Ipsum | ||
**React Lorem Ipsum** is a React Component **generates Lorem Ipsum placeholder text**. | ||
**React Lorem Ipsum** is a React Component that **generates placeholder text**. | ||
When backend API is not ready for data fetching and you have to make Frontend Development with static data until it comes, `react-lorem-ipsum` will create your texts for you easily. | ||
When backend API is not ready for data fetching and you have to make Frontend Development with static data (gibberish text) until it comes, `react-lorem-ipsum` will create your texts for you easily. | ||
React Lorem Ipsum is a zero-dependency lightweight (~4 kB) package. | ||
React Lorem Ipsum is a zero-dependency lightweight package. | ||
@@ -47,3 +47,3 @@ [![NPM version][npm-image]][npm-url] | ||
**React Code** | ||
**Code** | ||
@@ -50,0 +50,0 @@ ```js |
12239
2.3%281
1.44%