### Install Colorette Source: https://github.com/jorgebucaran/colorette/blob/main/README.md Install the package via npm. ```console npm install colorette ``` -------------------------------- ### Run benchmarks Source: https://github.com/jorgebucaran/colorette/blob/main/README.md Execute the benchmark suite to compare performance against other libraries. ```console npm --prefix bench start ``` -------------------------------- ### createColors() Source: https://github.com/jorgebucaran/colorette/blob/main/README.md Configures color support settings for the library. ```APIDOC ## createColors() ### Description Creates a custom instance of color functions, allowing for manual override of terminal color detection via the `useColor` option. ### Parameters - **options** (object) - Required - Configuration object - **useColor** (boolean) - Required - Explicitly enable or disable color output. ### Request Example ```js import { createColors } from "colorette" const { blue } = createColors({ useColor: false }) ``` ``` -------------------------------- ### Apply basic terminal styles Source: https://github.com/jorgebucaran/colorette/blob/main/README.md Import and apply color and formatting functions to strings for terminal output. ```javascript import { blue, bold, underline } from "colorette" console.log( blue("I'm blue"), bold(blue("da ba dee")), underline(bold(blue("da ba daa"))) ) ``` -------------------------------- ### Benchmark results Source: https://github.com/jorgebucaran/colorette/blob/main/README.md Performance comparison output showing operations per second. ```diff chalk 1,786,703 ops/sec kleur 1,618,960 ops/sec colors 646,823 ops/sec ansi-colors 786,149 ops/sec picocolors 2,871,758 ops/sec + colorette 3,002,751 ops/sec ``` -------------------------------- ### Create Custom Color Functions with createColors Source: https://context7.com/jorgebucaran/colorette/llms.txt Use `createColors()` to generate a new set of color functions, allowing explicit control over color enablement. This is useful for testing or when programmatically disabling colors, such as for log files. ```javascript import { createColors } from "colorette" // Force colors enabled (useful for testing or piped output) const colorsOn = createColors({ useColor: true }) console.log(colorsOn.blue("Always blue")) // Output: \x1b[34mAlways blue\x1b[39m // Force colors disabled (useful for log files or plain text output) const colorsOff = createColors({ useColor: false }) console.log(colorsOff.blue("Just plain text")) // Output: Just plain text console.log(colorsOff.red("No ANSI codes here")) // Output: No ANSI codes here // Numbers are converted to strings when colors disabled console.log(colorsOff.blue(42)) // Output: 42 // Use based on environment or configuration const useColors = process.env.LOG_COLORS !== "false" const c = createColors({ useColor: useColors }) console.log(c.green("✓ Task complete")) console.log(c.red("✗ Task failed")) // Create themed color sets const errorColors = createColors({ useColor: true }) const logToFile = createColors({ useColor: false }) function log(message, toFile = false) { const c = toFile ? logToFile : errorColors return c.red(message) } ``` -------------------------------- ### isColorSupported Source: https://github.com/jorgebucaran/colorette/blob/main/README.md Exposes the internal color support detection status. ```APIDOC ## isColorSupported ### Description A boolean property that indicates whether the current terminal environment supports color output. It is used internally but exposed for convenience. ### Response - **isColorSupported** (boolean) - `true` if the terminal supports color, `false` otherwise. ``` -------------------------------- ### Color Styling Functions Source: https://github.com/jorgebucaran/colorette/blob/main/README.md Functions for applying specific colors or styles to strings. ```APIDOC ## () ### Description Applies a specific color or style to the provided string. Supported colors include black, red, green, yellow, blue, magenta, cyan, white, and gray, along with various background colors, bright variants, and modifiers like bold, dim, and underline. ### Usage ```js import { blue } from "colorette" blue("I'm blue") //=> \x1b[34mI'm blue\x1b[39m ``` ``` -------------------------------- ### Control Color Output with Environment Variables Source: https://context7.com/jorgebucaran/colorette/llms.txt Colorette respects standard environment variables and CLI flags for controlling color output. Use `NO_COLOR` or `--no-color` to disable colors, and `FORCE_COLOR` or `--color` to enable them regardless of terminal detection. Colors are also automatically enabled in supported CI environments. ```javascript import { blue, isColorSupported } from "colorette" // Color behavior is determined by environment: // - NO_COLOR environment variable disables colors // - FORCE_COLOR environment variable enables colors // - --no-color CLI flag disables colors // - --color CLI flag enables colors // Run with: NO_COLOR= node script.js // Or: node script.js --no-color console.log(blue("This will be plain text when NO_COLOR is set")) // Run with: FORCE_COLOR= node script.js // Or: node script.js --color console.log(blue("This will be blue even in non-TTY environments")) // Check the resolved state console.log(`Colors enabled: ${isColorSupported}`) // CI environment detection (GitHub Actions, GitLab CI, CircleCI) // Colors are automatically enabled in supported CI environments ``` -------------------------------- ### Check Terminal Color Support with isColorSupported Source: https://context7.com/jorgebucaran/colorette/llms.txt Use `isColorSupported` to determine if the terminal supports colors. This is useful for conditionally formatting output or enabling/disabling color features. It can also be passed to `createColors` to dynamically control color usage. ```javascript import { isColorSupported, createColors } from "colorette" // Check if colors are supported before using them console.log(`Color support: ${isColorSupported}`) // Output: Color support: true (or false) // Conditionally format output if (isColorSupported) { console.log("\x1b[32mColors are enabled!\x1b[39m") } else { console.log("Colors are disabled") } // Use isColorSupported with createColors for dynamic toggling const userPreference = process.argv.includes("--color") const c = createColors({ useColor: userPreference || isColorSupported }) console.log(c.blue("This respects both auto-detection and user preference")) // Build output based on support function formatStatus(success) { if (isColorSupported) { return success ? "\x1b[32m✓\x1b[39m" : "\x1b[31m✗\x1b[39m" } return success ? "[OK]" : "[FAIL]" } console.log(formatStatus(true)) // ✓ (green) or [OK] console.log(formatStatus(false)) // ✗ (red) or [FAIL] ``` -------------------------------- ### View color output Source: https://github.com/jorgebucaran/colorette/blob/main/README.md Demonstrates the ANSI escape sequence generated by a color function. ```javascript import { blue } from "colorette" blue("I'm blue") //=> \x1b[34mI'm blue\x1b[39m ``` -------------------------------- ### Use styles with template literals Source: https://github.com/jorgebucaran/colorette/blob/main/README.md Apply styles directly within template literals for cleaner string formatting. ```javascript console.log(` There's a ${underline(blue("house"))}, With a ${bold(blue("window"))}, And a ${blue("corvette")} And everything is blue `) ``` -------------------------------- ### Nest terminal styles Source: https://github.com/jorgebucaran/colorette/blob/main/README.md Combine multiple styles within a single template literal without breaking color sequences. ```javascript console.log(bold(`I'm ${blue(`da ba ${underline("dee")} da ba`)} daa`)) ``` -------------------------------- ### Override color detection via CLI Source: https://github.com/jorgebucaran/colorette/blob/main/README.md Use environment variables or CLI flags to control color output in piped commands. ```console $ ./example.js --no-color | ./consumer.js ``` ```console $ NO_COLOR= ./example.js | ./consumer.js ``` -------------------------------- ### Bright Color Usage in Colorette Source: https://context7.com/jorgebucaran/colorette/llms.txt Utilize bright color variants for higher intensity terminal output. Import functions like redBright, greenBright, and blueBright for more emphasis. ```javascript import { redBright, greenBright, blueBright, yellowBright, magentaBright, cyanBright, whiteBright, blackBright } from "colorette" // High intensity colors for emphasis console.log(redBright("CRITICAL ERROR")) // Output: \x1b[91mCRITICAL ERROR\x1b[39m console.log(greenBright("✓ All tests passed")) // Output: \x1b[92m✓ All tests passed\x1b[39m console.log(blueBright("→ Next step")) // Output: \x1b[94m→ Next step\x1b[39m console.log(yellowBright("⚠ Important notice")) // Output: \x1b[93m⚠ Important notice\x1b[39m ``` -------------------------------- ### Override terminal color detection Source: https://github.com/jorgebucaran/colorette/blob/main/README.md Use createColors to manually enable or disable color output regardless of environment detection. ```javascript import { createColors } from "colorette" const { blue } = createColors({ useColor: false }) console.log(blue("Blue? Nope, nah")) ``` ```javascript import { createColors } from "colorette" const { blue } = createColors({ useColor: false }) ``` -------------------------------- ### Apply Text Style Modifiers with Colorette Source: https://context7.com/jorgebucaran/colorette/llms.txt Use imported functions like `bold`, `dim`, `italic`, `underline`, `inverse`, `hidden`, `strikethrough`, and `reset` to modify text appearance. Each modifier has a corresponding closing escape code. ```javascript import { bold, dim, italic, underline, inverse, hidden, strikethrough, reset } from "colorette" // Bold text for emphasis console.log(bold("Important message")) // Output: \x1b[1mImportant message\x1b[22m // Dim text for secondary information console.log(dim("Less important details")) // Output: \x1b[2mLess important details\x1b[22m // Italic text console.log(italic("Emphasized text")) // Output: \x1b[3mEmphasized text\x1b[23m // Underlined text for links or emphasis console.log(underline("Click here")) // Output: \x1b[4mClick here\x1b[24m // Inverse colors (swap foreground/background) console.log(inverse("Highlighted")) // Output: \x1b[7mHighlighted\x1b[27m // Hidden text (useful for passwords) console.log(hidden("secret")) // Output: \x1b[8msecret\x1b[28m // Strikethrough for deprecated items console.log(strikethrough("Deprecated feature")) // Output: \x1b[9mDeprecated feature\x1b[29m // Reset all styles console.log(reset("Back to normal")) // Output: \x1b[0mBack to normal\x1b[0m ``` -------------------------------- ### Bright Background Color Functions in Colorette Source: https://context7.com/jorgebucaran/colorette/llms.txt Apply high-intensity background colors using bright background functions like bgRedBright and bgGreenBright. These are useful for creating high-visibility status badges. ```javascript import { bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright, black } from "colorette" // High visibility status badges console.log(bgRedBright(black(" FAILED "))) // Output: \x1b[101m\x1b[30m FAILED \x1b[39m\x1b[49m console.log(bgGreenBright(black(" PASSED "))) // Output: \x1b[102m\x1b[30m PASSED \x1b[39m\x1b[49m console.log(bgYellowBright(black(" PENDING "))) // Output: \x1b[103m\x1b[30m PENDING \x1b[39m\x1b[49m ``` -------------------------------- ### Basic Color Usage in Colorette Source: https://context7.com/jorgebucaran/colorette/llms.txt Import and use basic color functions like red, green, blue, and yellow. These functions wrap text with ANSI escape codes for terminal output. They also handle various data types and return an empty string for empty or undefined values. ```javascript import { red, green, blue, yellow, magenta, cyan, white, gray, black } from "colorette" // Basic color usage console.log(red("Error: Something went wrong")) // Output: \x1b[31mError: Something went wrong\x1b[39m console.log(green("Success: Operation completed")) // Output: \x1b[32mSuccess: Operation completed\x1b[39m console.log(blue("Info: Processing started")) // Output: \x1b[34mInfo: Processing started\x1b[39m console.log(yellow("Warning: Deprecated feature")) // Output: \x1b[33mWarning: Deprecated feature\x1b[39m // Colors also work with numbers and other types console.log(red(-1e10)) // Works with negative numbers console.log(blue(42)) // Works with positive numbers console.log(green(true)) // Works with booleans console.log(yellow(null)) // Works with null // Empty or undefined values return empty string console.log(blue("")) // Returns: "" console.log(blue(undefined)) // Returns: "" console.log(blue()) // Returns: "" ``` -------------------------------- ### Background Color Functions in Colorette Source: https://context7.com/jorgebucaran/colorette/llms.txt Set background colors for terminal text using functions like bgRed, bgGreen, and bgYellow. These can be combined with foreground colors for better contrast. ```javascript import { bgRed, bgGreen, bgYellow, bgBlue, white, black } from "colorette" // Highlight important messages with background colors console.log(bgRed(" ERROR ")) // Output: \x1b[41m ERROR \x1b[49m console.log(bgGreen(" PASS ")) // Output: \x1b[42m PASS \x1b[49m console.log(bgYellow(" WARN ")) // Output: \x1b[43m WARN \x1b[49m console.log(bgBlue(" INFO ")) // Output: \x1b[44m INFO \x1b[49m // Combine with foreground colors for contrast console.log(bgRed(white(" CRITICAL "))) console.log(bgGreen(black(" SUCCESS "))) ``` -------------------------------- ### Nest Colors and Styles in Colorette Source: https://context7.com/jorgebucaran/colorette/llms.txt Colorette handles nested styles automatically, ensuring parent styles are restored when inner styles close. This allows for complex, multi-level styling without color bleeding. ```javascript import { bold, red, blue, dim, yellow, cyan, green, magenta } from "colorette" // Nest styles without breaking parent colors console.log(bold(`bold ${red(`red ${dim("dim")} red`)} bold`)) // Output: \x1B[1mbold \x1B[31mred \x1B[2mdim\x1B[22m\x1B[1m red\x1B[39m bold\x1B[22m // Complex multi-level nesting console.log(magenta( `magenta ${yellow( `yellow ${cyan("cyan")} ${red("red")} ${green("green")} yellow` )} magenta` )) // All colors properly restored at each level // Template literal patterns for rich output const status = "active" const count = 42 console.log(`Status: ${green(status)} | Count: ${bold(blue(count))}`) // Build complex log messages function logMessage(level, message) { const prefix = { error: bold(red("[ERROR]")), warn: bold(yellow("[WARN]")), info: bold(blue("[INFO]")), debug: dim("[DEBUG]") } console.log(`${prefix[level]} ${message}`) } logMessage("error", "Connection failed") logMessage("warn", "Retrying in 5 seconds") logMessage("info", "Connected successfully") logMessage("debug", "Received 1024 bytes") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.