UNPKG

lorem-ipsum

Version:

Generates lorem ipsum placeholder text for Node.js, Deno, browsers, and React Native. Developed with Bun.

4 lines (3 loc) 3.25 kB
(()=>{var u="html",p="plain",I=["html","plain"],c="words",f="word",T="sentences",R="sentence",A="paragraphs",l="paragraph";var m={POSIX:` `,WIN32:`\r `};var a=["ad","adipisicing","aliqua","aliquip","amet","anim","aute","cillum","commodo","consectetur","consequat","culpa","cupidatat","deserunt","do","dolor","dolore","duis","ea","eiusmod","elit","enim","esse","est","et","eu","ex","excepteur","exercitation","fugiat","id","in","incididunt","ipsum","irure","labore","laboris","laborum","Lorem","magna","minim","mollit","nisi","non","nostrud","nulla","occaecat","officia","pariatur","proident","qui","quis","reprehenderit","sint","sit","sunt","tempor","ullamco","ut","velit","veniam","voluptate"];var W=(t)=>t.charAt(0).toUpperCase()+t.slice(1),_=(t=0)=>Array.from({length:t},(r,o)=>o);class s{constructor({sentencesPerParagraph:t={max:7,min:3},wordsPerSentence:r={max:15,min:5},random:o,words:i=a}={}){if(t.min>t.max)throw Error(`Minimum number of sentences per paragraph (${t.min}) cannot exceed maximum (${t.max}).`);if(r.min>r.max)throw Error(`Minimum number of words per sentence (${r.min}) cannot exceed maximum (${r.max}).`);this.sentencesPerParagraph=t,this.words=i,this.wordsPerSentence=r,this.random=o||Math.random}generateRandomInteger(t,r){return Math.floor(this.random()*(r-t+1)+t)}generateRandomWords(t){let{min:r,max:o}=this.wordsPerSentence,i=t||this.generateRandomInteger(r,o);return _(i).reduce((e)=>`${this.pluckRandomWord()} ${e}`,"").trim()}generateRandomSentence(t){return`${W(this.generateRandomWords(t))}.`}generateRandomParagraph(t){let{min:r,max:o}=this.sentencesPerParagraph,i=t||this.generateRandomInteger(r,o);return _(i).reduce((e)=>`${this.generateRandomSentence()} ${e}`,"").trim()}pluckRandomWord(){let t=this.generateRandomInteger(0,this.words.length-1);return this.words[t]}}var E=s;var h=()=>{try{return navigator.product==="ReactNative"}catch{return!1}},M=()=>typeof process<"u"&&typeof process.platform==="string",D=()=>{try{return process.platform==="win32"}catch{return!1}};class n{constructor(t={},r=p,o){if(I.indexOf(r.toLowerCase())===-1)throw Error(`${r} is an invalid format. Please use ${I.join(" or ")}.`);this.format=r,this.generator=new E(t),this.suffix=o}getLineEnding(){if(this.suffix)return this.suffix;if(!h()&&M()&&D())return m.WIN32;return m.POSIX}formatString(t){if(this.format===u)return`<p>${t}</p>`;return t}formatStrings(t){return t.map((r)=>this.formatString(r))}generateWords(t){return this.formatString(this.generator.generateRandomWords(t))}generateSentences(t){return this.formatString(this.generator.generateRandomParagraph(t))}generateParagraphs(t){return this.formatStrings(Array.from({length:t},()=>this.generator.generateRandomParagraph())).join(this.getLineEnding())}}var S=n;var x=({count:t=1,format:r=p,paragraphLowerBound:o=3,paragraphUpperBound:i=7,random:e,sentenceLowerBound:g=5,sentenceUpperBound:d=15,units:U=T,words:O=a,suffix:L=""}={})=>{let N=new S({random:e,sentencesPerParagraph:{max:i,min:o},words:O,wordsPerSentence:{max:d,min:g}},r,L);switch(U){case A:case l:return N.generateParagraphs(t);case T:case R:return N.generateSentences(t);case c:case f:return N.generateWords(t);default:return""}};globalThis.LoremIpsum={Generator:s,LoremIpsum:n,loremIpsum:x};})();