fix(documentation): improve readme with comprehensive examples and formatting
- Enhanced readme with detailed API documentation - Added real-world usage examples and best practices - Updated legal section to Task Venture Capital GmbH - Updated CI/CD workflow configurations - Updated dependencies to latest versions - Removed obsolete gitlab-ci.yml
This commit is contained in:
@@ -6,8 +6,8 @@ on:
|
|||||||
- '**'
|
- '**'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
|
||||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
- name: Install pnpm and npmci
|
- name: Install pnpm and npmci
|
||||||
run: |
|
run: |
|
||||||
pnpm install -g pnpm
|
pnpm install -g pnpm
|
||||||
pnpm install -g @shipzone/npmci
|
pnpm install -g @ship.zone/npmci
|
||||||
|
|
||||||
- name: Run npm prepare
|
- name: Run npm prepare
|
||||||
run: npmci npm prepare
|
run: npmci npm prepare
|
||||||
|
@@ -6,8 +6,8 @@ on:
|
|||||||
- '*'
|
- '*'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
|
||||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
- name: Prepare
|
- name: Prepare
|
||||||
run: |
|
run: |
|
||||||
pnpm install -g pnpm
|
pnpm install -g pnpm
|
||||||
pnpm install -g @shipzone/npmci
|
pnpm install -g @ship.zone/npmci
|
||||||
npmci npm prepare
|
npmci npm prepare
|
||||||
|
|
||||||
- name: Audit production dependencies
|
- name: Audit production dependencies
|
||||||
@@ -54,7 +54,7 @@ jobs:
|
|||||||
- name: Prepare
|
- name: Prepare
|
||||||
run: |
|
run: |
|
||||||
pnpm install -g pnpm
|
pnpm install -g pnpm
|
||||||
pnpm install -g @shipzone/npmci
|
pnpm install -g @ship.zone/npmci
|
||||||
npmci npm prepare
|
npmci npm prepare
|
||||||
|
|
||||||
- name: Test stable
|
- name: Test stable
|
||||||
@@ -82,7 +82,7 @@ jobs:
|
|||||||
- name: Prepare
|
- name: Prepare
|
||||||
run: |
|
run: |
|
||||||
pnpm install -g pnpm
|
pnpm install -g pnpm
|
||||||
pnpm install -g @shipzone/npmci
|
pnpm install -g @ship.zone/npmci
|
||||||
npmci npm prepare
|
npmci npm prepare
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
@@ -104,7 +104,7 @@ jobs:
|
|||||||
- name: Prepare
|
- name: Prepare
|
||||||
run: |
|
run: |
|
||||||
pnpm install -g pnpm
|
pnpm install -g pnpm
|
||||||
pnpm install -g @shipzone/npmci
|
pnpm install -g @ship.zone/npmci
|
||||||
npmci npm prepare
|
npmci npm prepare
|
||||||
|
|
||||||
- name: Code quality
|
- name: Code quality
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,7 +3,6 @@
|
|||||||
# artifacts
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
|
||||||
|
|
||||||
# installs
|
# installs
|
||||||
node_modules/
|
node_modules/
|
||||||
@@ -17,4 +16,4 @@ node_modules/
|
|||||||
dist/
|
dist/
|
||||||
dist_*/
|
dist_*/
|
||||||
|
|
||||||
# custom
|
#------# custom
|
142
.gitlab-ci.yml
142
.gitlab-ci.yml
@@ -1,142 +0,0 @@
|
|||||||
# gitzone standard
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: "$CI_BUILD_STAGE"
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
snyk:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g snyk
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command snyk test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install legacy
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
|
||||||
- docker run
|
|
||||||
--env SOURCE_CODE="$PWD"
|
|
||||||
--volume "$PWD":/code
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g typedoc typescript
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
windowsCompatibility:
|
|
||||||
image: stefanscherer/node-windows:10-build-tools
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npm install & npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- windows
|
|
||||||
allow_failure: true
|
|
26
changelog.md
Normal file
26
changelog.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [2.0.3] - 2025-08-08
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Enhanced readme documentation with comprehensive examples and improved formatting
|
||||||
|
- Updated CI/CD workflow configurations
|
||||||
|
- Updated dependencies to latest versions
|
||||||
|
- Removed obsolete gitlab-ci.yml configuration
|
||||||
|
|
||||||
|
## [2.0.2] - Previous Release
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Core updates and improvements
|
||||||
|
|
||||||
|
## [2.0.1] - Previous Release
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- CI build arguments configuration
|
||||||
|
|
||||||
|
## [2.0.0] - Previous Release
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Major version update with organizational restructuring
|
@@ -1,8 +1,6 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": ["@gitzone/npmts"],
|
||||||
"@gitzone/npmts"
|
|
||||||
],
|
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
@@ -30,4 +28,4 @@
|
|||||||
"tsdoc": {
|
"tsdoc": {
|
||||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
package.json
21
package.json
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/consolecolor",
|
"name": "@push.rocks/consolecolor",
|
||||||
"version": "2.0.2",
|
"version": "2.0.3",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "A module for applying color styles to console output.",
|
"description": "A module for applying color styles to console output.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/ --verbose --testlog --timeout 20)",
|
||||||
"build": "(tsbuild --allowimplicitany)",
|
"build": "(tsbuild --allowimplicitany)",
|
||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
@@ -28,18 +28,17 @@
|
|||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/push.rocks/consolecolor/issues"
|
"url": "https://code.foss.global/push.rocks/consolecolor/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://code.foss.global/push.rocks/consolecolor",
|
"homepage": "https://code.foss.global/push.rocks/consolecolor#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ansi-256-colors": "^1.1.0"
|
"ansi-256-colors": "^1.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.1.72",
|
"@git.zone/tsbuild": "^2.1.72",
|
||||||
"@git.zone/tsrun": "^1.1.9",
|
"@git.zone/tsrun": "^1.1.9",
|
||||||
"@git.zone/tstest": "^1.0.88",
|
"@git.zone/tstest": "^2.3.2",
|
||||||
"@push.rocks/tapbundle": "^5.0.15",
|
"@types/node": "^22.0.0"
|
||||||
"@types/node": "^10.5.2"
|
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
@@ -56,5 +55,9 @@
|
|||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
]
|
],
|
||||||
}
|
"pnpm": {
|
||||||
|
"overrides": {}
|
||||||
|
},
|
||||||
|
"packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977"
|
||||||
|
}
|
||||||
|
11923
pnpm-lock.yaml
generated
11923
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
208
readme.md
208
readme.md
@@ -1,86 +1,202 @@
|
|||||||
# @push.rocks/consolecolor
|
# @push.rocks/consolecolor
|
||||||
|
|
||||||
colors for beautylog
|
🎨 **Beautiful terminal colors for Node.js** - Make your console output pop with vibrant ANSI colors!
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
To install `@push.rocks/consolecolor`, you need Node.js installed on your system. If you have Node.js installed, you can add `@push.rocks/consolecolor` to your project by running:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install @push.rocks/consolecolor --save
|
pnpm install @push.rocks/consolecolor
|
||||||
|
# or
|
||||||
|
npm install @push.rocks/consolecolor
|
||||||
```
|
```
|
||||||
|
|
||||||
This command will install `@push.rocks/consolecolor` and add it to your project's `package.json` file.
|
## What it does
|
||||||
|
|
||||||
|
`@push.rocks/consolecolor` transforms your boring console output into a vibrant, colorful experience. Perfect for CLI tools, logging systems, or any Node.js application that needs to make terminal output more readable and visually appealing.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
In this guide, we'll explore how to use `@push.rocks/consolecolor` to colorize your console output in a Node.js application. We'll cover the basics, including coloring text, backgrounds, and combining both for striking effects. This package utilizes TypeScript and ESM syntax for modern, type-safe code examples.
|
### 🚀 Quick Start
|
||||||
|
|
||||||
### Getting Started
|
|
||||||
|
|
||||||
First, ensure you have imported the library in your TypeScript file:
|
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import * as consolecolor from '@push.rocks/consolecolor';
|
import * as consolecolor from '@push.rocks/consolecolor';
|
||||||
|
|
||||||
|
// Simple colored text
|
||||||
|
const blueText = consolecolor.coloredString('Hello World!', 'blue');
|
||||||
|
console.log(blueText);
|
||||||
|
|
||||||
|
// Text with background color
|
||||||
|
const alertMessage = consolecolor.coloredString('WARNING', 'red', 'white');
|
||||||
|
console.log(alertMessage);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Coloring Text
|
### 🎨 Available Colors
|
||||||
|
|
||||||
The foundation of using `@push.rocks/consolecolor` is to change the color of the text output. You can choose from a variety of colors including blue, red, green, and more. Here's how to color a string blue:
|
The module supports these vibrant colors:
|
||||||
|
|
||||||
|
- `black` - Deep black ⚫
|
||||||
|
- `blue` - Bright blue 🔵
|
||||||
|
- `brown` - Warm brown 🟤
|
||||||
|
- `cyan` - Cool cyan 🟦
|
||||||
|
- `green` - Fresh green 🟢
|
||||||
|
- `orange` - Vibrant orange 🟠
|
||||||
|
- `pink` - Soft pink 🩷
|
||||||
|
- `red` - Bold red 🔴
|
||||||
|
- `white` - Pure white ⚪
|
||||||
|
|
||||||
|
### 📚 API Reference
|
||||||
|
|
||||||
|
#### `coloredString(text, fontColor, backgroundColor?)`
|
||||||
|
|
||||||
|
Creates a colored string for terminal output.
|
||||||
|
|
||||||
|
**Parameters:**
|
||||||
|
- `text` (string): The text to colorize
|
||||||
|
- `fontColor` (TColorName): The color for the text
|
||||||
|
- `backgroundColor` (TColorName, optional): The background color
|
||||||
|
|
||||||
|
**Returns:** A string with ANSI color codes
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
let blueString = consolecolor.coloredString("This text is blue.", "blue");
|
// Basic usage
|
||||||
console.log(blueString);
|
const simpleColored = consolecolor.coloredString('Status: OK', 'green');
|
||||||
|
|
||||||
|
// With background
|
||||||
|
const highlighted = consolecolor.coloredString('CRITICAL', 'white', 'red');
|
||||||
```
|
```
|
||||||
|
|
||||||
### Adding Background Color
|
### 💡 Real-World Examples
|
||||||
|
|
||||||
In addition to coloring text, you can also set the background color of your text for greater emphasis:
|
#### Creating a Logger with Color-Coded Severity
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
let redTextOnGreen = consolecolor.coloredString("Red text on a green background.", "red", "green");
|
import * as consolecolor from '@push.rocks/consolecolor';
|
||||||
console.log(redTextOnGreen);
|
|
||||||
```
|
|
||||||
|
|
||||||
### Combining Colors
|
class ColorLogger {
|
||||||
|
info(message: string) {
|
||||||
You can easily mix and match text and background colors to suit your needs. Here's an example of a more detailed usage, where we add a function to create and log messages of different severities with appropriate coloring:
|
console.log(consolecolor.coloredString(`ℹ INFO: ${message}`, 'cyan'));
|
||||||
|
}
|
||||||
```typescript
|
|
||||||
function logMessage(message: string, type: 'info' | 'warning' | 'error') {
|
success(message: string) {
|
||||||
switch (type) {
|
console.log(consolecolor.coloredString(`✔ SUCCESS: ${message}`, 'green'));
|
||||||
case 'info':
|
}
|
||||||
console.log(consolecolor.coloredString(message, 'cyan'));
|
|
||||||
break;
|
warning(message: string) {
|
||||||
case 'warning':
|
console.log(consolecolor.coloredString(`⚠ WARNING: ${message}`, 'orange', 'black'));
|
||||||
console.log(consolecolor.coloredString(message, 'orange', 'black'));
|
}
|
||||||
break;
|
|
||||||
case 'error':
|
error(message: string) {
|
||||||
console.log(consolecolor.coloredString(message, 'red', 'white'));
|
console.log(consolecolor.coloredString(`✖ ERROR: ${message}`, 'red', 'white'));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logMessage('An informational message', 'info');
|
const logger = new ColorLogger();
|
||||||
logMessage('A warning message', 'warning');
|
logger.info('Application started');
|
||||||
logMessage('An error message', 'error');
|
logger.success('Database connected');
|
||||||
|
logger.warning('Memory usage above 80%');
|
||||||
|
logger.error('Failed to write to disk');
|
||||||
```
|
```
|
||||||
|
|
||||||
This example defines a `logMessage` function that accepts a message and a message type. It uses `@push.rocks/consolecolor` to color the message according to its severity.
|
#### Progress Indicator with Colors
|
||||||
|
|
||||||
### Advanced Usage
|
```typescript
|
||||||
|
import * as consolecolor from '@push.rocks/consolecolor';
|
||||||
|
|
||||||
Beyond basic coloring, `@push.rocks/consolecolor` allows for intricate customization. For instance, you can create utilities that dynamically select colors based on conditions, enhance logging mechanisms, or implement theme-based console outputs in your Node.js applications.
|
function showProgress(step: number, total: number, status: 'pending' | 'running' | 'done') {
|
||||||
|
const percentage = Math.round((step / total) * 100);
|
||||||
|
const progressBar = '█'.repeat(percentage / 5) + '░'.repeat(20 - percentage / 5);
|
||||||
|
|
||||||
|
let statusColor: 'orange' | 'blue' | 'green' = 'orange';
|
||||||
|
if (status === 'running') statusColor = 'blue';
|
||||||
|
if (status === 'done') statusColor = 'green';
|
||||||
|
|
||||||
|
const output = consolecolor.coloredString(
|
||||||
|
`[${progressBar}] ${percentage}% - ${status}`,
|
||||||
|
statusColor
|
||||||
|
);
|
||||||
|
|
||||||
|
process.stdout.write('\r' + output);
|
||||||
|
}
|
||||||
|
|
||||||
Considering the capabilities of `@push.rocks/consolecolor` alongside Node.js's console object, you can create highly readable, colorful console applications that are easier to debug and pleasant to interact with.
|
// Usage
|
||||||
|
showProgress(5, 10, 'running');
|
||||||
|
```
|
||||||
|
|
||||||
### Conclusion
|
#### Colorful Data Table
|
||||||
|
|
||||||
`@push.rocks/consolecolor` offers a simple yet powerful API for adding color to Node.js console applications. By following the examples provided, you can enhance the visual appeal and readability of your console output, making development and debugging a more enjoyable experience. For a comprehensive list of all available colors and more advanced features, refer to the official documentation and explore the module's possibilities.
|
```typescript
|
||||||
|
import * as consolecolor from '@push.rocks/consolecolor';
|
||||||
|
|
||||||
|
function printColorfulTable(data: Array<{name: string, status: string, value: number}>) {
|
||||||
|
// Header
|
||||||
|
console.log(consolecolor.coloredString('━'.repeat(50), 'cyan'));
|
||||||
|
console.log(
|
||||||
|
consolecolor.coloredString('Name', 'white') + '\t\t' +
|
||||||
|
consolecolor.coloredString('Status', 'white') + '\t\t' +
|
||||||
|
consolecolor.coloredString('Value', 'white')
|
||||||
|
);
|
||||||
|
console.log(consolecolor.coloredString('━'.repeat(50), 'cyan'));
|
||||||
|
|
||||||
|
// Data rows
|
||||||
|
data.forEach(row => {
|
||||||
|
const statusColor = row.status === 'active' ? 'green' :
|
||||||
|
row.status === 'pending' ? 'orange' : 'red';
|
||||||
|
const valueColor = row.value > 80 ? 'green' :
|
||||||
|
row.value > 40 ? 'orange' : 'red';
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
row.name + '\t\t' +
|
||||||
|
consolecolor.coloredString(row.status, statusColor) + '\t\t' +
|
||||||
|
consolecolor.coloredString(row.value.toString(), valueColor)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(consolecolor.coloredString('━'.repeat(50), 'cyan'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example usage
|
||||||
|
printColorfulTable([
|
||||||
|
{ name: 'Service A', status: 'active', value: 95 },
|
||||||
|
{ name: 'Service B', status: 'pending', value: 60 },
|
||||||
|
{ name: 'Service C', status: 'failed', value: 15 }
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🔧 TypeScript Support
|
||||||
|
|
||||||
|
This module is written in TypeScript and provides full type definitions out of the box:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import type { TColorName, IRGB } from '@push.rocks/consolecolor';
|
||||||
|
|
||||||
|
// TColorName type for color validation
|
||||||
|
const myColor: TColorName = 'blue'; // ✅ Valid
|
||||||
|
// const invalid: TColorName = 'purple'; // ❌ TypeScript error
|
||||||
|
|
||||||
|
// IRGB interface for RGB values
|
||||||
|
const customRGB: IRGB = { r: 5, g: 3, b: 1 }; // Used internally
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🎯 Use Cases
|
||||||
|
|
||||||
|
- **CLI Tools**: Make your command-line tools more user-friendly with color-coded output
|
||||||
|
- **Logging Systems**: Differentiate log levels with distinct colors
|
||||||
|
- **Build Scripts**: Highlight errors, warnings, and success messages
|
||||||
|
- **Development Tools**: Color-code test results, linting output, or deployment statuses
|
||||||
|
- **Data Visualization**: Create simple colored charts and graphs in the terminal
|
||||||
|
- **Interactive CLIs**: Guide users with colored prompts and responses
|
||||||
|
|
||||||
|
### 🚦 Best Practices
|
||||||
|
|
||||||
|
1. **Use colors consistently** - Establish a color scheme (e.g., red for errors, green for success)
|
||||||
|
2. **Consider accessibility** - Not everyone can distinguish all colors equally
|
||||||
|
3. **Provide non-color alternatives** - Use symbols alongside colors (✔, ✖, ⚠)
|
||||||
|
4. **Test in different terminals** - Colors may appear differently across terminal emulators
|
||||||
|
5. **Keep it readable** - Avoid color combinations that are hard to read
|
||||||
|
|
||||||
## License and Legal Information
|
## License and Legal Information
|
||||||
|
|
||||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||||
|
|
||||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
@@ -95,4 +211,4 @@ Registered at District court Bremen HRB 35230 HB, Germany
|
|||||||
|
|
||||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
18
test/test.ts
18
test/test.ts
@@ -1,14 +1,20 @@
|
|||||||
import { expect, tap } from '@push.rocks/tapbundle';
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
|
|
||||||
import * as consolecolor from '../ts/index.js';
|
import * as consolecolor from '../ts/index.js';
|
||||||
|
|
||||||
tap.test('should produce a blue font', async () => {
|
tap.test('should produce a blue font', async () => {
|
||||||
console.log(consolecolor.coloredString('this is a blue font, no background', 'blue'));
|
console.log(
|
||||||
|
consolecolor.coloredString('this is a blue font, no background', 'blue'),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should produce a red string with green background', async () => {
|
tap.test('should produce a red string with green background', async () => {
|
||||||
console.log(
|
console.log(
|
||||||
consolecolor.coloredString('this is a red font with green background', 'red', 'green')
|
consolecolor.coloredString(
|
||||||
|
'this is a red font with green background',
|
||||||
|
'red',
|
||||||
|
'green',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -20,7 +26,7 @@ tap.test('should produce different font colors', async () => {
|
|||||||
consolecolor.coloredString('orange', 'orange'),
|
consolecolor.coloredString('orange', 'orange'),
|
||||||
consolecolor.coloredString('green', 'green'),
|
consolecolor.coloredString('green', 'green'),
|
||||||
consolecolor.coloredString('pink', 'pink'),
|
consolecolor.coloredString('pink', 'pink'),
|
||||||
consolecolor.coloredString('cyan', 'cyan')
|
consolecolor.coloredString('cyan', 'cyan'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -32,8 +38,8 @@ tap.test('should produce different background colors', async () => {
|
|||||||
consolecolor.coloredString('orange', 'white', 'orange'),
|
consolecolor.coloredString('orange', 'white', 'orange'),
|
||||||
consolecolor.coloredString('green', 'white', 'green'),
|
consolecolor.coloredString('green', 'white', 'green'),
|
||||||
consolecolor.coloredString('pink', 'white', 'pink'),
|
consolecolor.coloredString('pink', 'white', 'pink'),
|
||||||
consolecolor.coloredString('cyan', 'white', 'cyan')
|
consolecolor.coloredString('cyan', 'white', 'cyan'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
export default tap.start();
|
||||||
|
@@ -4,5 +4,5 @@
|
|||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/consolecolor',
|
name: '@push.rocks/consolecolor',
|
||||||
version: '2.0.2',
|
version: '2.0.2',
|
||||||
description: 'colors for beautylog'
|
description: 'colors for beautylog',
|
||||||
}
|
};
|
||||||
|
@@ -57,7 +57,7 @@ let coloredFont = (stringArg: string, colorArg: TColorName) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* colors the back of a string
|
* colors the back of a string for the terminal
|
||||||
*/
|
*/
|
||||||
let coloredBackground = (stringArg: string, colorArg: TColorName) => {
|
let coloredBackground = (stringArg: string, colorArg: TColorName) => {
|
||||||
let rgbCode = colorTranslator(colorArg);
|
let rgbCode = colorTranslator(colorArg);
|
||||||
@@ -65,12 +65,12 @@ let coloredBackground = (stringArg: string, colorArg: TColorName) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* color a string with xterm
|
* color a string for the terminal
|
||||||
*/
|
*/
|
||||||
export let coloredString = (
|
export let coloredString = (
|
||||||
stringArg: string,
|
stringArg: string,
|
||||||
colorFontArg: TColorName,
|
colorFontArg: TColorName,
|
||||||
colorBackgroundArg?: TColorName
|
colorBackgroundArg?: TColorName,
|
||||||
): string => {
|
): string => {
|
||||||
let returnString = coloredFont(stringArg, colorFontArg);
|
let returnString = coloredFont(stringArg, colorFontArg);
|
||||||
if (colorBackgroundArg) {
|
if (colorBackgroundArg) {
|
||||||
|
@@ -6,9 +6,9 @@
|
|||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "NodeNext",
|
"moduleResolution": "NodeNext",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"verbatimModuleSyntax": true
|
"verbatimModuleSyntax": true,
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {}
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": ["dist_*/**/*.d.ts"]
|
||||||
"dist_*/**/*.d.ts"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user