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.
- ✅ Auto-detection for
browser
andnode
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
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. 🙏
npm i @mnrendra/chalk-supports-color
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.
import type {
ColorSupportLevel,
ColorSupport,
ColorInfo,
SupportsColor,
Options
} from '@mnrendra/chalk-supports-color'
Contributions are always welcome! Please open discussions here.
- sindresorhus for creating the original source code.
- Qix- for being the active maintainer of the original source code.
- and all contributors who contributed to the original source code.