0.3.0 ā€¢ Published 7 years ago

beyond-ipsum v0.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

beyond-ipsum

šŸ”  - A filler text generator defaulting to the beginning lyrics from the song One Step Beyond by Madness.

Installation

npm:

npm install beyond-ipsum

HTML:

<script src="beyond-ipsum.min.js"></script>

Usage

ES6:

import BeyondIpsum from 'beyond-ipsum';

const generator = new BeyondIpsum();

Browser:

BeyondIpsum
// or
window.BeyondIpsum

// i.e
var generator = new BeyondIpsum();

Example

import BeyondIpsum from 'beyond-ipsum';

const generator = new BeyondIpsum({
  // Settings for the generator, see section 'Settings'
});

// Get a random sentence
const sentence = generator.getSentence();

console.log(sentence);
// e.g "Move heavy beyond nuttiest well move you've to in."

Settings

var generator = new BeyondIpsum({
  // Settings here
});
SettingTypeDefaultDescription
wordsArrayThe first 42 unique words in the lyrics of One Step beyond by MadnessThe words to use
sentenceLimitsObject{min: 2, max: 9}Min/max words in a sentence
headingLimitsObject{min: 3, max: 6}Min/max words in a heading
paragraphLimitsObject{min: 4, max: 13}Min/max sentences in a paragraph
startSentenceString / booleanfalseSentence to begin the first paragraph with, false if just random
startHeadingString / booleanfalseSentence to use as the first heading, false if just random
formatString<h1/><p/><h2/><p/><p/><h2/><p/>Describe the format of getFormattedContent(). Put the wanted tag names between < and />. Heading tag names will generate headings in them, all other will generate a paragraph as their content
allowRepeatedWordsBooleanfalseIf true, the same word can appear twice in a row

API

getWord()

Get a random word from the pool of words. If setting allowRepeatedWords is false, this method will not return the same word twice in row.

Returns

{String} A word from the pool.

getSentence()

Returns

{String} Random sentence made up from the pool of words.

getHeading();

Returns

{String} Random text string suitable for headings.

getParagraph()

Returns

{String} Paragraph of text made up from random sentences.

getParagraphs(numberOfParagraphs)

Parameters

ParameterTypeDefaultDescription
numberOfParagraphsNumber3Number of paragraps to return

Returns

{String} Multiple paragraphs made up from random sentences.

getFormattedContent()

Returns

{String} Formatted random text, based on the format setting.

interpolate(string)

Replace occurences of, for example, {{paragraph}} in the submitted string with randomly generated paragraphs. Also available are {{heading}}, {{sentence}} and {{word}}.

Parameters

ParameterTypeDefaultDescription
stringString""The string to interpolate.

Returns

{String} The same string as the one provided, but with the random good stuff interpolated.

updateSettings(newSettings)

Update/overwrite the settings after instantiation.

Parameters

ParameterTypeDefaultDescription
newSettingsObject{}Object with the settings to overwrite.

Returns

{Object} The new settings object

resetDefaultSettings()

Reset to the default settings after instantiation.

Returns

{Object} The new settings object