Skip to content

Lorem Ipsum Generator — TypeScript source

Generate placeholder Lorem Ipsum text - paragraphs and sentences with adjustable counts. Classic Latin word pool, instant copy.

This is the TypeScript implementation — the same logic the interactive tool runs, in a shareable, citable form.

// Lorem Ipsum generator. Pure structure (random word choice). The unit-test
// surface for the Lorem Ipsum Generator tool.

const WORDS = ('lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor ' +
  'incididunt ut labore et dolore magna aliqua enim ad minim veniam quis nostrud exercitation ' +
  'ullamco laboris nisi aliquip ex ea commodo consequat duis aute irure in reprehenderit voluptate ' +
  'velit esse cillum eu fugiat nulla pariatur excepteur sint occaecat cupidatat non proident sunt ' +
  'culpa qui officia deserunt mollit anim id est laborum').split(' ');

function randInt(max: number): number {
  return Math.floor(Math.random() * max);
}

export function sentence(minWords = 8, maxWords = 16): string {
  const span = Math.max(1, maxWords - minWords + 1);
  const n = minWords + randInt(span);
  const words: string[] = [];
  for (let i = 0; i < n; i++) words.push(WORDS[randInt(WORDS.length)]);
  const s = words.join(' ');
  return s.charAt(0).toUpperCase() + s.slice(1) + '.';
}

export function paragraph(sentences = 5): string {
  return Array.from({ length: sentences }, () => sentence()).join(' ');
}

export function lorem(paragraphs = 3, sentencesPerPara = 5): string {
  return Array.from({ length: paragraphs }, () => paragraph(sentencesPerPara)).join('\n\n');
}

export { WORDS };

Also available in 13 other languages

Every CosmoDev tool ships its pure logic in TypeScript (web) and Go (CLI), with authored implementations in a dozen-plus languages — the same contract, ported. Compare all languages side by side →