Registry / cli-styles

cli-styles

JSON →
library1.0.0jsnpmunverified

cli-styles is a lightweight utility library designed to standardize the visual appearance of command-line interface (CLI) applications, particularly in relation to user prompts. Instead of being a prompt solution itself, it provides a consistent set of styles for user input (e.g., default, password, invisible), status indicators (question, success, error marks), and prompt delimiters (e.g., '›'). This enables different prompt libraries to adopt a uniform look and feel. The package is currently at version 1.0.0, released in February 2020, and does not appear to be under active development, maintaining a stable API. It is frequently used in conjunction with `prompt-skeleton` and a suite of dedicated prompt libraries like `text-prompt` and `select-prompt` to ensure visual coherence across an application's CLI interactions. Its primary differentiator is its focus on providing reusable styling primitives rather than a full-fledged prompt system.

npm install cli-styles
INSTALL
IMPORT
SIG · CLI-STYLES
C
cli-styles
javascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cliStyles
import cliStyles from 'cli-styles'
import { input, indicator, delimiter } from 'cli-styles'
The package is CommonJS-first and exports a single default object. While bundlers like Webpack or Rollup might allow this syntax, direct Node.js ESM usage often requires careful configuration or a dynamic import for older CJS modules. Named imports will result in `undefined`.
cliStyles (CommonJS)
const cliStyles = require('cli-styles')
This is the primary and most reliable way to import 'cli-styles' in Node.js environments, given its CommonJS module format.
input.default
cliStyles.input.default('Your input')
cliStyles.input('Your input')
The 'input' property is an object containing various input style functions (e.g., 'default', 'password'). You must access the specific style function, not call 'input' directly.

Demonstrates how to import 'cli-styles' and apply its input styles, status indicators, and delimiters to a basic readline prompt to achieve a consistent look.

import cliStyles from 'cli-styles'; import readline from 'readline'; const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); async function runPrompt() { // Using the question indicator and delimiter process.stdout.write(cliStyles.indicator.question + ' ' + cliStyles.delimiter + ' '); // Using default input style const question = cliStyles.input.default('What is your name? '); rl.question(question, (name) => { if (name.length > 0) { process.stdout.write(cliStyles.indicator.success + ' ' + cliStyles.delimiter + ' '); console.log(cliStyles.input.default(`Hello, ${name}!`)); } else { process.stdout.write(cliStyles.indicator.error + ' ' + cliStyles.delimiter + ' '); console.log(cliStyles.input.default('Name cannot be empty.')); } rl.close(); }); } runPrompt();
Debug
Known issues
gotchacli-styles is a CommonJS module and does not natively support named ESM imports. Attempting `import { input } from 'cli-styles'` will fail or result in `undefined` values in pure ESM environments.
fix
Use `import cliStyles from 'cli-styles'` for ESM, which will import the default export, then access properties like `cliStyles.input`. For CommonJS, use `const cliStyles = require('cli-styles')`.
affects: >=0.1.0
deprecatedThe package is not actively maintained since its last update in February 2020. While stable at 1.0.0, users should be aware that new features, bug fixes, or updates for compatibility with newer Node.js versions or terminal features are unlikely.
fix
Consider evaluating alternative, actively maintained libraries for new projects if future compatibility or features are critical. For existing projects, be mindful of potential issues with newer Node.js versions or terminal emulation that may not be addressed.
affects: >=1.0.0
gotchacli-styles is not a prompt library itself; it provides styling primitives for existing prompt implementations. Directly calling `cliStyles.input` or `cliStyles.indicator` will not render a prompt or text, as these are objects containing styling functions or pre-styled strings.
fix
Always access the specific style function or string, e.g., `cliStyles.input.default('text')` or `cliStyles.indicator.success`. Integrate these outputs with a proper prompt library like `prompt-skeleton` or Node.js's `readline` module.
affects: >=0.1.0
gotchaThe package depends on older versions of `chalk` (implicitly via its `package.json` at the time of 1.0.0 release). This might lead to dependency conflicts if your project uses a much newer `chalk` version, or it might not leverage the latest color capabilities or performance improvements.
fix
Inspect your `package-lock.json` for `cli-styles`'s `chalk` dependency. If conflicts arise, consider using `npm dedupe` or manually resolving dependency trees. For new projects, evaluate alternatives that use up-to-date dependencies.
affects: >=0.1.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require('cli-styles')` in an ECMAScript Module (ESM) context (e.g., in a `.mjs` file or a module with `"type": "module"` in `package.json`).
fix
For ESM, use `import cliStyles from 'cli-styles';` to import the default export. For CommonJS, ensure your file is `.cjs` or `"type": "commonjs"` is specified, or simply use the default Node.js behavior.
TypeError: cliStyles.input.default is not a function
This error is unlikely to occur unless `cliStyles` itself is not correctly imported or is `undefined`. More commonly, `cliStyles.input` might be treated as a function if `cliStyles` isn't properly destructured or imported as a default.
fix
Ensure `cliStyles` is imported correctly (e.g., `const cliStyles = require('cli-styles')` or `import cliStyles from 'cli-styles'`). The `input.default` property is a function provided by `chalk`, so verify `chalk` is also correctly resolved within `cli-styles`.
TypeError: Cannot read properties of undefined (reading 'default') at Object.input
This error often happens if you've attempted named destructuring like `import { input } from 'cli-styles'` in an ESM context. Since `cli-styles` only has a default export, `input` would be `undefined`.
fix
Import the entire default export: `import cliStyles from 'cli-styles'`. Then access its properties: `cliStyles.input.default(...)`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
chalkrequiredProvides color and styling capabilities for terminal output.
ansi-escapesrequiredOffers ANSI escape codes for cursor manipulation, particularly for 'invisible' input styles.
Agent activity
8 hits · last 30 days
node
6
Resources
cli-styles — npm install cli-styles · libregistry