@mnrendra/chalk-supports-color
v2.1.0
Published
Refactored supports-color code to support both CommonJS (CJS) and ES Modules (ESM) with mixed exports.
Downloads
116
Maintainers
Readme
@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
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
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 🙇
- 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.