$ show knicklabs/lorem-ipsum.js
Lorem Ipsum.js is a JavaScript library that generates placeholder lorem ipsum text for use in web development, design mockups, and other applications requiring dummy text. It provides both a programmatic API and a command-line interface, supporting output in plain text or HTML formats with configurable parameters for word, sentence, and paragraph counts. The library is designed to work across multiple JavaScript environments including Node.js, web browsers, and React Native. The architecture follows a modular structure with clear separation of concerns: core text generation logic resides in lib/, utility functions in util/, constants in constants/, and the CLI interface in bin/. The main entry point exports a loremIpsum() function that accepts configuration options and delegates to specialized classes for generation and formatting. The system handles platform-specific details like line endings and clipboard operations through environment detection utilities. Key features include robust input validation, cross-platform compatibility, customizable word lists and length bounds, and proper error handling. The library implements defensive programming practices with comprehensive type safety via TypeScript, extensive unit testing, and attention to edge cases such as unsupported platforms or invalid parameters. The CLI tool offers additional functionality like copying generated text to the system clipboard.
The LLM identified 3 files worth highlighting for reuse:
Detects whether the code is running in a Node.js environment by checking for the existence of module.exports. This utility is completely self-contained with no internal dependencies, handles edge cases gracefully, and demonstrates the environment detection pattern. It can be extracted to any project needing to distinguish Node.js from browser environments with minimal modification.
Detects React Native runtime by checking if navigator.product equals 'ReactNative', wrapped in a try/catch block to handle environments where navigator is undefined. This isolated utility shows proper error handling for platform detection and represents a reusable pattern for detecting specific JavaScript runtime environments. The implementation is safe for use in both browser and Node.js contexts.
Determines if the current process is running on Windows by comparing process.platform against a constant, with a fallback to false if the comparison fails. This simple yet robust utility demonstrates the failsafe pattern where exceptions are caught and a safe default value is returned. It has zero dependencies beyond a constants file and can be easily reused in any Node.js project requiring platform-specific behavior.