@zahra633/inklog 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +89 -0
- package/package.json +50 -0
- package/tsconfig.json +25 -0
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @zahra633/inklog
|
|
2
|
+
|
|
3
|
+
A lightweight, beautiful, and fully typed terminal logger for Node.js. `inklog` creates neatly formatted, colored boxes around your terminal messages using `chalk`, complete with status icons and automatic text wrapping so your logs never break terminal layout!
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎨 **Beautiful Formatting:** Automatically wraps text in elegant ASCII box-drawing characters.
|
|
8
|
+
- 📐 **Smart Word Wrapping:** Detects your terminal width automatically and wraps long text without splitting words visually.
|
|
9
|
+
- 🚦 **Status Icons:** Built-in recognizable prefixes for different log levels (✔, ✖, ⚠, ℹ).
|
|
10
|
+
- 🌈 **Color Coded:** Uses `chalk` to colorize boxes based on the tone of your message (Green, Red, Yellow, Blue).
|
|
11
|
+
- 📦 **Zero-Config:** Works out of the box with zero setup required.
|
|
12
|
+
- 🛡️ **TypeScript Ready:** Written in TypeScript to provide excellent autocomplete and type definitions.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
You can install it via npm:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @zahra633/inklog
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
You can import specific logging functions or the default object.
|
|
25
|
+
|
|
26
|
+
### Import Functions Individually
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { successLog, errorLog, warningLog, infoLog } from "@zahra633/inklog";
|
|
30
|
+
|
|
31
|
+
successLog("Database connection established successfully!");
|
|
32
|
+
errorLog("Failed to authenticate user: Invalid credentials.");
|
|
33
|
+
warningLog("API rate limit is approaching.");
|
|
34
|
+
infoLog("Server is running on port 3000.");
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Import as Default Object
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import inklog from "@zahra633/inklog";
|
|
41
|
+
|
|
42
|
+
inklog.successLog("User profile updated!");
|
|
43
|
+
|
|
44
|
+
// Works effortlessly with long strings and JSON objects:
|
|
45
|
+
inklog.infoLog(
|
|
46
|
+
"This is a really long log message that is going to be dynamically wrapped based on your system's current terminal width without causing any overflow issues or messing up the box design whatsoever."
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
inklog.warningLog({ message: "You can even pass objects and get formatted JSON out!", status: 400 });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## API Reference
|
|
53
|
+
|
|
54
|
+
### `successLog(msg: any)`
|
|
55
|
+
Prints a green box with a checkmark (✔) icon. Ideal for success events.
|
|
56
|
+
|
|
57
|
+
### `errorLog(msg: any)`
|
|
58
|
+
Prints a red box with an X (✖) icon. Ideal for error events and exceptions.
|
|
59
|
+
|
|
60
|
+
### `warningLog(msg: any)`
|
|
61
|
+
Prints a yellow box with a warning (⚠) icon. Ideal for deprecations and warnings.
|
|
62
|
+
|
|
63
|
+
### `infoLog(msg: any)`
|
|
64
|
+
Prints a blue box with an info (ℹ) icon. Ideal for general logging and status updates.
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
ISC License
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const successLog: (msg: any) => void;
|
|
2
|
+
export declare const errorLog: (msg: any) => void;
|
|
3
|
+
export declare const warningLog: (msg: any) => void;
|
|
4
|
+
export declare const infoLog: (msg: any) => void;
|
|
5
|
+
declare const inklog: {
|
|
6
|
+
successLog: (msg: any) => void;
|
|
7
|
+
errorLog: (msg: any) => void;
|
|
8
|
+
warningLog: (msg: any) => void;
|
|
9
|
+
infoLog: (msg: any) => void;
|
|
10
|
+
};
|
|
11
|
+
export default inklog;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.infoLog = exports.warningLog = exports.errorLog = exports.successLog = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const log = console.log;
|
|
9
|
+
const wrapText = (text, maxWidth) => {
|
|
10
|
+
const words = text.split(" ");
|
|
11
|
+
const lines = [];
|
|
12
|
+
let currentLine = "";
|
|
13
|
+
for (const word of words) {
|
|
14
|
+
if ((currentLine + (currentLine ? " " : "") + word).length <= maxWidth) {
|
|
15
|
+
currentLine += (currentLine ? " " : "") + word;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
if (currentLine)
|
|
19
|
+
lines.push(currentLine);
|
|
20
|
+
currentLine = word;
|
|
21
|
+
while (currentLine.length > maxWidth) {
|
|
22
|
+
lines.push(currentLine.substring(0, maxWidth));
|
|
23
|
+
currentLine = currentLine.substring(maxWidth);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (currentLine)
|
|
28
|
+
lines.push(currentLine);
|
|
29
|
+
return lines;
|
|
30
|
+
};
|
|
31
|
+
const getPrefix = (type) => {
|
|
32
|
+
switch (type) {
|
|
33
|
+
case "success": return "✔";
|
|
34
|
+
case "error": return "✖";
|
|
35
|
+
case "warning": return "⚠";
|
|
36
|
+
case "info": return "ℹ";
|
|
37
|
+
default: return "";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const getColor = (type) => {
|
|
41
|
+
switch (type) {
|
|
42
|
+
case "success": return chalk_1.default.green;
|
|
43
|
+
case "error": return chalk_1.default.red;
|
|
44
|
+
case "warning": return chalk_1.default.yellow;
|
|
45
|
+
case "info": return chalk_1.default.blue;
|
|
46
|
+
default: return chalk_1.default.white;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const handler = (msg, type) => {
|
|
50
|
+
const textMsg = typeof msg === "string" ? msg : JSON.stringify(msg, null, 2) || "";
|
|
51
|
+
const columns = process.stdout.columns || 80;
|
|
52
|
+
const prefix = getPrefix(type);
|
|
53
|
+
const colorFn = getColor(type);
|
|
54
|
+
const prefixStr = prefix ? `${prefix} ` : "";
|
|
55
|
+
const extraCharsPerLine = 4 + prefixStr.length;
|
|
56
|
+
const maxLineWidth = Math.max(10, columns - extraCharsPerLine);
|
|
57
|
+
const lines = textMsg.split("\n").flatMap(line => wrapText(line, maxLineWidth));
|
|
58
|
+
const longestLine = Math.max(...lines.map(l => l.length), 0);
|
|
59
|
+
const dashLength = longestLine + prefixStr.length + 2;
|
|
60
|
+
const dash = "─".repeat(dashLength);
|
|
61
|
+
log(colorFn(`┌${dash}┐`));
|
|
62
|
+
for (let i = 0; i < lines.length; i++) {
|
|
63
|
+
const line = lines[i];
|
|
64
|
+
const paddedLine = line.padEnd(longestLine, " ");
|
|
65
|
+
if (i === 0) {
|
|
66
|
+
log(colorFn(`│ ${prefixStr}${paddedLine} │`));
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const emptyPrefix = " ".repeat(prefixStr.length);
|
|
70
|
+
log(colorFn(`│ ${emptyPrefix}${paddedLine} │`));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
log(colorFn(`└${dash}┘`));
|
|
74
|
+
};
|
|
75
|
+
const successLog = (msg) => handler(msg, "success");
|
|
76
|
+
exports.successLog = successLog;
|
|
77
|
+
const errorLog = (msg) => handler(msg, "error");
|
|
78
|
+
exports.errorLog = errorLog;
|
|
79
|
+
const warningLog = (msg) => handler(msg, "warning");
|
|
80
|
+
exports.warningLog = warningLog;
|
|
81
|
+
const infoLog = (msg) => handler(msg, "info");
|
|
82
|
+
exports.infoLog = infoLog;
|
|
83
|
+
const inklog = { successLog: exports.successLog, errorLog: exports.errorLog, warningLog: exports.warningLog, infoLog: exports.infoLog };
|
|
84
|
+
exports.default = inklog;
|
|
85
|
+
// Testing logs
|
|
86
|
+
(0, exports.successLog)("This is a success message");
|
|
87
|
+
(0, exports.errorLog)("This is an error message");
|
|
88
|
+
(0, exports.warningLog)("This is a warning message");
|
|
89
|
+
(0, exports.infoLog)("This is an info message. We can test the automatic word wrapping feature by providing a really long text that will dynamically wrap into the next line. This prevents overflow or messy formatting issues in the terminal output!");
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zahra633/inklog",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A colorful and beautiful terminal logger for Node.js with fixed-width output and icons",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "ts-node-dev --transpile-only src/index.ts",
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"start": "node dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"console",
|
|
14
|
+
"pretty-logger",
|
|
15
|
+
"colored-logs",
|
|
16
|
+
"log-formatter",
|
|
17
|
+
"dev-logger",
|
|
18
|
+
"inklog"
|
|
19
|
+
],
|
|
20
|
+
"author": "@zahra633/inklog - Zahra",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"homepage": "https://github.com/shayanalikhan888/inklog#readme",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/shayanalikhan888/inklog.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/shayanalikhan888/inklog/issues"
|
|
29
|
+
},
|
|
30
|
+
"type": "commonjs",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"chalk": "^5.6.2",
|
|
33
|
+
"cookie-parser": "^1.4.7",
|
|
34
|
+
"cors": "^2.8.6",
|
|
35
|
+
"dotenv": "^17.3.1",
|
|
36
|
+
"express": "^5.2.1",
|
|
37
|
+
"inquirer": "^13.3.0",
|
|
38
|
+
"mongoose": "^9.2.1",
|
|
39
|
+
"morgan": "^1.10.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/cookie-parser": "^1.4.10",
|
|
43
|
+
"@types/cors": "^2.8.19",
|
|
44
|
+
"@types/express": "^5.0.6",
|
|
45
|
+
"@types/morgan": "^1.9.10",
|
|
46
|
+
"@types/node": "^25.5.0",
|
|
47
|
+
"ts-node-dev": "^2.0.0",
|
|
48
|
+
"typescript": "^5.9.3"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2022",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"rootDir": "./src",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"types": [
|
|
14
|
+
"node"
|
|
15
|
+
],
|
|
16
|
+
"declaration": true
|
|
17
|
+
},
|
|
18
|
+
"include": [
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"exclude": [
|
|
22
|
+
"node_modules",
|
|
23
|
+
"templates"
|
|
24
|
+
]
|
|
25
|
+
}
|