Rangen is a suite of random generators and procedural generation tools; rangen-loremipsum creates Lorem ipsum fake text to use as placeholder in your designs, publishing mockups...
The lib provides you with 3 functions:
- the
generateSentence()
: generates a simple sentence with random words - the
generateParagraph()
: generates a paragraph with a few Lorem ipsum sentences - the
generateText()
: generates a text with a few Lorem ipsum paragraphs
You can install it via NPM (or Yarn):
npm install @mpecheux/rangen-loremipsum
yarn add @mpecheux/rangen-loremipsum
In a Node context, you can then import the package using the require
keyword:
const rangenLoremIpsum = require("@mpecheux/rangen-loremipsum");
const sentence = rangenLoremIpsum.generateSentence();
console.log(sentence);
// Pharetra tristique laoreet condimentum facilisis aliquam feugiat.
For ES6 JavaScript, use the import
keyword:
import rangenLoremIpsum from "@mpecheux/rangen-loremipsum";
const paragraph = rangenLoremIpsum.generateParagraph();
console.log(paragraph);
// Hendrerit congue maecenas ullamcorper quisque feugiat. Netus risus primis ultricies amet. Netus malesuada faucibus torquent commodo maecenas arcu dictumst. Nostra sit odio mollis aliquam nec congue commodo.
You can also use the CDN versions directly if you don't want to install anything:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Rangen: Name - Demo</title>
<script src="https://unpkg.com/@mpecheux/[email protected]/dist/rangen-loremipsum.min.js"></script>
<!-- or:
<script src="https://cdn.jsdelivr.net/npm/@mpecheux/[email protected]/dist/rangen-loremipsum.min.js"></script>
-->
</head>
<body>
<div id="container"></div>
<button onclick="generateText()">Generate!</button>
<script>
const generateText = () => {
const name = RangenLoremIpsum.generateText();
document.getElementById("container").innerText = name;
}
window.onload = () => {
generateText();
}
</script>
</body>
</html>
(Or download them and put them in your project as local dependencies ;) )
By default, the lib uses a list of "latin-sounding" words, like "lorem", "ipsum", "dolor", "sit", "amet"...
But, of course, you can pass in your own words list to influence the texts generated by the package! To do so, simply use the wordsList
option (that's available for all 3 functions):
const paragraph = rangenLoremIpsum.generateParagraph({
wordsList: [
"hello", "world", "tiger", "glass", "other", "cat", "truck",
"phone", "baby", "test", "difference", "hat", "cap", "car",
"kitty", "rabbit", "cow", "metal", "wood", "stone"
]
});
console.log(paragraph);
// Other baby truck wood cow baby stone world. Wood world cap phone stone baby hello. Car wood truck car kitty test. Phone baby rabbit kitty cat hat truck. Difference glass kitty stone difference.
Parameters:
-
minWords
: minimum number of words in the sentence[default: 4]
-
maxWords
: maximum number of words in the sentence[default: 8]
-
wordsList
: custom list of words to use in the generator[default:
null
]
const sentence = rangenLoremIpsum.generateSentence({
minWords: 12,
maxWords: 20
});
console.log(sentence);
// Rutrum a nostra consequat duis faucibus at luctus lobortis phasellus class proin ut nunc.
Parameters:
-
minWords
: minimum number of words in each sentence[default: 4]
-
maxWords
: maximum number of words in each sentence[default: 8]
-
minSentences
: minimum number of sentences in the paragraph[default: 3]
-
maxSentences
: maximum number of sentences in the paragraph[default: 6]
-
wordsList
: custom list of words to use in the generator[default:
null
]
const paragraph = rangenLoremIpsum.generateParagraph({
minWords: 12,
maxWords: 20,
minSentences: 4,
maxSentences: 6,
});
console.log(paragraph);
// Justo primis tortor porttitor tincidunt donec lobortis felis vel donec blandit aenean curabitur convallis semper libero sociosqu et mauris bibendum. A donec sit fames imperdiet semper tortor volutpat dui facilisis purus velit nam arcu at. Rhoncus vulputate varius consequat per ante tincidunt suspendisse vehicula pharetra aliquet fames enim pulvinar dolor nam curae. Ante dapibus pretium litora tortor mollis vestibulum habitant felis enim quisque aliquam cubilia aliquam tellus auctor turpis vestibulum. Quis sodales mi sed ipsum auctor mattis ultricies diam nostra pulvinar tristique nullam. Enim integer euismod ligula fermentum aliquet dictum ultrices quam velit hac gravida auctor faucibus a nostra rhoncus interdum cras.
Parameters:
-
minWords
: minimum number of words in each sentence[default: 4]
-
maxWords
: maximum number of words in each sentence[default: 8]
-
minSentences
: minimum number of sentences in each paragraph[default: 3]
-
maxSentences
: maximum number of sentences in each paragraph[default: 6]
-
minParagraphs
: minimum number of paragraphs in the text[default: 2]
-
maxParagraphs
: maximum number of paragraphs in the text[default: 4]
-
wordsList
: custom list of words to use in the generator[default:
null
]
const text = rangenLoremIpsum.generateText({
minWords: 2,
maxWords: 5,
minSentences: 1,
maxSentences: 3,
minParagraphs: 4,
maxParagraphs: 6
});
console.log(text);
// Eros aenean iaculis vehicula accumsan. Fusce enim erat. Elementum taciti nostra.
// Metus ultricies. Arcu tempus metus elementum euismod. Proin fringilla consequat.
// Sollicitudin ligula ultrices congue nec. Purus vestibulum ut ligula egestas. Praesent urna integer.
// Fermentum luctus proin sociosqu. Morbi bibendum.
// Cubilia enim imperdiet iaculis. Fringilla pretium ut. Consectetur non elit ullamcorper.
// Adipiscing neque a quisque erat.