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

1.0.0 • Public • Published

@mnrendra/chalk-supports-color

Refactor the supports-color code to TypeScript and ensure the output supports both CommonJS (CJS) and ES Modules (ESM) with mixed exports. This will allow users to import or require the module without needing to use .default.

Benefits

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

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')

console.log(supportsColor) // It will print:
// {
//   stdout: {
//     level: 2,
//     hasBasic: true,
//     has256: true,
//     has16m: false
//   },
//   stderr: {
//     level: 2,
//     hasBasic: true,
//     has256: true,
//     has16m: false
//   }
// }

console.log(supportsColor.stdout) // It will print:
// {
//   level: 2,
//   hasBasic: true,
//   has256: true,
//   has16m: false
// }

console.log(supportsColor.stderr) // It will print:
// {
//   level: 2,
//   hasBasic: true,
//   has256: true,
//   has16m: false
// }

console.log(stdout) // It will print:
// {
//   level: 2,
//   hasBasic: true,
//   has256: true,
//   has16m: false
// }

console.log(stderr) // It will print:
// {
//   level: 2,
//   hasBasic: true,
//   has256: true,
//   has16m: false
// }

console.log(createSupportsColor({ isTTY: true })) // It will print:
// {
//   level: 2,
//   hasBasic: true,
//   has256: true,
//   has16m: false
// }

console.log(supportsColor.default) // It will print the same as `supportsColor`.

Using ES Modules:

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

console.log(supportsColor) // It will print:
// {
//   stdout: {
//     level: 2,
//     hasBasic: true,
//     has256: true,
//     has16m: false
//   },
//   stderr: {
//     level: 2,
//     hasBasic: true,
//     has256: true,
//     has16m: false
//   }
// }

console.log(supportsColor.stdout) // It will print:
// {
//   level: 2,
//   hasBasic: true,
//   has256: true,
//   has16m: false
// }

console.log(supportsColor.stderr) // It will print:
// {
//   level: 2,
//   hasBasic: true,
//   has256: true,
//   has16m: false
// }

console.log(stdout) // It will print:
// {
//   level: 2,
//   hasBasic: true,
//   has256: true,
//   has16m: false
// }

console.log(stderr) // It will print:
// {
//   level: 2,
//   hasBasic: true,
//   has256: true,
//   has16m: false
// }

console.log(createSupportsColor({ isTTY: true })) // It will print:
// {
//   level: 2,
//   hasBasic: true,
//   has256: true,
//   has16m: false
// }

console.log(supportsColor.default) // It will print the same as `supportsColor`.

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 🙇

Reference

Refactored from the original source code since version v9.4.0, commit c214314.

License

MIT

Author

@mnrendra

Package Sidebar

Install

npm i @mnrendra/chalk-supports-color

Weekly Downloads

4

Version

1.0.0

License

MIT

Unpacked Size

40.3 kB

Total Files

9

Last publish

Collaborators

  • mnrendra