ns Docsns Docs
Guides

Best Practices

Recommended patterns and tips for using nstypocolors effectively in real-world projects.

This guide outlines recommended patterns for using nstypocolors so your logs remain readable, intentional, and professional—especially in CLIs and developer-facing tools.

Use Gradients Sparingly


Gradients are visually powerful, but overuse can reduce clarity and impact.

Recommended uses:

  • Startup banners
  • Build and success messages
  • Important state transitions

Avoid gradients for:

  • Every log line
  • Large blocks of text
  • Debug-level output
import { logBuild } from 'nstypocolors'

logBuild('Build completed successfully')
const { logBuild } = require('nstypocolors')

logBuild('Build completed successfully')

Gradients work best when they signal a moment, not when they fill the entire output.

Match Colors to Meaning


Each preset conveys a specific intent. Use them consistently.

PurposeFunction
Success / passlogSuccess
Errors / fatallogError
WarningslogWarn
InformationlogInfo
Build / phaselogBuild
Neutral outputlogDefault

Consistency improves developer experience more than creative styling.

Prefer Presets Over Custom Colors


nstypocolors is opinionated by design. Presets exist to prevent noisy or unreadable output.

Instead of:

applyColor(text, someCustomAnsi)

Prefer:

import { logInfo } from 'nstypocolors'

logInfo('Server started on port 3000')
const { logInfo } = require('nstypocolors')

logInfo('Server started on port 3000')

This keeps logs predictable across terminals and platforms.

Keep Messages Short and Intentional


Gradients look best on short to medium-length messages.

Good

logSuccess('Deployment successful')

Less ideal

logSuccess('The deployment process finished successfully without any issues detected')

If a message is long, use a gradient header followed by plain text.

Combine with Plain Logs


A reliable pattern is:

  1. Gradient for status
  2. Plain text for details
logBuild('Starting build')
console.log('→ Compiling source files')
console.log('→ Optimizing assets')
logBuild('Starting build')
console.log('→ Compiling source files')
console.log('→ Optimizing assets')

This improves scanning and keeps output calm and readable.

CLI-Specific Tips


When building CLIs:

  • Use logBuild for phases (init, build, deploy)
  • Use logWarn for recoverable issues
  • Use logError before exiting with non-zero codes
if (!configExists) {
  logError('Missing configuration file')
  process.exit(1)
}
if (!configExists) {
  logError('Missing configuration file')
  process.exit(1)
}

Avoid Colors in Machine Output


If output is meant to be parsed (JSON, pipes, redirects), avoid colored logs entirely.

A common approach:

  • Colors for humans
  • Plain output for machines

You may also send colored logs to stderr and structured output to stdout.

Never rely on color alone when output is consumed by scripts or CI systems.

Test Small Messages


nstypocolors safely handles very short strings, but always test edge cases.

logSuccess('OK')
logWarn('!')

Short messages should be reserved for confirmations or alerts.

Keep Logs Accessible


Remember:

  • Not all terminals render colors equally
  • Some users may be color-sensitive

nstypocolors uses soft, readable palettes by default—avoid stacking extra styles or effects.

Final Thought


nstypocolors is not about louder logs. It’s about clear, expressive, and intentional communication.

Use color to guide attention. Let meaning lead, and styling follow.

Last updated on

On this page