Installations
npm install @poppinss/colors
Releases
Update dependencies
Published on 28 Mar 2024
Updating dependencies
Published on 15 Dec 2023
Publish source map and use TSC for generating types
Published on 06 Nov 2023
Publish under latest release
Published on 14 Oct 2023
Use tsup for bundling
Published on 23 Sept 2023
Update dependencies
Published on 29 Jun 2023
Developer
poppinss
Developer Guide
Module System
ESM
Min. Node Version
>=18.16.0
Typescript Support
Yes
Node Version
21.6.0
NPM Version
9.8.1
Statistics
5 Stars
92 Commits
2 Forks
4 Watching
2 Branches
4 Contributors
Updated on 27 Dec 2023
Languages
TypeScript (99.49%)
Shell (0.51%)
Total Downloads
Cumulative downloads
Total Downloads
4,271,170
Last day
6%
9,972
Compared to previous day
Last week
15.6%
54,345
Compared to previous week
Last month
6.9%
210,147
Compared to previous month
Last year
101.4%
2,055,657
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
@poppinss/colors
Wrapper over kleur with better support for testing
Why this package exists?
This package is a wrapper over kleur with additional implementations to make testing easier and work seamlessly with terminals/stdout streams that do not support colors.
Usage
Install the package from the npm registry as follows.
1npm i @poppinss/colors
And use it as follows. The ansi
method returns an instance of the kleur package.
1import useColors from '@poppinss/colors' 2const colors = useColors.ansi() 3 4console.log(colors.red('this is an error')) 5console.log(colors.cyan('hello world'))
Chaining methods
1const colors = useColors.ansi() 2console.log(colors.red().bgBlack('this is an error'))
Raw implementation
The raw implementation is ideal for testing. Instead of outputting ANSI escape codes, we wrap the string with transformation names. For example:
1import useColors from '@poppinss/colors' 2const colors = useColors.raw() 3 4console.log(colors.red('hello world')) 5// OUTPUT: red(hello world) 6 7console.log(colors.bgBlack().red('hello world')) 8// OUTPUT: bgBlack(red(hello world))
As you can notice, the output is a plain text value, so it is easier to write assertions against it.
1assert.equal(colors.red('hello world'), 'red(hello world)')
Silent output
The silent mode does not perform any transformations on the string and returns the value. This is helpful when the output terminal or stdout stream does not support colors.
1import useColors from '@poppinss/colors' 2const colors = useColors.silent() 3 4console.log(colors.red('hello world')) 5// OUTPUT: hello world 6 7console.log(colors.bgBlack().red('hello world')) 8// OUTPUT: hello world
Pick based on the runtime environment
Ideally, you will use one of the available implementations based on some runtime environment. For example:
1import useColors from '@poppinss/colors' 2import supportsColor from 'supports-color' 3 4const isTestEnv = process.env.NODE_ENV === 'test' 5 6const colors = isTestEnv 7 ? useColors.raw() // use raw in test environment 8 : supportsColor.stdout 9 ? useColors.ansi() // use kleur when stdout has colors 10 : useColors.silent() // use silent mode 11 12export default colors
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/poppinss/.github/docs/SECURITY.md:1
- Info: Found linked content: github.com/poppinss/.github/docs/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/poppinss/.github/docs/SECURITY.md:1
- Info: Found text in security policy: github.com/poppinss/.github/docs/SECURITY.md:1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/checks.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'develop'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
4.3
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More