@mnrendra/chalk-supports-color
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

@mnrendra/chalk-supports-color

Refactored supports-color code to support both CommonJS (CJS) and ES Modules (ESM) with mixed exports. This allows users to import or require the module without needing to access the .default property.

Benefits

  • ✅ Auto-detection for browser and node platforms
  • ✅ Supports both CommonJS (CJS) and ES Modules (ESM)
  • ✅ Mixed exports (no need to access .default for default value)
  • ✅ Minified distribution package
  • ✅ Well-tested (100% code coverage)
  • TypeScript source code for easier development

Reference

Refactored from the original source code since version v9.4.0, commit c214314.
This module will be kept updated with the original source code; contributions are welcome. 🙏

Install

npm i @mnrendra/chalk-supports-color

Usage

Using CommonJS:

const supportsColor = require('@mnrendra/chalk-supports-color')

const {
  stdout,
  stderr,
  createSupportsColor
} = require('@mnrendra/chalk-supports-color')

// from default export
console.log(supportsColor)
console.log(supportsColor.default)
console.log(supportsColor.stdout)
console.log(supportsColor.stderr)
// from named exports
console.log(stdout)
console.log(stderr)
console.log(createSupportsColor({ isTTY: true }))

Using ES Modules:

import supportsColor, {
  stdout,
  stderr,
  createSupportsColor
} from '@mnrendra/chalk-supports-color'

// from default export
console.log(supportsColor)
console.log(supportsColor.default)
console.log(supportsColor.stdout)
console.log(supportsColor.stderr)
// from named exports
console.log(stdout)
console.log(stderr)
console.log(createSupportsColor({ isTTY: true }))

For more details, refer to the original source code: https://github.com/chalk/supports-color.

Types

import type {
  ColorSupportLevel,
  ColorSupport,
  ColorInfo,
  SupportsColor,
  Options
} from '@mnrendra/chalk-supports-color'

Contribute

Contributions are always welcome! Please open discussions here.

Special Thanks 🙇

License

MIT

Author

@mnrendra

Package Sidebar

Install

npm i @mnrendra/chalk-supports-color

Weekly Downloads

5

Version

2.1.0

License

MIT

Unpacked Size

23.7 kB

Total Files

9

Last publish

Collaborators

  • mnrendra